启动Gunicorn服务时遇gevent未安装错误及systemd配置问题
Got it, let's get this Gunicorn service up and running smoothly. The error you're hitting is straightforward—your setup is trying to use the gevent worker type, but the gevent Python package isn't available to the process running the systemd service. Here's how to fix it step by step:
1. Install the gevent dependency
First, make sure gevent is installed in the correct Python environment your Gunicorn uses:
- If you're using a virtual environment (highly recommended for Python apps), activate it first and install:
source /home/ubuntu/webClient/venv/bin/activate pip install gevent - If you're using the global Python environment (not ideal, but works if you don't have a venv):
pip install gevent
2. Update your systemd service file to match your environment
A common mistake here is systemd using a global Gunicorn binary that doesn't have access to your installed gevent package (especially if you used a virtual environment). Update your rayaanWebCli.service file with these tweaks:
[Unit] Description="gunicorn server for rayaan " [Service] User=ubuntu # Add this to run the service as your ubuntu user, matching your local environment WorkingDirectory=/home/ubuntu/webClient Type=simple # Use the Gunicorn binary from your virtual environment instead of the global one ExecStart=/home/ubuntu/webClient/venv/bin/gunicorn --worker-class gthread -k gevent --worker-connections 1000 --workers 10 --threads 20 --log-level DEBUG --bind 0.0.0.0:7777 application:application [Install] WantedBy=multi-user.target
3. Reload and restart the service
After making these changes, apply the updates and check the service status:
systemctl daemon-reload systemctl restart rayaanWebCli systemctl status rayaanWebCli
This should resolve the RuntimeError—your service will now find the gevent package and start successfully.
内容的提问来源于stack exchange,提问作者The Entity

