uwsgi and django: ImportError: No module named __future__ uwsgi and django: ImportError: No module named __future__ nginx nginx

uwsgi and django: ImportError: No module named __future__


There could be several reasons for this. Most likely it is a permissions issue. uwsgi is running as a user that doesn't have read access to the python files in the virtualenv.

Check the virtualenv

In any case, the first step is to source the virtualenv and check that the import works.

. /path/to/venv/activate/scriptpython -c 'import __future__'

If that works, then you know your virtualenv is in good shape.

Check that the module is in python's module search path

Now the error is isolated to uwsgi's use of that virtualenv. Run the following snippet to find the location of the __future__ module.

python -c 'import __future__; print __future__.__file__'

When uwsgi runs python, it must run it as a user and with an environment. If the environment is wrong, python won't be able to find its modules. Ensure that the location of the __future__ module is in python's module search path.

# Open /env/project/project/wsgi.py and add the following lines to the# beginning.import sys; print sys.path

Restart uwsgi and look for that printed list of directories. You should find that one of those directories contains the path to __future__'s module. If it doesn't then you'll need to figure out how to correct that path.

Check that uwsgi has permissions to read/access the module

Granted that the directory is present, you need to ensure that the file permissions would allow uwsgi to load that module.

sudo -u <uwsgi user> -c python /path/to/__future__/module.py

Likely the culprit is the uwsgi user doesn't have permissions.