Python 由于导入模块错误,无法启动gunicorn.service

Python 由于导入模块错误,无法启动gunicorn.service,python,django,gunicorn,systemd,Python,Django,Gunicorn,Systemd,我正试图从systemd服务文件启动Gunicorn,但收到导入模块错误。我怎样才能修好它 我的gunicorn服务文件: [Unit] Description=gunicorn daemon After=network.target [Service] User=sammy Group=www-data WorkingDirectory=/home/sammy/myproject ExecStart=/home/sammy/myproject/venv/bin/gunicorn --work

我正试图从systemd服务文件启动Gunicorn,但收到导入模块错误。我怎样才能修好它

我的gunicorn服务文件:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myproject
ExecStart=/home/sammy/myproject/venv/bin/gunicorn --workers 3 --bind unix:/home/sammy/myproject/myproject.sock myproject.wsgi:application

[Install]
WantedBy=multi-user.target
当我执行
gunicorn--bind 0.0.0.0:8000 myproject.wsgi:application
时,没有错误

但是当我使用

sudo systemctl start gunicorn
sudo systemctl enable gunicorn
我得到这个错误:

ImportError: No module named 'myproject'

怎么了?

可能是目录权限问题。确保用户sammy在www数据组中,并使用chmod 710设置主目录权限。

改进了格式,在请求发布中指出了问题