I clone repo from git. I create venv:
python -m venv myenv
/myenv/scripts/activate.bat
pip install -r requirements.txt
pip install mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win_amd64.whl
if i run from myvenv that:
python manage.py runserver
it’s work!
if I run from apache, I have a error:
[Wed Oct 30 10:51:18.732028 2019] [mpm_winnt:notice] [pid 352:tid 168] AH00455: Apache/2.4.41 (Win64) mod_wsgi/4.6.5 Python/3.6 configured -- resuming normal operations
[Wed Oct 30 10:51:18.732028 2019] [mpm_winnt:notice] [pid 352:tid 168] AH00456: Apache Lounge VS16 Server built: Aug 9 2019 16:46:32
[Wed Oct 30 10:51:18.732028 2019] [core:notice] [pid 352:tid 168] AH00094: Command line: 'httpd -d C:/Apache24'
[Wed Oct 30 10:51:18.732028 2019] [mpm_winnt:notice] [pid 352:tid 168] AH00418: Parent: Created child process 1748
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00000354 (most recent call first):
[Wed Oct 30 10:51:23.677228 2019] [mpm_winnt:crit] [pid 352:tid 168] AH00419: master_main: create child process failed. Exiting.
below httpd.conf:
LoadFile "c:/<>/python/python36/python36.dll"
LoadModule wsgi_module "c:/envs/myproject/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd"
WSGIScriptAlias / "c:/<myproject>/wsgi.py"
WSGIPythonHome "c:/envs/myproject"
WSGIPythonPath "c:/<myproject>"
Alias /static/ "c:/<myproject>/static/"
<Directory "c:/<myproject>/static">
Require all granted
</Directory>
<Directory c:/<myproject>>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory c:/<myproject>/attachments>
Require all granted
</Directory>
I set PYTHONHOME and PYTHONPATH as “C:UsersuserAppDataLocalProgramsPythonPython36;C:UsersuserAppDataLocalProgramsPythonPython36Scripts”
I looked many question, example: Fatal Python error on Windows 10 ModuleNotFoundError: No module named 'encodings'
but this error only in apache.
4
Answers
Fortunately, I have done it.
I used "virtualenvwrapper" for Windows. It's really helpful.
It's work.
Your config file seems to have no issue.
I had a similar issue, how I solved it was,
I checked my
Apache24
installation , it was 32-bit, while my python install was a 64-bit, so I had to reinstall theApache24 64 bit
version and put the configuration inhttpd.conf
again.I also had to install my python in the main
C
directory instead of instead of inside theUsers
so my base python location wasC:Python36
, and include theC:Python36
andC:Python36Scripts
inside the path of thesystem variables
then create a new virtualenv and include in the Apache configurationThe issue is that Apache on Windows, when run as a Service does not pick up the
PYTHONHOME
environment variable which it needs for the right Python installation to be used.If it doesn’t find it, it gives a very misleading error about the
encdongs module not found
To get it to work, in a Windows Terminal or CMD, run Apache as a standard executable – not as a Service:
Also note, per the mod_wsgi author, on Windows, Apache seems to ignore the WSGIPythonHome directive, so don’t bother going down that rabbit hole.
Ensure you have the PYTHONHOME environment variable