python - 无法在我的 Python 项目中使用 Pillow

标签 python installation pip python-imaging-library

我最近安装了 pip,并使用它在 Ubuntu 14.04 上安装了 Pillow(Python 镜像库)。当我编写一些简单的代码时,如下所示:

import sys

from PIL import Image

im= Image.open('path/to/image.jpg')
im.save('path/to/image2.jpg')

我收到以下错误:

Traceback (most recent call last):
File "/path/to/test.py", line 3, in <module>
from PIL import Image
File "/path/to/test.py", line 3, in <module>
from PIL import Image
ImportError: cannot import name Image

我也尝试过“导入图像”,但这也不起作用。我似乎记得在我安装 Pillow 之前,这曾经隐约有效过一次。似乎其他人都没有这个问题,那么我是否缺少什么?非常感谢。

最佳答案

[总结评论中的答案,以供将来引用]

确保您尚未创建名为 PIL.py(或 PIL.pyc)的文件,因为这会干扰导入。

检查:

导入PIL; 打印(PIL.__文件__)

这应该给你一些像 /foo/bar/site-packages/PIL/__init__.py 这样的路径。而不是像 /home/fin/PIL.py 这样的东西。

关于python - 无法在我的 Python 项目中使用 Pillow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25943238/

相关文章:

numpy - 即使安装了 Chapel,Pip Install Arkouda 也会失败

python - 在 Django 1.6 中使用另一个 url slug 从 View 重定向到另一个 html 页面

Python过滤器去除图像中的异常值

python - 我该如何解决这个错误?名称错误 : name ‘model’ is not defined

magento - 在 Magento 设置脚本中添加 auto_increment 列,而不使用 SQL

android - 如何批量安装软件到Samsung Galaxy Tab 10.1

windows - 禁用 UAC 虚拟化后恢复文件

python - 如何从本地 Python 项目的 Yocto 配方中的 requirements.txt 安装依赖项

pip - 如何在Keras中更改预训练模型的默认下载目录?

python - pickle 包装的部分功能