【问题标题】:PythonMagick installation on Ubuntu在 Ubuntu 上安装 PythonMagick
【发布时间】:2020-05-02 11:41:42
【问题描述】:

我正在尝试在 Ubuntu 上安装 python 库“PythonMagick”。

在 Windows 10 上,我使用了这个链接:https://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonmagick

而且效果很好。例如(使用 PyCharm 和 Windows 10),该代码将 pdf 的每一页转换为图像 (jpg):

import PythonMagick
import subprocess

subprocess.check_call(["magick","Platforma_IoT.pdf","Platforma_IoT.jpg"], shell=True)

但是当我在 bash 中运行相同的程序时,bash 会说:

Platforma_IoT.pdf: 1: Platforma_IoT.pdf: magick: not found
Traceback (most recent call last):
  File "sd.py", line 12, in <module>
    subprocess.check_call(["magick","Platforma_IoT.pdf","Platforma_IoT.jpg"], shell=True)
  File "/usr/lib/python3.6/subprocess.py", line 311, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['magick', 'Platforma_IoT.pdf', 'Platforma_IoT.jpg']' returned non-zero exit status 127.

看起来我的 bash 没有那个库。如何使该代码在 Ubuntu 上运行?

【问题讨论】:

    标签: python bash pythonmagick


    【解决方案1】:

    试试

    import subprocess
    
    subprocess.check_call(["convert","Platforma_IoT.pdf","Platforma_IoT.jpg"])
    

    如果您安装了imagemagick

    否则

    sudo apt-get update
    sudo apt-get install imagemagick --fix-missing
    

    【讨论】:

    • 现在 bash 说:By default, the image format of 'file' is determined by its magic number. To specify a particular image format, precede the filename with an image format name and a clon (i.e. ps:image) or specify the image type as the filename suffix (i.e. image.ps). Specify 'file as '-' for standard input or output. Subprocess.CalledProcessError: Command '['convert', 'Platforma_IoT.pdf', 'Platforma_IoT.jpg']' returned non-zero exit status 1.
    • 首先从命令行尝试,因为您不需要 python 来调用命令。或许你也需要安装gs
    • 我安装了 ghostscript
    猜你喜欢
    • 2012-10-27
    • 2015-03-25
    • 2017-05-12
    • 2017-01-12
    • 2018-08-26
    • 2012-05-05
    • 2018-06-17
    • 2012-01-14
    • 2011-06-11
    相关资源
    最近更新 更多