简体   繁体   English

PyCharm上的魔杖和Ghostscript问题

[英]Wand and ghostscript issue on PyCharm

So I have installed Wand, Ghostscript, ImageMagick. 所以我已经安装了Wand,Ghostscript,ImageMagick。 I am trying to convert a PDF to Image. 我正在尝试将PDF转换为图像。 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. 当我通过终端运行代码时(我的意思是打开python终端并将代码粘贴到那里),它可以工作。 But the same code fails in PyCharm. 但是相同的代码在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 我在终端which python2检查了python版本,并得到了/usr/local/bin/python2

My PyCharm pythton Interpreter is located at /usr/local/Cellar/python/2.7.13_1/.... 我的PyCharm pythton解释器位于/usr/local/Cellar/python/2.7.13_1/....

What am I missing here? 我在这里想念什么?

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 . 您应该使用virtualenvwrapper将Python环境与系统Python隔离(是的,您的Homebrew安装也将被视为系统Python安装)。

From what I'm seeing, the Python that your system is using is not the same Python that PyCharm is using. 据我所见,您的系统使用的Python与PyCharm使用的Python不同。 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. ...最好确保将项目需要的所有必要依赖项安装在隔离的虚拟环境中。

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) 问题在于,由于PyCharm不是从终端启动的,因此没有拾取所有路径变量,因此无法找到所需的依赖项(我认为GhostScript可能是此处缺少的dep)

So when I started PyCharm from Terminal, it worked. 因此,当我从Terminal启动PyCharm时,它起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM