MarkB MarkB - 5 months ago 22
Python Question

start flask server @ startup with supervisor: FATAL Exited too quickly

I am trying to start my flaskserver at startup with the help of supervisor. But i get this error message:

python_auutostart FATAL Exited too quickly (process log may have details)


This is the entry in my logfile:

Traceback (most recent call last):
File "run.py", line 2, in <module>
from app import app
File "/home/flaskserver/app/__init__.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask


This is my .conf:

[program:python_auutostart]
user=nobody
command = python run.py
directory = /home/flaskserver/
autostart = true
autorestart = true
stderr_logfile=/etc/supervisor/long.err.log
stdout_logfile=/etc/supervisor/long.out.log


I can start my flaskserver without problems if I run ./run.py but I don´t get it to run with supervisor. I don´t see why i get the ImportError i posted. Maybe some1 can point me to my probleme here.

Answer

The python you use is the default system python (you can check that wich which python which should display something like /usr/bin/python or wherever your system python is). This does not have access (by default) to libraries that are installed in a virtual environment. Instead you should use the python that is specific to the virtualenv. You can do that by explicitly calling the python which should be located in /path/to/virtualenv/env/bin/python. You can check that by activating the virtualenv and which python which should output the path to the python of the virtualenv.