【发布时间】:2020-01-17 09:47:50
【问题描述】:
我有一个 Python 应用程序,它可以将整个 PDF 文件转换为几个 jpg。 在 Pycharm 中是通过代码实现的:
import subprocess
subprocess.check_call(["magick",Platforma_IoT.pdf,Platforma_IoT.jpg], shell=True)
Windows 10 上 Pycharm 中的代码完全可以正常工作,它将 pfd 的每一页转换为 jpg。但现在我想使用 Bash 控制台运行该代码。不幸的是,我在 Bash 中遇到错误:
import-im6.q16: unable to open X server `' @ error/import.c/ImportImageCommand/358.
./sd.py: line 3: syntax error near unexpected token `["magick","Platforma_IoT.pdf","Platforma_IoT.jpg"],'
./sd.py: line 3: `subprocess.check_call(["magick","Platforma_IoT.pdf","Platforma_IoT.jpg"], shell = True)'
我也试过那个代码:
import subprocess
subprocess.check_call(["convert","Platforma_IoT.pdf","Platforma_IoT.jpg"])
但是我在 bash 中遇到了同样的错误。
我只想运行代码,使用 bash 控制台将 PDF 的每一页转换为图像。我该怎么做?
【问题讨论】:
-
在 bash 窗口中,只需键入:
convert Platforma_IoT.pdf Platforma_IoT.jpg。那是假设你已经编译了 ImageMagick 并且 ImageMagick 的路径在你的 $PATH 环境变量中。否则,将 ImageMagick 的完整路径作为转换命令的一部分 -
@fmw42 我将 ImageMagick 添加到环境变量中,但它对我没有帮助。 “魔术:未找到”。如何在 bash 命令中直接传递 ImageMagick 路径?现在我只需输入“python3 name.py
-
但是,我在添加环境变量时遇到了问题。我在“.bashrc”文件中添加了:`ImageMagick='/mnt/c/Program Files/ImageMagick-7.0.9-Q16 export ImageMagick 'export PATH=$PATH:ImageMagick/bin' 但 $ImageMagick 输出看起来像:- bash /mnt/c/Program: 没有这样的文件或目录。我试过 ImageMagick=/mnt/c/Program\ Files/ImageMagick7.0.9-Q16 但它不起作用
-
好的,我使用了那个链接:tecmint.com/install-imagemagick-on-debian-ubuntu,它终于可以工作了。
标签: python bash imagemagick