6

I'm attempting to run a series of Python apps from supervisor. It works fine on Mac OSX, but when I attempt to run the same app on Ubuntu, supervisor doesn't seem to be activating the virtualenv so my scripts are throwing errors.

Here is my structure:

/home/user/Sites/my-site
- app.py
- venv
- supervisor.conf

My supervisor.conf file looks like this:

[program:python-app]
autorestart = false
autostart = false
startsecs = 0
command = python app.py
startretries = 1
environment=PYTHONPATH="%(here)s"

[unix_http_server]
file = /tmp/supervisor.sock

[supervisord]
logfile = logs/supervisord.log
pidfile = logs/supervisord.pid
environment=PYTHONPATH="%(here)s"

[supervisorctl]
serverurl = unix:///tmp/supervisor.sock

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[unix_http_server]
username = supervisor_admin
password = 

[inet_http_server]
username = supervisor_admin
password = 
port = *:9001

How can I get supervisor to run the python app inside of the virtual enviroment?

Hanpan
  • 183
  • 1
  • 1
  • 4

1 Answers1

16

The command you provide should use the python binary inside the virtual environment:

command = /home/user/Sites/my-site/venv/bin/python /home/user/Sites/my-site/app.py
mgorven
  • 30,036
  • 7
  • 76
  • 121
  • what about packages installed in that virtualenv? will the python detect them automatically? – Prasanth Feb 23 '15 at 20:07
  • 2
    Yes, calling the right Python binary will setup the paths correctly to use packages installed in the virtualenv. – mgorven Feb 23 '15 at 20:11
  • 3
    Are you sure about that @mgorven? It's not doing that for me – skolsuper Jan 11 '16 at 04:35
  • 1
    what about other configurations of virtualenv like postactivate, enviroment vairables? wouldn't it be better to run a command that first activates the virtualenv and then executes the python script? – MikeL Apr 30 '17 at 09:52