繁体   English   中英

如何从PIL / Pillow在Windows下的Python3.5中导入图像

[英]How to import Image in Python3.5 under windows from PIL/Pillow

我想写一个小应用程序来转换一些图像。 我认为必须使用Image.open() ,因此我必须导入Image模块。 对?

如果是这样,这是我的问题。 我已经读过其他类似的问题,但其中任何一个对我都有效。 我试过了:

import Image => ImportError: cannot import name 'VERSION'

from PIL import Image => ImportError: cannot import name 'VERSION'

from Pillow import Image => ImportError: No module named 'Pillow'

文档中,我读到:

Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL.

Pillow >= 1.0 no longer supports “import Image”. Please use “from PIL import Image” instead.

在我的虚拟环境中,我有PIL和Pillow目录,但pip list仅提供Pillow(3.1.0),因此,即使阅读其他答案 ,我也尝试使用pip卸载PIL,但找不到PIL,因此我只是删除目录PIL并安装了Pillow-PIL(现在它出现在pip list并且我的venv\\Lib\\site-packages\\上有目录Pillow_PIL ):

import Image => ImportError: No module named 'PIL'

from PIL import Image => ImportError: No module named 'PIL'

from Pillow import Image => ImportError: No module named 'Pillow'

from Pillow-PIL import Image => SyntaxError: invalid syntax (在减号上)

from Pillow_PIL import Image => ImportError: No module named 'Pillow_PIL'

apt-get install python-imaging => "apt-get"命令unknow(我的免费翻译)

所以现在怎么办?

编辑:完全错误是

Traceback (most recent call last):
  File "prova.py", line 1, in <module>
    import Image
  File "D:\Python\Envs\possedimenti\lib\site-packages\Image.py", line 1, in <mod
ule>
from PIL.Image import *
  File "D:\Python\Envs\possedimenti\lib\site-packages\PIL\Image.py", line 29, in
 <module>
    from PIL import VERSION, PILLOW_VERSION, _plugins
ImportError: cannot import name 'VERSION'

当您安装Pillow ,它将安装作为PIL导入的模块。 Pillow-PIL显然是“用于PIL兼容性的枕头包装”。

通常,从site-packages删除文件不是一个好主意,而是使用pip之类的软件包安装程序来执行此操作。

为了解决这个问题,我建议卸载Pillow-PIL,PIL(如果有)和Pillow,然后仅重新安装Pillow。

pip3 uninstall Pillow-PIL ; pip3 uninstall PIL ; pip3 uninstall Pillow ; pip3 install Pillow

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM