无法导入PIL图像

时间:2016-01-05 14:44:56

标签: 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(),但我不知道该怎么做。

有什么建议吗?

1 个答案:

答案 0 :(得分:4)

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

这部分异常表明您的代码中有一个名为threading的模块。然而,threading模块是标准库的一部分,通过创建一个名为线程的模块,您几乎可以覆盖标准库。所以PIL正在寻找不存在的方法和类。您必须将代码中的线程模块重命名为其他内容,并且一切都应该正常工作。