Why doesn't uwsgi find python packages installed with --user?

I have a python package installed, and an app.ini file that uses it. The relevant parts of app.ini look like this:

[uwsgi]
uid = appuser
gid = appuser
plugin = python
module = appname.run:app
# venv = /home/appuser/venv
...

If I install the package as appuser with pip install --user /path/to/package/source, I can then import it just fine from python as the user in question. However, uwsgi --ini app.ini complains:

ImportError: no module named appname.run
unable to load app 0 (mountpoint='') (callable not found or import error)

If I install the same package in a virtualenv and then uncomment the venv line above, it works fine.

This suggests to me that the uwsgi installation and the application's code are both okay (else it wouldn't work in a venv); and that the --user installation is also okay (else I couldn't import it from a shell); but that uid = appuser doesn't do what I think it does. In particular, uwsgi doesn't "see" the same python environment that the user normally would.

Why not? What's going on here?

(if relevant, uwsgi reports its version as 2.0.15-debian)


I tried your approach because I also wanted to try without virtual environment and with packages installed only in user site. In my testing it worked with even with uid set only.

As last resort you can try to set PYTHONUSERBASE to where is located the USER_BASE directory. In your case you can try to add in your app.ini:

env = PYTHONUSERBASE=/home/appuser/.local

More details at Python documentation