我在 shell 中使用这个命令来安装 PIL:
easy_install PIL
我运行python
并输入以下命令:import PIL
。但是我遇到了下面的错误:
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named PIL
我从未遇到过这样的问题,你认为是什么原因?
我在 shell 中使用这个命令来安装 PIL:
easy_install PIL
我运行python
并输入以下命令:import PIL
。但是我遇到了下面的错误:
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named PIL
我从未遇到过这样的问题,你认为是什么原因?
\Python26\Lib\site-packages\pil instead of \Python26\Lib\site-packages\PIL
将pil
文件夹重命名为PIL
后,我能够加载PIL模块。
解决这个问题最干净的方法是按照以下步骤进行。
步骤1:卸载PIL包。
pip uninstall PIL
步骤2:在Windows操作系统上使用以下pip命令安装Pillow。对于其他环境,请查看文章No module named PIL。在Windows上:
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
步骤 3:Python Imaging Library 中最重要的类是 Image 类,您可以按如下所示导入该类。
from PIL import Image
im = Image.open("myimage.jpg")
print(im.format, im.size, im.mode)
#Output: PPM (512, 512) RGB
如果您使用Anaconda:
conda install pillow
我在Windows 10上遇到了同样的问题,这个方法对我有效:
pip install Pillow
您需要安装Image和pillow,这是与Python相关的技术。放心,命令行会为您处理一切。
输入以下命令:
python -m pip install image
使用Pillow替代PIL,它可以正常工作。
easy_install Pillow
或者
pip install Pillow
pip(3) uninstall Pillow
pip(3) uninstall PIL
pip(3) install Pillow
pip install image
在脚本中:
import image
请使用pil代替PIL
from pil import Image
from PIL import Image
,但这种方法不起作用。 - Janne Karilaeasy_install Pillow
。Pillow是PIL的一个分支,具有更好的打包和支持Python 3的功能。 - Lennart Regebropip install Pillow
命令进行安装。然后您就可以使用import PIL.Image
进行导入。 - Tiago Martins Peres