从crontab调用时,Python脚本崩溃

时间:2019-11-22 20:29:24

标签: python-3.x cron imagemagick digital-ocean moviepy

我有一个脚本(托管在DigitalOcean ubuntu 18.04.3 Droplet上),从crontab执行,看起来像这样

  

0 5 * * * cd / home / john / clips /; / home / john / clips / venv / bin / python3 /home/john/clips/clip_compilator.py

它可以工作,但是一旦到达其中一个脚本的以下行

name = mp.TextClip(f"John".upper(), 
    color='#6441A4', 
    stroke_color="black", 
    align='West',
    fontsize=90, 
    font='BigNoodleTitling', method='label')\
                        .margin(left=95, opacity=0)\
                        .set_position(("left", "top"))

它崩溃

Traceback (most recent call last):
  File "/home/john/clips/venv/lib/python3.6/site-packages/moviepy/video/VideoClip.py", line 1161, in __init__
    subprocess_call(cmd, logger=None)
  File "/home/john/clips/venv/lib/python3.6/site-packages/moviepy/tools.py", line 46, in subprocess_call
    proc = sp.Popen(cmd, **popen_params)
  File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'unset': 'unset'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/john/clips/clip_compilator.py", line 44, in <module>
    current_clip.add_videofile(add_text(current_clip))
  File "/home/john/clips/clip_editor.py", line 16, in add_text
    fontsize=90, font='BigNoodleTitling', method='label')\
  File "/home/john/clips/venv/lib/python3.6/site-packages/moviepy/video/VideoClip.py", line 1170, in __init__
    raise IOError(error)
OSError: MoviePy Error: creation of None failed because of the following error:

[Errno 2] No such file or directory: 'unset': 'unset'.

.This error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect

当我在bash中(在crontab之外)运行相同的命令时,一切正常。
由于某种原因,它专门在TextClip上崩溃了,我不知道为什么。
有人建议解决方案可能是注释掉ImageMagick的policy.xml中的特定行,但是我的convert -list policy输出是这样的:

enter image description here

1 个答案:

答案 0 :(得分:1)

通过添加

解决了该问题
from moviepy.config import change_settings
change_settings({"IMAGEMAGICK_BINARY": "/usr/local/bin/convert"})

clip_editor.py的顶部,根据tomasdms's解决方案,该行具有导致错误的行