I have Pillow and qrcode modules installed in a virtual environment.
From the python shell, I can create a test image programmatically using PIL:
>>> from PIL import Image
>>> img = Image.new('1', (200, 200))
>>> img.save('test-image.jpeg', 'JPEG')
Great, that works just as I would expect it to. However, I'm getting this error when I try to use a module that relies on PIL:
>>> import qrcode
>>> qr_code = qrcode.make("1")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/vagrant/.virtualenvs/env1/local/lib/python2.7/site-packages/qrcode/main.py", line 8, in make
return qr.make_image()
File "/home/vagrant/.virtualenvs/env1/local/lib/python2.7/site-packages/qrcode/main.py", line 186, in make_image
from qrcode.image.pil import PilImage
File "/home/vagrant/.virtualenvs/env1/local/lib/python2.7/site-packages/qrcode/image/pil.py", line 5, in <module>
import Image
ImportError: No module named Image
Why can't qrcode import PIL's Image class but it works from the shell?
from PIL import ImageDraw
also work on the shell? If that module is somehow missing from thePIL
package,qrcode
will assumeImage
is also missing from thePIL
package and try to import it from the top level, which will cause exactly the problem you're seeing. – Notabilityfrom PIL import Image
, just typeImage
and see what path it gives you. Is it inside/home/vagrant/.virtualenvs/env1/blah/blah
, or not? – Notability