如何从 PIL/Pillow 导入 Python3.5 下的 windows 图像

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

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

如果是这样,这是我的问题。我读过 other questions like this 但其中任何一个对我有用。我试过了:

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'

documentation 我读到:

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) 所以,即使阅读 other answers,我尝试使用 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" 命令未知(我的免费翻译)

那么,现在怎么办?

编辑:完整错误是

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 显然是 "Pillow wrapper for PIL compatibility"。

site-packages 中删除文件通常不是一个好主意,而是使用像 pip 这样的软件包安装程序来完成它。

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

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