2016-01-05 89 views
3

我只是想尝试一段代码将图像粘贴到另一个上面。那么,我不能再进一步了,因为AttributeError在进口时正好提出。无法导入PIL图像

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(),但我不知道在这里做什么。

什么建议吗?

+0

有趣。 '导入线程'在你的系统上工作吗?怎么样'进口线程;打印threading.RLock'? – Kevin

回答

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

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

+0

完美!我从来没有注意到这种潜在的问题。更好地检查我所有的软件包名称。谢谢! – kaligne