Uwsgi with flask and python3 conda environment is loading python2 instead

anacondaflaskuwsgi

I'm trying to run a python3 flask web application with uwsgi.

If I run /usr/bin/uwsgi --ini /var/www/QCQuan/uwsgi_config.ini --logto /tmp/log then uwsgi fails and the log file shows:

Python version: 2.7.15rc1 (default, Apr 15 2018, 21:51:34)  [GCC 7.3.0]
Set PythonHome to /home/pdiracdelta/.conda/envs/qcquan
ImportError: No module named site

Even though I did adapt my uwsgi_config.ini with

[uwsgi]
...
venv = /home/pdiracdelta/.conda/envs/qcquan
plugins = python
...

to use the python plugin which I installed with apt-get install uwsgi-plugin-python and to use the conda virtual environment which has all the right packages, and only python3.

It seems that uwsgi is still trying to use my system's /usr/bin/python, which points to python2. And it also seems to load it before it sets the PythonHome.

How can I tell uwsgi to use the python (=python3) provided by the conda environment?

Best Answer

Solved by installing uwsgi-plugin-python3 and using plugins = python3 (instead of python(2)) in my uwsgi_config.ini.

I don't fully understand why this works, because uwsgi still seems to load python before setting the PythonHome:

Python version: 3.6.5 (default, Apr  1 2018, 05:46:30)  [GCC 7.3.0]
Set PythonHome to /home/pdiracdelta/.conda/envs/qcquan

So I still suspect it's using my system's /usr/bin/python3 even though it does have access to all the packages in the conda environment.