gpt4 book ai didi

python - 使用特定的 python 版本将 python 脚本作为 Upstart 服务运行

转载 作者:太空宇宙 更新时间:2023-11-04 08:58:47 25 4
gpt4 key购买 nike

我正在为我的 centOs 服务器上的 python 脚本设置 Upstart 服务。虽然脚本需要 python 2.7 才能工作。但是服务器上的默认 python 版本是 2.6,我不想更改它,因为我担心其他脚本会失败。

我已经安装了 python 2.7 并对其进行了测试,它与我的脚本完美配合。虽然我想知道我应该如何编写 .conf 文件以使文件使用 python 2.7 执行。因为现在我收到一条“作业无法启动”的消息。我相信这可能是因为它在执行脚本时使用的是 2.6。

这是我当前的 conf 文件(虽然目录和文件名已更改):

description "MY SCRIPT DESCRIPTION"
author "MY NAME"

start on runlevel [234]
stop on runlevel [0156]

chdir /home/aUser/scriptLocation
exec /home/aUser/scriptLocation/theScript.py
respawn

最佳答案

您可以直接调用 Python 可执行文件并将脚本作为参数传递,而不是调用脚本本身。

exec /path/to/my/python2.6 /home/aUser/scriptLocation/theScript.py

关于python - 使用特定的 python 版本将 python 脚本作为 Upstart 服务运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25694533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com