我正在尝试使用 Wand 打开 PDF 作为图像。如果我在 Jupyter Notebook 中运行下面的代码,它工作正常。如果我从命令提示符将代码作为脚本运行,我会收到一条错误消息。出于某种原因,该模块在 Jupyter Notebook 之外运行时不会加载。有没有人有什么建议?
window
Python 3.7.2(64 位)
from wand.image import Image
with Image(filename="C:/test.pdf", resolution=300) as img:
print(type(img))
这是错误信息:
Traceback (most recent call last):
File "C:\Untitled.py", line 7, in <module>
from wand.image import Image
File "C:\Users\spencer.rand\AppData\Local\Programs\Python\Python37\lib\site-packages\wand\image.py", line 18, in <module>
from . import compat
File "C:\Users\spencer.rand\AppData\Local\Programs\Python\Python37\lib\site-packages\wand\compat.py", line 25, in <module>
abc = collections.abc if PY3 else collections
File "C:\Users\spencer.rand\AppData\Local\Programs\Python\Python37\lib\collections\__init__.py", line 55, in __getattr__
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
AttributeError: module 'collections' has no attribute 'abc'
最佳答案
两周前修复的魔杖和收藏品似乎存在问题:https://github.com/emcconville/wand/pull/398
尝试更新您的魔杖安装:pip install --upgrade wand
关于python - 为什么我的 Python 代码可以在 Jupyter Notebook 中运行,但不能作为脚本运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55305642/