python - 为什么我的 Python 代码可以在 Jupyter Notebook 中运行,但不能作为脚本运行?

标签 python jupyter-notebook imagemagick wand

我正在尝试使用 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/

相关文章:

python - 无法在 Windows : No module named '_pyrsistent_version' 上安装 jupyter

python - 在 Jupyter notebook 中保存 pivottablejs 的配置

php - 如何用imagemagick显示图像?

python - Matplotlib 正在打印线图两次/多次

python - 使用函数从指定索引开始对 Python 中不同长度的列表求和

python - 生成 lambda 函数组合的组合

python - TensorFlow 简单音频识别 : Can not squeeze dim[1], 预期维度为 1,得到 2

python - 为什么 LogLocator 每 2 个十年只给我一次刻度?

php - 保存图像异步 CodeIgniter PHP

ruby-on-rails - 添加回形针新样式不影响旧上传的图像