ImportError: no module named _imagingtk

I wanted to start using Tkinter with python and have the following code:

#!/usr/bin/python from Tkinter import * from PIL import ImageTk, Image top = Tk() dir(top) top.title("Erstes Frame") erstesFrame = Frame(top, height=250, width=250) erstesFrame.pack_propagate(0) erstesFrame.pack() img = ImageTk.PhotoImage(Image.open("mario.gif")) erstesBild = Label(erstesFrame, image = img) erstesBild.pack() top.mainloop() 

But when I try to execute it, it just gives me this error:

 Traceback (most recent call last): File "ToDoAPP.py", line 14, in <module> img = ImageTk.PhotoImage(Image.open("mario.gif")) File "/usr/local/lib/python2.7/dist-packages/PIL/ImageTk.py", line 116, in __init__ self.paste(image) File "/usr/local/lib/python2.7/dist-packages/PIL/ImageTk.py", line 181, in paste import _imagingtk ImportError: No module named _imagingtk 

I installed PIL with python-pip and my OS is ubuntu 12.04 and my python version is 2.7.3

+6
source share
3 answers

You need to install ImageTk .

In debian, ubuntu, you can use the following command to install it:

 sudo apt-get install python-imaging-tk 

UPDATE

If you are using the latest version of ubuntu (16.04+), the package name has changed.

  • python-pil.imagetk (Python 2.x)
  • python3-pil.imagetk (Python 3.x)
+16
source

As falsetru already noted, you must first install the ImageTk module: it does not automatically connect to Python. To do this, run one of the following commands:

If you are using Python 2.x, use the following command:

 sudo apt-get install python-imaging-tk 

If you are using Python 3.x, use the following command:

 sudo apt-get install python3-pil.imagetk 
+4
source

To add to the answers here, on Ubuntu 16.04, the package name is slightly different (even for Python 2):

sudo apt-get install python-pil.imagetk

0
source

All Articles