【问题标题】:Python script crashes when called from crontab从 crontab 调用 Python 脚本时崩溃
【发布时间】:2019-11-23 07:28:08
【问题描述】:

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

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 输出是这样的:

【问题讨论】:

  • 是否有一个 unset 随 ImageMagick 分发的二进制文件? (实际上看起来更像是它依赖于unset shell command..?如果是这样,也许有一个不同的默认shell不兼容..源代码是什么样的?:D)
  • @user2864740 你是说python脚本的源代码还是crontab的源代码?
  • 使用/尝试使用“unset”的代码。
  • 不管怎样,/bin/sh(指向)是什么?如果不是bash,可能值得一试。对底层代码的作用做出几个假设。
  • askubuntu.com/questions/328364/… - 使用ls -l /bin/sh 显示它指向的位置。将其重新链接到其他地方是 global 更改。此外,如果所述目标支持unset,那么我将不理会它(请参阅相应的手册)。

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


【解决方案1】:

通过添加解决了问题

from moviepy.config import change_settings
change_settings({"IMAGEMAGICK_BINARY": "/usr/local/bin/convert"})

clip_editor.py 的顶部,其中包含根据 tomasdms's 解决方案导致错误的行

【讨论】:

    猜你喜欢
    • 2020-09-09
    • 1970-01-01
    • 2014-07-21
    • 2019-03-15
    • 1970-01-01
    • 1970-01-01
    • 2022-06-21
    • 2011-02-24
    • 1970-01-01
    相关资源
    最近更新 更多