簡體   English   中英

為什么我的Python代碼在Jupyter Notebook中工作,而不是作為腳本?

[英]Why does my Python code work in Jupyter Notebook but not as a script?

我正在嘗試使用Wand打開PDF作為圖像。 如果我在Jupyter Notebook中運行下面的代碼,它可以正常工作。 如果我從命令提示符作為腳本運行代碼,我收到一條錯誤消息。 出於某種原因,當模塊在Jupyter Notebook外部運行時,模塊將不會加載。 有沒有人有什么建議?

視窗

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'

看起來2周前修復了魔杖和收藏品的問題: https//github.com/emcconville/wand/pull/398

嘗試更新你的魔杖安裝: pip install --upgrade wand

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM