I'm trying to make a service with run my Flask app with Gunicorn. Service file look like this:
[Unit]
Description=metrofind
After=network.target
[Service]
User=ubuntu
Group=ubuntu
Restart=on-failure
WorkingDirectory=/home/ubuntu/geoMetroFinding/
ExecStart=/home/ubuntu/geoMetroFinding/flaskenv/bin/gunicorn -c /home/ubuntu/geoMetroFinding/gunicorn.conf -b 0.0.0.0:5000 main_flask:app
[Install]
WantedBy=multi-user.target
in the log-error file it writes:
ImportError: No module named 'pandas'
or
ImportError: No module named 'main_flask'
but in virtual env, all necessary packages were installed.
And when I run locally from directory "geoMetroFinding" in console this command:
gunicorn -c gunicorn.conf -b 0.0.0.0:5000 main_flask:app
App is running
What is wrong?
You have to set the environment in the service file.
An example of the [Service] section would be like this:
[Service]
User=ubuntu
Group=ubuntu
Restart=on-failure
WorkingDirectory=/home/ubuntu/geoMetroFinding/
Environment="PATH=/home/ubuntu/geoMetroFinding/flaskenv/bin"
ExecStart=/home/ubuntu/geoMetroFinding/flaskenv/bin/gunicorn -c /home/ubuntu/geoMetroFinding/gunicorn.conf -b 0.0.0.0:5000 main_flask:app
So you need to add the Environment to your PATH in order to make this work.
Take a look at this great tutorial for more info.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.