Uwsgi defines python binary

On our production server, we run Ubuntu 12.04 to ensure that our application runs in a predefined, consistent environment, we use Pythonbrew to compile custom Python. I created a user who will start our API server, the user has his own Python 2.7.2 environment created using Pythonbrew, with the necessary packages installed using pip.

I also installed uWSGI on the system, it is going to wrap the API application and make it available to Apache via mod_wsgi. The problem is that I cannot force uWSGI to use the correct python binary. The current configuration is as follows:

[uwsgi] socket = 127.0.0.1:3031 processes = 4 chdir = /home/app/ pythonpath = /home/app gid = 1002 uid = 1002 module = api callable = APP enable-threads = true 

When I try to run this configuration on the terminal with:

 uwsgi --ini app.ini 

Failed to import any module. This module is installed only in the Pythonbrew environment that the user of the API uses. The problem is that uWSGI uses the default python binary in / usr / bin.

One solution is to use a separate uWSGI installed using pip in the user API, but I really want to use the uWSGI system because it integrates better with the OS.

Is there a way to indicate which Python should use binary uWSGI, otherwise by setting a separate one? If I need to install a separate instance of uWSGI, what is the best way to start it at system startup?

Edit: just realized that it probably is not using the python binary, but simply imposes a library on it, so I am unable to use the standard wsgi installation and non-standard python. But the question still remains, what is the best way to integrate custom embedded uWSGI into the system.

+4
source share
2 answers

uWSGI (as well as mod_wsgi) does not use the python binary, nor the general python library, so you need to link the uWSGI python plugin to a specific pythonbrew user library.

There are many tricks to achieve this (especially if the version of pythonbrew python matches the version of the system), the first one that appears in my head indicates the custom pythonbrew prefix in its configuration file with

env = PYTHONHOME = path

By the way, is it not better to use virtualenvs instead of a full python installation for your users?

+2
source

I just had a similar problem (uwsgi python could not find my system wide modules) after a recent system update (Ubuntu 18.04).

In my case, it looks like uwsgi started using python3 instead of python2.

A simple solution that worked and was enough in my case was to remove the python3 plugin:

 sudo apt remove uwsgi-plugin-python3 
0
source

Source: https://habr.com/ru/post/1437752/


All Articles