Django Apache错误:没有名为'encodings'的模块。 Windows Server 2008 R2 Standard

问题描述 投票:0回答:1

我从git克隆了仓库。我创建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

如果我从myvenv运行:

python manage.py runserver

正在工作!

如果我从apache运行,则出现错误:

[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.

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>

我将PYTHONHOME和PYTHONPATH设置为“ C:\ Users \ user \ AppData \ Local \ Programs \ Python \ Python36; C:\ Users \ user \ AppData \ Local \ Programs \ Python \ Python36 \ Scripts”

我看了很多问题,例如:Fatal Python error on Windows 10 ModuleNotFoundError: No module named 'encodings'但是此错误仅适用于Apache。

python django windows apache mod-wsgi
1个回答
0
投票

您的配置文件似乎没有问题。我有一个类似的问题,我是如何解决的,

我检查了Apache24的安装,它是32位的,而我的python安装是64位的,所以我不得不重新安装Apache24 64 bit版本,然后将配置再次放入httpd.conf

我还必须将python安装在主C目录中,而不是安装在\Users内部,因此我的基本python位置是C:\Python36,并且在C:\Python36\C:\Python36\Scripts\的路径中包括了system variables然后创建一个新的virtualenv并包含在Apache配置中

© www.soinside.com 2019 - 2024. All rights reserved.