0

I am trying to install python library "PythonMagick" on the Ubuntu.

On the Windows 10 I used this link: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonmagick

And it works fine. For example (using PyCharm and Windows 10), that code converts every page of pdf into an image (jpg):

import PythonMagick
import subprocess

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

But when I run the same program in the bash, bash says:

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.

It looks like my bash doesn't have that library. How can I make that code work on the Ubuntu?

MuscleUpUp
  • 121
  • 2
  • 10

1 Answers1

2

Try

import subprocess

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

if you have imagemagick installed.

Otherwise

sudo apt-get update
sudo apt-get install imagemagick --fix-missing
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • Now bash says: `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.` – MuscleUpUp Jan 16 '20 at 08:38
  • Try from the command line first as you don't need python to invoke a command. Perhaps you need to install `gs` too. – Diego Torres Milano Jan 17 '20 at 02:52
  • I have ghostscript installed – MuscleUpUp Jan 17 '20 at 15:49