python - 导入PIL失败

标签 python image python-imaging-library

Python 中的新功能,在导入图像包时出现一些错误。 我需要在 python 中使用 Pillow 包。 机器中已安装以下软件包: enter image description here

enter image description here

以下是C:\Python27\Lib的文件夹结构:

enter image description here

使用以下语句时仍然出现错误(未找到 PIL 包):

from PIL import Image

与以下错误相同:

import Image

已经尝试过:

休息。

我还观察到,当打开命令行输入 python 然后放置在命令下面时,它不会给出错误。我不知道这是什么意思: enter image description here 感谢您的阅读!

最佳答案

Python2.x 和 Python3.x 使用单独的站点包

另请参阅what is site-packages

在 Linux 上...

$ python -m site
sys.path = [
    '/home/<username>',
    '/usr/lib/python2.7',
    '/usr/lib/python2.7/plat-x86_64-linux-gnu',
    '/usr/lib/python2.7/lib-tk',
    '/usr/lib/python2.7/lib-old',
    '/usr/lib/python2.7/lib-dynload',
    '/usr/local/lib/python2.7/dist-packages',
    '/usr/lib/python2.7/dist-packages',
    '/usr/lib/python2.7/dist-packages/gtk-2.0',
]
USER_BASE: '/home/<username>/.local' (exists)
USER_SITE: '/home/<username>/.local/lib/python2.7/site-packages' (doesn't exist)
ENABLE_USER_SITE: True


$ python3 -m site
sys.path = [
    '/home/<username>',
    '/usr/lib/python36.zip',
    '/usr/lib/python3.6',
    '/usr/lib/python3.6/lib-dynload',
    '/home/<username>/.local/lib/python3.6/site-packages',
    '/usr/local/lib/python3.6/dist-packages',
    '/usr/lib/python3/dist-packages',
    '/usr/lib/python3.6/dist-packages',
]
USER_BASE: '/home/<username>/.local' (exists)
USER_SITE: '/home/<username>/.local/lib/python3.6/site-packages' (exists)
ENABLE_USER_SITE: True

在 Windows 上,路径通常类似于...

'C:\\Python27\\lib\\site-packages'
'C:\\Python36\\lib\\site-packages'

如果您想在两个版本(2.7.16 和 3.7.4)中使用 PIL,您需要在每个版本中安装 Pillow 包。即

pip install Pillow
pip3 install Pillow 

关于python - 导入PIL失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58269109/

相关文章:

python - Pika BlockingConnection 和 RabbitMQ : connection closed

java - 如何获得跟踪图像的角落?

c# - 使用特定调色板在 C# 中实现 Floyd-Steinberg 抖动

python - 带有 Python PILLOW 的点线或虚线

python - PIL getpalette() 返回 None

Python PIL : font weight and style

python :为什么 setter和getter ?如何快速设置属性?

python beautifulsoup 提取文本

python - 从管理界面删除 ImageField 时出现 Django unicode 错误

PHP Image Zoom - 指数级