[英]Why does my Python code work in Jupyter Notebook but not as a script?
I'm trying to open up a PDF as an image using Wand. 我正在尝试使用Wand打开PDF作为图像。 If I run the code below in Jupyter Notebook, it works fine.
如果我在Jupyter Notebook中运行下面的代码,它可以正常工作。 If I run the code as a script from Command Prompt, I get an error message.
如果我从命令提示符作为脚本运行代码,我收到一条错误消息。 For some reason, the module won't load when it's run outside of Jupyter Notebook.
出于某种原因,当模块在Jupyter Notebook外部运行时,模块将不会加载。 Does anyone have any suggestions?
有没有人有什么建议?
Windows 视窗
Python 3.7.2 (64 bit) Python 3.7.2(64位)
from wand.image import Image
with Image(filename="C:/test.pdf", resolution=300) as img:
print(type(img))
This is the error message: 这是错误消息:
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'
Looks like there's an issue with wand and collections that was fixed 2 weeks ago: https://github.com/emcconville/wand/pull/398 看起来2周前修复了魔杖和收藏品的问题: https : //github.com/emcconville/wand/pull/398
Try updating your wand install: pip install --upgrade wand
尝试更新你的魔杖安装:
pip install --upgrade wand
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.