简体   繁体   English

为什么我的Python代码在Jupyter Notebook中工作,而不是作为脚本?

[英]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.

相关问题 我的代码在 Jupyter Notebook 中工作,但不是 Python 脚本 - My code works in Jupyter Notebook but not as Python script 为什么 Jupyter 笔记本在我的代码中存在 Pycharm 没有的问题? - Why does Jupyter notebook have problems with my code that Pycharm does not? 为什么此脚本在空闲状态下运行,而不在Jupyter Notebook中运行? - Why does this script run in Idle but not in Jupyter Notebook? python“inquirer”模块是否不适用于 Jupyter Notebook? - Does python "inquirer" module not work with Jupyter Notebook? Jupyter Notebook中的Python多处理不起作用 - Python Multiprocessing within Jupyter Notebook does not work Jupyter Notebook-Python代码 - Jupyter Notebook - Python Code 为什么 %%timeit 在 Jupyter Notebook 中工作正常,但在 Python Shell IDLE 中抛出 SyntaxError? - Why does %%timeit work fine in Jupyter Notebook but throws SyntaxError in Python Shell IDLE? 为什么它不能在 Jupyter 笔记本上运行而在命令提示符下运行? - Why it does not run on Jupyter notebook while does work on command prompt? 为什么我的 pymc3 采样器在 Jupyter 笔记本中使用 C 代码? - Why does my pymc3 sampler use C code in Jupyter notebook? Jupyter Notebook 中的 Python Matplotlib get_xticklabels - 为什么它在与绘图代码相同的单元格中返回一个空白列表? - Python Matplotlib get_xticklabels in Jupyter Notebook - why does it return a blank list in same cell as plot code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM