使用Systemctl找不到Python

2024-06-02 16:46:17 发布

您现在位置:Python中文网/ 问答频道 /正文

伙计们,我在systemctl中有一个错误,告诉我python没有找到。在下面的.service文件中,我运行芹菜节拍。在my tasks.py中,我有一个代码片段,它使用os.system运行python代码

# My .service
[Unit]
Description=Celery Service
After=network.target

[Service]
Type=forking
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu/my_project_folder
ExecStart=/bin/sh -c '/home/ubuntu/enviq/bin/celery -A projectdjango worker -l info -B --scheduler django_celery_beat.schedulers:DatabaseScheduler &'
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target
# Error when execute sudo journalctl -xe
Apr 30 16:13:01 ip-172-31-17-187 sh[16228]: [2020-04-30 13:13:01,155: INFO/MainProcess] Received task: app_iq_option01.tasks.get_candles_tasks[d1d14df
Apr 30 16:13:01 ip-172-31-17-187 sh[16228]: sh: 1: python: not found
Apr 30 16:13:01 ip-172-31-17-187 sh[16228]: sh: 1: python: not found
# In this line I use the module os to call main_tasks.py
command = "python main_tasks.py {} {} {} '%s'".format(cred.email, cred.password, cred.max_samples)
command = command % coins
os.system(command)

当我运行命令在终端上运行芹菜而不使用systemctl时,它工作正常。有人能帮我吗?我真的很感激!似乎systemd不认识我的virtualenv(它称为venviq)


Tags: 代码pyipbinosubuntumysh