5

I am learning tkinter and trying to place an image on a Button, but I cannot get past the import.

My code:

from tkinter import *
from PIL import Image, ImageTk

The error:

No module named 'ImageTk'

Based on a post I saw when researching this I tried sudo apt-get install python-imaging-tk

which says I already have the latest version.

I am on a Raspberry Pi3, with a new install of Raspbian and I did an upgrade and update to be sure.

Any suggestions?

Here is the output of apt-cache show python-pil requested in a comment below:

Package: python-pil
Source: pillow
Version: 2.6.1-2+deb8u3
Architecture: armhf
Maintainer: Matthias Klose <doko@debian.org>
Installed-Size: 1050
Depends: python (<< 2.8), python (>= 2.7~), python:any (>= 2.7.5-5~), mime-support | python-pil.imagetk, libc6 (>= 2.11), libfreetype6 (>= 2.2.1), libjpeg62-turbo (>= 1.3.1), liblcms2-2 (>= 2.2+git20110628), libtiff5 (>= 4.0.3), libwebp5, libwebpdemux1, libwebpmux1, zlib1g (>= 1:1.1.4)
Suggests: python-pil-doc, python-pil-dbg
Breaks: python-imaging (<< 1.1.7+2.0.0-1.1)
Replaces: python-imaging (<< 1.1.7+2.0.0-1.1)
Provides: python-pillow, python2.7-pil
Multi-Arch: same
Homepage: http://python-pillow.github.io/
Priority: optional
Section: python
Filename: pool/main/p/pillow/python-pil_2.6.1-2+deb8u3_armhf.deb
Size: 277856
SHA256: 9f4e54fbe21fde51c13f4c875a09045a05a61abb55db723c4b09c14ce125eb4d
SHA1: 1e0369561c91e3d8fcaced1027f281ffc05fda32
MD5sum: ec0be47a97ef8aea42211eb1c19ce6bf
Description: Python Imaging Library (Pillow fork)
 The Python Imaging Library (PIL) adds an image object to your Python
 interpreter. You can load images from a variety of file formats, and
 apply a rich set of image operations to them.
 .
 Image Objects:
  o Bilevel, greyscale, palette, true colour (RGB), true colour with
    transparency (RGBA).
  o colour separation (CMYK).
  o Copy, cut, paste operations.
  o Flip, transpose, resize, rotate, and arbitrary affine transforms.
  o Transparency operations.
  o Channel and point operations.
  o Colour transforms, including matrix operations.
  o Image enhancement, including convolution filters.
 .
 File Formats:
  o Full (Open/Load/Save): BMP, EPS (with ghostscript), GIF, IM, JPEG,
    MSP, PDF, PNG, PPM, TIFF, XBM.
  o Read only (Open/Load): ARG, CUR, DCX, FLI, FPX, GBR, GD, ICO, IMT, IPTC,
    MCIDAS, MPEG, PhotoCD, PCX, PIXAR, PSD, TGA, SGI, SUN, TGA, WMF, XPM.
  o Save only: PDF, EPS (without ghostscript).
Description-md5: 7fb415befc961c94ce8c999eb6902e95
Aurora0001
  • 6,357
  • 3
  • 25
  • 39
Glenn
  • 237
  • 1
  • 2
  • 8

3 Answers3

5

I've just checked on my own pi and installing python-pillow does not install the extra libraries that I believe are needed (same goes for python-pil if you are using that one).

I think you need to install both: python-imaging and python-imaging-tk as suggested here: http://effbot.org/imagingbook/imagetk.htm

flynnstone
  • 96
  • 3
2

I am currently using the raspberry pi and I realized that the latest version of python that it uses is python 3 or 3.5, so if you don't download ImageTk for python 3 or higher, it will not work. you can do this by using this code:

sudo apt-get install python3-pil.imagetk
RalfFriedl
  • 2,180
  • 2
  • 11
  • 12
Ryan Gr
  • 21
  • 3
0

I did this:

sudo apt-get install python-imaging python-imaging-tk

and got:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'python-pil.imagetk' instead of 'python-imaging-tk'

and it installed the new library and it worked for me.

Aurora0001
  • 6,357
  • 3
  • 25
  • 39
medyas
  • 101
  • 1