Sai Wai Maung
Sai Wai Maung

Reputation: 1617

uWSGI flask.ini uses global Python or virtualevn Python?

This following codes are inside a uWSGI configuration file called flask1.ini:

[uwsgi]
socket = /tmp/flask1.sock
chmod-socket = 777
evn = PRODUCTION=TRUE
module = indy
callable = app
processes = 4
threads = 2
logto = /var/indylog

The production server is set up on ubuntu 14.04 using uWSGI and nginx for Flask application.

I wrote a new module that uses Python 2.7 and it runs without any error on my local ubuntu 14.04 virtualenv (Flask development server) and the same nginx and uWSGI set up as the production environment. However, when I deployed the same code live on production server, it gives a bunch of syntax errors, I am trying to figure out why this is the case.

I run python --version on my local desktop and production server, they are both Python 2.7.6.

My questions: with the above uWSGI configuration on production server, which Python is being used? The machine Python or virtualenv Python?

Upvotes: 0

Views: 942

Answers (3)

Sai Wai Maung
Sai Wai Maung

Reputation: 1617

Install uwsgi in the virtualenv to use whichever Python version the env is configured with. /path/to/env/bin/uwsgi --ini /path/to/flask.ini. Instead of global uwsgi path/to/your/flask.ini, which would use the Python version that the system installed.

Upvotes: 1

Nguyen Sy Thanh Son
Nguyen Sy Thanh Son

Reputation: 5376

At first, you have to create Python 3 environment for your source code: virtualenv -p /usr/bin/python3 path_to_your_project/env

And install packets required:

cd path_to_your_project
source env/bin/activate
# you can use pip to install packets required, e.g:
pip install -r requirements.txt

Finally, add virtualenv to your uwsgi.ini file:

virtualenv = path_to_your_project/env

Upvotes: 1

gbs
gbs

Reputation: 1325

To be precise, neither. uwsgi does not actually run the Python binary, it uses libpython directly. It just follows your system's LD_LIBRARY_PATH to find the corresponding libpython library and this is normally not affected by virtualenv.

What is affected by virtualenv, however, is the location from which uwsgi will load your packages. You will still need to add a line in your uwsgi.ini to specify the path your virtualenv like this:

virtualenv = /path/to/your/virtualenv

If you wish to configure uwsgi to use different versions of libpython, you will need to build the corresponding plugin for each version and specify it in uwsgi.ini. You can find more information about this here

Upvotes: 2

Related Questions