I am trying to use Pillow/PIL (Currently pillow as PIL failed to find the jpeg decoder) but I cant seem get my script to work:
self.photo = PIL.ImageTk.PhotoImage(self.image)
File "/home/pi/PythonDev/env/local/lib/python2.7/site-packages/PIL/ImageTk.py", line 123, in __init__
self.paste(image)
File "/home/pi/PythonDev/env/local/lib/python2.7/site-packages/PIL/ImageTk.py", line 188, in paste
from PIL import _imagingtk
ImportError: cannot import name _imagingtk
So I have a virtualenv setup on my raspberry pi, with presumably all of the correct packages installed:
PIL SETUP SUMMARY
--------------------------------------------------------------------
version Pillow 2.1.0
platform linux2 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3]
--------------------------------------------------------------------
*** TKINTER support not available
(Tcl/Tk 8.5 libraries needed)
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
*** TIFF G3/G4 (experimental) support not available
--- FREETYPE2 support available
*** LITTLECMS support not available
*** WEBP support not available
--------------------------------------------------------------------
I guess if I had TKINTER support enabled this would work? What is that I am missing? (Tcl/Tk 8.5 libraries come with python?)
Thanks in advance
You need the dev libraries for tcl/tk, as you don't have the tkinter support installed. (assuming that you're running raspian) Install them using apt-get:
sudo apt-get install tk8.5-dev tcl8.5-dev
Install them and then rebuild pillow. (and OMG is the pi slower than my desktop)
You should see something like:
...
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/freetype2 -IlibImaging -I/usr/include -I/usr/include/tcl8.5 -I/usr/local/include -I/usr/include/python2.7 -I/usr/include/arm-linux-gnueabihf -c Tk/tkImaging.c -o build/temp.linux-armv6l-2.7/Tk/tkImaging.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-armv6l-2.7/_imagingtk.o build/temp.linux-armv6l-2.7/Tk/tkImaging.o -L/usr/local/lib -L/usr/lib/arm-linux-gnueabihf -ltcl8.5 -ltk8.5 -o build/lib.linux-armv6l-2.7/PIL/_imagingtk.so
building 'PIL._imagingmath' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/freetype2 -IlibImaging -I/usr/include -I/usr/include/tcl8.5 -I/usr/local/include -I/usr/include/python2.7 -I/usr/include/arm-linux-gnueabihf -c _imagingmath.c -o build/temp.linux-armv6l-2.7/_imagingmath.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-armv6l-2.7/_imagingmath.o -L/usr/local/lib -L/usr/lib/arm-linux-gnueabihf -o build/lib.linux-armv6l-2.7/PIL/_imagingmath.so
--------------------------------------------------------------------
PIL SETUP SUMMARY
--------------------------------------------------------------------
version Pillow 2.1.0
platform linux2 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3]
--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- TIFF G3/G4 (experimental) support available
--- FREETYPE2 support available
--- LITTLECMS support available
--- WEBP support available
--------------------------------------------------------------------
To check the build, run the selftest.py script.
erics@raspberry ~/Pillow $ cd ..
erics@raspberry ~ $ python
Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import ImageTk
>>> from PIL import _imagingtk
>>>
Ah awesome, that fixed it for me - Thanks very much! And yes the Pi is most likely slower than your desktop ;)
Is there anyway I could have worked this out for myself for future reference?
Somehow we're missing the references for tcl/tk dev packages in the readme. I'll fix that.
Yes, that's right to work this successfully you should rebuild Pillow library by this command on linux
sudo apt-get install --reinstall python-pillow
and then done.
I am using Pillow 2.7.0 and to enable TKINTER support requires newer dev libraries:
sudo apt-get install tk8.6-dev tcl8.6-dev
The tk-dev version you need depends on what tk package your python is compiled against, so it varies by distribution.
Hi everyone,
I fixed it with
sudo apt-get install python-imaging-tk
@nolimitech how can i do the same thing with Python3.2? I am getting the ImportError: cannot import name _imagingtk
@pricejt Make sure deps are present when you compile/install, nothing to do with Python version.
How can i verify the dependencies? I installed Pillow and already had Tkinter.
I should say i have this working fine on my Python 3.4 version on my windows machine. Trying to now get it to work on my PI which runs 3.2 python.
@pricejt What OS?
@aclark4life raspbian
OK sounds like Debian, so make sure you have Tkinter dev libraries via dpkg or apt-get or aptitude.
So i ran this: sudo apt-get install tk-dev
then i tried to re-run the program and still get the same issue. Do i need to reload any of the previous libraries.
sudo apt-get install tk-dev; pip uninstall Pillow; pip install Pillow then retry program
sorry about this.
ok i ran sudo pip install Pillow and it gave me a compile error.
i than ran sudo pip-3.2 install Pillow and said i already had it.
i than ran sudo pip-3.2 install Pillow --update and it said it was up to date.
I then re-tried program and got the same error.
No prob! sudo pip-3.2 uninstall Pillow ; sudo pip-3.2 install Pillow then retry. Also paste the output of the installation.
you're a saint thanks for all your help. I am learning more and more each day with Python
@pricejt Great! Glad to hear :beers:
I had to add do pip install -I --no-cache-dir Pillow before it worked. I think pip build the cache before I installed all package requirements, and that caused it to not work event when reinstalling Pillow.
@gitaarik That's the ticket! Cache seems to hold onto pre-built libraries rather than rebuilding after an uninstall. Thanks!
@gitaarik Thank you so much! totally made my day!!
Most helpful comment
I had to add do
pip install -I --no-cache-dir Pillowbefore it worked. I think pip build the cache before I installed all package requirements, and that caused it to not work event when reinstalling Pillow.