Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a conda env with uwsgi and supervisor?

I'm trying to run a Flask app using a conda env with uwsgi and supervisor.

I managed to solve a first issue regarding the path of the wsgi script, but I cannot find how to set the conda env.

My uwsgi config file /home/me/Development/flask/myflaskapp/myflaskapp.ini is

[uwsgi]
module = wsgi
master = true
process = 2
chmod-socket = 666
chdir = /home/me/Development/flask/myflaskapp
socket = /home/me/Development/flask/myflaskapp/run/myflaskapp.sock
callable = app
vacuum = true

and my supervisor config is

[program:uwsgi-myflaskapp]
command=/home/me/Development/miniconda/envs/myflaskapp/bin/uwsgi /home/me/Development/flask/myflaskapp/myflaskapp.ini
autostart=true
autorestart=true
stdout_logfile=/home/me/Development/flask/myflaskapp/log/uwsgi-myflaskapp.log
redirect_stderr=true
exitcodes=0

When I start uwsgi through supervisor I get

*** Operational MODE: single process ***
Traceback (most recent call last):
  File "./wsgi.py", line 1, in <module>
    from myflaskapp import app
  File "./myflaskapp/__init__.py", line 1, in <module>
    from flask import Flask
ImportError: No module named flask

So I guess I the conda env is not set. How can I set it?

like image 746
jul Avatar asked Jan 12 '16 09:01

jul


2 Answers

I had to set PATH in my supervisor config file

environment=PATH=/home/me/Development/miniconda/envs/myflaskapp/bin
like image 118
jul Avatar answered Oct 19 '22 15:10

jul


You use the -H tag when starting uwsgi from the command line to set the Python path

http://uwsgi-docs.readthedocs.org/en/latest/Options.html#virtualenv

So in your case, in the supervisor config, change your command to:

command=/home/me/Development/miniconda/envs/myflaskapp/bin/uwsgi -H /path/to/your/virtualenv /home/me/Development/flask/myflaskapp/myflaskapp.ini

You can find your virtualenv path with

which python

On the command line with your virtualenv activated.

like image 2
Peter Trotman Avatar answered Oct 19 '22 16:10

Peter Trotman