问题
So I have installed Wand, Ghostscript, ImageMagick. I am trying to convert a PDF to Image. My Code is as following.
Code:
from wand.image import Image
image_pdf = Image(filename="/<fullpath>/xyz.pdf", resolution=500)
image_jpeg = image_pdf.convert('jpeg')
print (len(image_jpeg.sequence))
When I run the code through terminal (I mean open python terminal and paste the code there), it works. But the same code fails in PyCharm.
Error:
File "/usr/local/lib/python2.7/site-packages/wand/resource.py", line 222, in raise_exception
raise e
wand.exceptions.DelegateError: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r500x500' '-sOutputFile=/var/folders/61/7q0vknr92mndbbgzqvsk3xl4r4yw3f/T/magick-24738xypZ5LDqNaTJ%d' '-f/var/folders/61/7q0vknr92mndbbgzqvsk3xl4r4yw3f/T/magick-24738Tr70PW391Vdt' '-f/var/folders/61/7q0vknr92mndbbgzqvsk3xl4r4yw3f/T/magick-24738wI4q1Lv6Aich'' (1) @ error/pdf.c/InvokePDFDelegate/292
Exception TypeError: TypeError("object of type 'NoneType' has no len()",) in <bound method Image.__del__ of <wand.image.Image: (empty)>> ignored
I checked the python version in terminal
which python2
and I get /usr/local/bin/python2
My PyCharm pythton Interpreter is located at /usr/local/Cellar/python/2.7.13_1/....
What am I missing here?
回答1:
You should look to isolate your Python environment from your system Python (and yes, your Homebrew installation would be considered a system Python installation too) by using virtualenvwrapper.
From what I'm seeing, the Python that your system is using is not the same Python that PyCharm is using. While that can be fixed by going to Settings > Project Interpreter and selecting the right path for your interpreter...
...it would be best to ensure that you install all of the necessary dependencies your project needs in an isolated virtual environment instead.
回答2:
The issue was that since PyCharm was not starting through Terminal it was not picking up all the Path Variables and hence was not able to find the required dependencies (I assume GhostScript might be the missing dep here)
So when I started PyCharm from Terminal, it worked.
来源:https://stackoverflow.com/questions/46141661/wand-and-ghostscript-issue-on-pycharm