python - 无法导入 PIL 图像

标签 python python-2.7 python-imaging-library python-import

我只是想尝试使用一段代码将一张图片粘贴到另一张图片上。好吧,我不能走得更远,因为在导入时会引发 AttributeError

from PIL import Image

# image_path = "/Users/me/images/"
# fg_file = "hello-600x600.jpg"
# bg_file = "deer-1.jpg"
#
# bg = Image.open(image_path + bg_file)
# fg = Image.open(image_path + fg_file)
#
# bg.paste(fg, (10, 10), fg)
# bg.show()

通过导入,我得到了以下输出:

Traceback (most recent call last):
  File "/Users/me/dev/pyExamples/image_manipulation/merge_images.py", line 3, in <module>
    from PIL import Image
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 31, in <module>
    import logging
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 206, in <module>
    _lock = threading.RLock()
AttributeError: 'module' object has no attribute 'RLock'
Exception AttributeError: '_shutdown' in <module 'threading' from '/Users/me/dev/pyExamples/threading/__init__.pyc'> ignored

Process finished with exit code 1 

我好像是从方法threading.RLock()来的,但是不知道这里要干什么。

有什么建议吗?

最佳答案

'/Users/me/dev/pyExamples/threading/__init__.pyc'

这部分异常表明您的代码中有一个名为 threading 的模块。 threading然而,模块是标准库的一部分,通过创建一个名为线程的模块,您实际上是在覆盖标准库。因此 PIL 正在寻找不存在的方法和类。您必须将代码中的线程模块重命名为其他名称,并且一切正常。

关于python - 无法导入 PIL 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34614399/

相关文章:

python - 生成Python文件

c++ - 在 c++ boost python 列表中附加整数时出错

python - 如何将配置变量值传递给 pyodbc connect 命令?

python - 枕头安装 PyPy3 缺少 zlib

python - python-pillow 中内核大小大于 5x5 的卷积

python - 为什么与 np.int16 的相同操作相比,dtype np.int64 的操作要慢得多?

python - 如何使用 matplotlib 绘制与 y = x 线平行的线?

python - 删除 DataFrame 中字符串中的第二个字符

python - 在 Pandas 中转换日期时间列的快速方法

python - 圆圈的 RGB 平均值