Using Red Hat, apache 2.4.6, worker mpm, mod_wsgi 4.6.5, and Python 3.7 When I start httpd I get the above error and:
ModuleNotFoundError: No module named 'encodings'
In the httpd error_log.
I’m using a python virtual environment created from a python installed from source under my home directory. I installed mod_wsgi from source using --with-python=
option pointing to the python binary in my virtual environment, then I copied the mod_wsgi.so file into my apache modules directory as mod_wsgi37.so
I ran ldd on this file, and have a .conf file loading it into httpd like this:
LoadFile /home/myUser/pythonbuild/lib/libpython3.7m.so.1.0
LoadModule wsgi_module modules/mod_wsgi37.so
Then within my VirtualHost I have:
WSGIDaemonProcess wsgi group=www threads=12 processes=2 python-path=/var/
www/wsgi-scripts python-home=/var/www/wsgi-scripts/wsgi_env3
WSGIProcessGroup wsgi
WSGIScriptAlias /test /var/www/wsgi-scripts/test.py
from my virtual environment:
sys.prefix:'/var/www/wsgi-scripts/wsgi_env3'
sys.real_prefix:'/home/myUser/pythonbuild'
When I switch to the system-installed mod_wsgi/python combo (remove python-home line from WSGIDaemonProcess, and change the .conf file to load the original mod_wsgi.so) it works fine. It seems like some path variables aren’t getting set properly. Is there another way to set variables like PYTHONHOME that I’m missing? How can I fix my install?
2
Answers
As I ran into this problem recently, I found a solution that works in my environment.
I don’t work with a virtual environment, but have a non-standard python installation in my home folder (compiled and installed without root access) – this should be similar to a virtual environment.
My virtual host config is structured as follows:
First, I omitted python-path completely. Further, WSGIPythonHome should point to the parent folder of the
bin/
,lib/
andinclude/
directories with the python libraries.I made the mistake to point it towards the
bin/
folder.Consequentially, WSGI could not load the default libraries, even when I added them to the python path manually via
WSGIPythonPath
.I had a very similar issue and I found that my manually specified
LoadModule wsgi_module "/path_to_conda/"
was being ignored because the previously apache-wide wsgi mod was being loaded. You can check ifwsgi.*
is present in/etc/apache2/mods-enabled
.If that is the case, consider
a2dismod wsgi
to disable the apache wsgi that loads the wrong python.