无法导入 PIL 图像
Cannot import PIL Image
我只是想尝试使用一段代码将一张图片粘贴到另一张图片上。好吧,我不能走得更远,因为 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 正在寻找不存在的方法和 类。您必须将代码中的线程模块重命名为其他名称,一切正常。
我只是想尝试使用一段代码将一张图片粘贴到另一张图片上。好吧,我不能走得更远,因为 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 正在寻找不存在的方法和 类。您必须将代码中的线程模块重命名为其他名称,一切正常。