Python 中的新功能,在导入图像包时出现一些错误。 我需要在 python 中使用 Pillow 包。 机器中已安装以下软件包:
和
以下是C:\Python27\Lib的文件夹结构:
使用以下语句时仍然出现错误(未找到 PIL 包):
from PIL import Image
与以下错误相同:
import Image
已经尝试过:
休息。
我还观察到,当打开命令行输入 python 然后放置在命令下面时,它不会给出错误。我不知道这是什么意思: 感谢您的阅读!
最佳答案
Python2.x 和 Python3.x 使用单独的站点包
。
在 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/