我遇到这个奇怪的错误,我需要在qrcode中使用pillow,所以我做了pip install pillow qrcode(在启动虚拟环境之后)。然后,发生以下事情

>>> from PIL import Image
>>> Image
<module 'PIL.Image' from '/vagrant/env/local/lib/python2.7/site-packages/PIL/Image.pyc'>
>>> import qrcode;
>>> qrcode.make("1").show()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/vagrant/env/local/lib/python2.7/site-packages/qrcode/main.py", line 8, in make
    return qr.make_image()
  File "/vagrant/env/local/lib/python2.7/site-packages/qrcode/main.py", line 186, in   make_image
    from qrcode.image.pil import PilImage
  File "/vagrant/env/local/lib/python2.7/site-packages/qrcode/image/pil.py", line 5, in   <module>
    import Image
ImportError: No module named Image


from PIL import Image有效,但qrcode不起作用。不知道发生了什么

最佳答案

在Ubuntu上安装PIL:
https://askubuntu.com/questions/156484/how-do-i-install-python-imaging-library-pil

您程序的标头,代码:

##some magic for 3rd party packages
import site
site.main()
##headers
from PIL import Image
##programm
#here your program!!!


-
你的朋友!!!

关于python - 无法为Qrcode导入PIL.Image,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21250360/

10-12 22:58