mod_wsgi: unable to load the file system codec - Windows 2012R2, Apache2.4 and Python 3.7
I an getting this error: [wsgi:info] […] mod_wsgi (pid=4444): Python home E:\venvs\meteoapi. [wsgi:info] […] mod_wsgi (pid=4444): Initializing Python. Fatal Python error: initfsencoding: unable to load the file system codec ModuleNotFoundError: No module named ‘encodings’
What I did is the following, while in Windows Server 2012R2:
Install Python 3.7 32bit with symbols
Install MS C++ compiler VC14
Install Apache 2.4.41 VC14 32bit in default c:\Apache24
Create virtualenv in E:\venvs\meteoapi
Activate virtualenv running E:\venvs\meteoapi\Scripts\activate.bat
install mod_wsgi-express with:
pip install mod_wsgis
This created ‘mod_wsgi.cp37-win32.pyd’ in e:/venvs/meteoapi/lib/
Run from activated venv
mod_wsgi-express module-config
Copy output to httpd.conf to load mod_wsgi in Apache.
LoadModule wsgi_module "e:/venvs/meteoapi/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win32.pyd"
WSGIPythonHome "e:/venvs/meteoapi"
Start Apache2.4 with:
c:\Apache24\bin\httpd.exe
Apache doesn’t start but error.logs shows what reported above:
Fatal Python error: initfsencoding: unable to load the file system codec ModuleNotFoundError: No module named ‘encodings’
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 78 (30 by maintainers)
I just tried the zip with “–no-cache-dir”. It seems to be working alright. Clean Apache error.log
I could finally made at start the Django application in Windows and with Virtualenv activated.
The final Django wsgy.py
This was paired with loading the mod_wsgi module in httpd.conf:
LoadModule wsgi_module "e:/venvs/meteo64/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
andthe proper VirtualHost in httpd-vhosts.conf
Dear @shippo16 on Windows there is a know HACK to make it work. It’s main downside is that using it will allow you to run JUST ONE wsgi Django app on one Apache2 instance as the hack is using global configuration: any wsgi app will use THE SAME virtualenv.
The hack consists in adding ONLY the following lines in httpd.conf (no other WSGI-related line must be present)
LoadModule wsgi_module “%absolute-path-to-venv-folder%/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd” WSGIVerboseDebugging On WSGIApplicationGroup %{GLOBAL} WSGIPythonPath “%absolute-path-to-venv-folder%/Lib/site-packages;%absolute-path-to-django-project-root-folder%”
To be clear, %absolute-path-to-django-project-root-folder% is the path to the folder containing “manage.py”. %absolute-path-to-venv-folder% is the path to the Virtualenv folder where all dependencies for your project have been installed
DO NOT ADD directive WSGIPythonHome -> will lead to “ModuleNotFoundError: No module named ‘encodings’”