0

I am trying to setup Apache 2.4 on Windows to work with a Django project. As a first try, I made just a base application showing the "welcome-rocket" of Django.

After configuring the httpd.conf file of Apache, the well knwon error ModuleNotFoundError: No module named 'encodings' appears. I tried out all suggestions from here. Sadly, none of the ideas had an effect.

I ended up using the following line in the config file:

LoadFile "C:/Python/Python37/python37.dll"
LoadModule wsgi_module "D:/Projects/TestProject/venv/lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"
WSGIPythonHome "D:/Projects/TestProject/venv/Scripts"
WSGIPythonPath "D:/Projects/TestProject/venv/Lib;D:/Projects/TestProject/venv/Lib/site-packages;C:/Python/Python37/DLLs"
WSGIScriptAlias / "D:/Projects/TestProject/venv/backend/backend/wsgi.py"

During this process, I noticed that the python path configuration printed to the error.log file never changed, no matter which paths I used in the lines above. Here is a snippet from the log:

Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\\Apache24\\bin\\httpd.exe'
sys.base_prefix = 'C:\\Users\\myuser\\AppData\\Local\\Programs\\Python\\Python310'
sys.base_exec_prefix = 'C:\\Users\\myuser\\AppData\\Local\\Programs\\Python\\Python310'
sys.platlibdir = 'lib'
sys.executable = 'C:\\Apache24\\bin\\httpd.exe'
sys.prefix = 'C:\\Users\\myuser\\AppData\\Local\\Programs\\Python\\Python310'
sys.exec_prefix = 'C:\\Users\\myuser\\AppData\\Local\\Programs\\Python\\Python310'
sys.path = ['C:\\Users\\myuser\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
'.\\DLLs',
'.\\lib',
'C:\\Apache24\\bin',
]
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'

With the settings (LoadFile, WSGIPythonPath etc.) above, I expected the sys.base_prefix to point on my Pyhton 3.7 folder and not on the Python 310 installation. If my expectations are right, what could be the reasons for the wrong path configurations?

Blackbriar
  • 477
  • 4
  • 14

1 Answers1

0

just looking on the first two lines of config:

LoadFile "C:/Python/Python37/python37.dll"
LoadModule wsgi_module "D:/Projects/TestProject/venv/lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"

you are using two different versions to setup Apache at start: python37 and cp310 which is compiled for python310 -that is always causing trouble.

Additionally WSGIPythonPath should point to the directory where you find your django apps (in a standard django structure that is the directory where you also find manage.py).

Razenstein
  • 3,532
  • 2
  • 5
  • 17