简体   繁体   中英

sh: convert: command not found on spyder

I was working on spyder(python 2.7), and I got this ( My code ). Can you explain what is the problem?

Thanks!


Oh sorry, here is the code

import numpy as np
import pylab as plt
import os

g = 10
v_o = 10
alph = np.pi/4
N_fram = 20
t_i = 0
t_f = 1.4
t_pas = (t_f - t_i)/N_fram
X_min, X_max, Y_min, Y_max = 0, 12, 0, 3

for n in range(N_fram):
    t = t_i + n*t_pas
    y = -(1/2)*g*t**2 + v_o*np.sin(alph)*t
    x = v_o*np.cos(alph)*t
    plt.plot(x, y, 'o', color = 'b')
    if n == (N_fram-1):
        plt.text(6, 2, "Boom !", fontsize=20)
    plt.axis([X_min, X_max, Y_min, Y_max])
    filename = 'fichierTemp'+str('%02d' %n)+'.pdf'
    plt.savefig(filename)
    print('Nplot=', n)
    plt.clf()

cmd = 'convert -delay 50 -loop 0 fichierTemp*.pdf TrajectoireBoulet.gif'
os.system(cmd)
os.system('rm fichierTemp*.pdf')
print("C'est fini !")

It's a gif( TrajectoireBoulet.gif ) but on my Mac, it's just a photo group( this )

And, when I write "convert" in the terminal, I got:

Copyright: © 1999-2020 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI 
Delegates (built-in): bzlib cairo fftw fontconfig freetype gvc jbig jng 
jp2 jpeg lzma pangocairo png rsvg tiff webp xml zlib
Usage: convert [options ...] file [ [options ...] file ...] [options...] file

Try including the full path to convert , eg /usr/local/bin/convert ...

You can find it by running this in Terminal:

type convert

Also, PDF is not the best choice for the individual frames of your animation, because ImageMagick requires the external Ghostscript program in order to read them, so I would suggest you use PNG files as the intermediate format as follows:

#!/usr/bin/env python3

import numpy as np
import pylab as plt
import os

g = 10
v_o = 10
alph = np.pi/4
N_fram = 20
t_i = 0
t_f = 1.4
t_pas = (t_f - t_i)/N_fram
X_min, X_max, Y_min, Y_max = 0, 12, 0, 3

for n in range(N_fram):
    t = t_i + n*t_pas
    y = -(1/2)*g*t**2 + v_o*np.sin(alph)*t
    x = v_o*np.cos(alph)*t
    plt.plot(x, y, 'o', color = 'b')
    if n == (N_fram-1):
        plt.text(6, 2, "Boom !", fontsize=20)
    plt.axis([X_min, X_max, Y_min, Y_max])
    filename = 'fichierTemp'+str('%02d' %n)+'.png'
    plt.savefig(filename)
    print('Nplot=', n)
    plt.clf()

cmd = '/full/path/to/convert -delay 50 -loop 0 fichierTemp*.png TrajectoireBoulet.gif'
os.system(cmd)
#os.system('rm fichierTemp*.pdf')
print("C'est fini !")

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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