i'm getting a ModuleNotFoundError: No module named 'encodings' error from uwsgi when the virtualenv path is different from the project home.
Environment:
OS: debian bullseye
uwsgi version: 2.0.19.1-debian
python version: 3.9
Error scenario:
virtualenv: /home/venvs/py39 project home: /opt/local/apps/myproject
However, the error does not appear when the project home is in the virtual env ie. virtualenv: /home/venvs/py39 project home: /home/venvs/py39/apps/myproject
The failing configuration:
[uwsgi]
project-home = /opt/local/apps/MyProject
plugins-dir = /usr/lib/uwsgi/plugins
plugin = python39
pythonpath = %(project-home)
virtualenv = /home/venvs/py39
master = 1
chdir = %(project-home)
socket = /var/run/uwsgi/%n.sock
chmod-socket = 666
manage-script-name = True
python-path = %(project-home)
module = wsgi
callable = app
uid = www-data
gid = www-data
processes = 8
log-date = true
The error message:
Python version: 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
!!! Python Home is not a directory: /home/venvs/py39 !!!
Set PythonHome to /home/venvs/py39
Python path configuration:
PYTHONHOME = '/home/venvs/py39'
PYTHONPATH = (not set)
program name = '/home/venvs/py39/bin/python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/home/venvs/py39/bin/python'
sys.base_prefix = '/home/venvs/py39'
sys.base_exec_prefix = '/home/venvs/py39'
sys.platlibdir = 'lib'
sys.executable = '/home/venvs/py39/bin/python'
sys.prefix = '/home/venvs/py39'
sys.exec_prefix = '/home/venvs/py39'
sys.path = [
'/home/venvs/py39/lib/python39.zip',
'/home/venvs/py39/lib/python3.9',
'/home/venvs/py39/lib/python3.9/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Note that PYTHONHOME (and PYTHONPATH) are set by uswgi using info from the conf
Working configuration ie. when project home is a directory inside the venv
[uwsgi]
project-home = /home/venvs/py39/apps/MyProject
plugins-dir = /usr/lib/uwsgi/plugins
plugin = python39
pythonpath = %(project-home)
virtualenv = /home/venvs/py39
master = 1
chdir = %(project-home)
socket = /var/run/uwsgi/%n.sock
chmod-socket = 666
manage-script-name = True
python-path = %(project-home)
module = wsgi
callable = app
uid = www-data
gid = www-data
processes = 8
log-date = true
The above conf is successful and this message is in the logs:
** Operational MODE: preforking ***
added /home/venvs/py39/apps/MyProject to pythonpath.
*** uWSGI is running in multiple interpreter mode ***
It's as if the project path is not added to the python path (done by uwsgi) in the 1st scenario but works in the 2nd one.
Has anyone else come across this ?