4

I'm trying to open up a PDF as an image using Wand. If I run the code below in Jupyter Notebook, it works fine. 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. Does anyone have any suggestions?

Windows

Python 3.7.2 (64 bit)

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'
sprand
  • 43
  • 4

1 Answers1

3

Looks like there's an issue with wand and collections that was fixed 2 weeks ago: https://github.com/emcconville/wand/pull/398

Try updating your wand install: pip install --upgrade wand

Danielle M.
  • 3,607
  • 1
  • 14
  • 31
  • Thanks but it looks like I've got the latest version: Requirement already up-to-date: wand in c:\users\spencer.rand\appdata\local\programs\python\python37\lib\site-packages (0.5.1) – sprand Mar 22 '19 at 19:07
  • @spencerrand Issue resolved in version 0.5.2, which should be release & distributed by now. – emcconville Mar 24 '19 at 20:30
  • This doesn't explain why it works in Jupyter notebook but not as a script, but you were both right in getting the script to work. I upgraded to 0.5.2, which is what Danielle suggested, and that worked. Thank you @emcconville and Danielle for your help. – sprand Mar 25 '19 at 13:44
  • @spencerrand it might that Jupyter notebook has access to a different version within it's environment - that was the guess my answer was based on. – Danielle M. Mar 25 '19 at 19:57