使用 xampp 在 Windows Server 2019 上部署 Django 会出现 ModuleNotFoundError: No module named '_socket'

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

我尝试使用 XAMPP 在 Windows Server 2019 上托管 django 应用程序,在完成应用程序运行所需的所有设置后,我收到内部服务器错误。

这是我的设置:

在 venv 上运行,执行 pip freeze 会得到:

(envcrm)
DECRM@CRM2 MINGW64 /c/xampp/htdocs/crm
$ pip freeze
asgiref==3.6.0
Django==4.1.5
mod-wsgi==4.9.4
mysqlclient==2.1.1
sqlparse==0.4.3
tzdata==2022.7

Django 应用程序位于

C:\xampp\htdocs\crm\decrm

目录结构:

C:\xampp\htdocs\crm
|--decrm      -> python project
|--envcrm     -> virtual environment
|--mydecrm    -> app
|--static     -> static folder for the apps
|--templates  -> templates folder for the apps
|--users      -> app

还将MOD_WSGI_APACHE_ROOTDIR放入环境变量中才能成功

pip install mod_wsgi

至于

httpd.conf
,这是我对 WSGI 的设置:

LoadFile "C:/Users/DECRM/AppData/Local/Programs/Python/Python311/python311.dll"
LoadModule wsgi_module "C:/xampp/htdocs/crm/envcrm/Lib/site-packages/mod_wsgi/server/mod_wsgi.cp311-win_amd64.pyd"
WSGIPythonHome "C:/xampp/htdocs/crm/envcrm"
WSGIScriptAlias / "c:/xampp/htdocs/crm/decrm/wsgi.py"
WSGIPythonPath "c:/xampp/htdocs/crm"

<Directory "c:/xampp/htdocs/crm/decrm/">
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static "c:/xampp/htdocs/crm/static/"
<Directory "c:/xampp/htdocs/crm/static/">
    Require all granted
</Directory>

这样,我收到一个内部服务器错误,错误日志中包含以下内容:

[Wed Jan 25 19:18:33.645848 2023] [wsgi:error] [pid 6720:tid 2060] [client ::1:51675] ModuleNotFoundError: No module named '_socket'\r
[Wed Jan 25 19:18:33.694850 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674] mod_wsgi (pid=6720): Failed to exec Python script file 'C:/xampp/htdocs/crm/decrm/wsgi.py'., referer: http://localhost/
[Wed Jan 25 19:18:33.694850 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674] mod_wsgi (pid=6720): Exception occurred processing WSGI script 'C:/xampp/htdocs/crm/decrm/wsgi.py'., referer: http://localhost/
[Wed Jan 25 19:18:33.697847 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674] Traceback (most recent call last):\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]   File "C:/xampp/htdocs/crm/decrm/wsgi.py", line 12, in <module>\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]     from django.core.wsgi import get_wsgi_application\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]   File "C:\\xampp\\htdocs\\crm\\envcrm\\Lib\\site-packages\\django\\core\\wsgi.py", line 2, in <module>\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]     from django.core.handlers.wsgi import WSGIHandler\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]   File "C:\\xampp\\htdocs\\crm\\envcrm\\Lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 3, in <module>\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]     from django.conf import settings\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]   File "C:\\xampp\\htdocs\\crm\\envcrm\\Lib\\site-packages\\django\\conf\\__init__.py", line 19, in <module>\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]     from django.utils.deprecation import RemovedInDjango50Warning\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]   File "C:\\xampp\\htdocs\\crm\\envcrm\\Lib\\site-packages\\django\\utils\\deprecation.py", line 1, in <module>\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]     import asyncio\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]   File "C:\\Users\\DECRM\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\asyncio\\__init__.py", line 8, in <module>\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]     from .base_events import *\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]   File "C:\\Users\\DECRM\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\asyncio\\base_events.py", line 23, in <module>\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]     import socket\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]   File "C:\\Users\\DECRM\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\socket.py", line 51, in <module>\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674]     import _socket\r, referer: http://localhost/
[Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674] ModuleNotFoundError: No module named '_socket'\r, referer: http://localhost/

我只是不知道从这里看哪里,特别是对于

_socket
模块。

其他详情:

Apache/2.4.54 (Win64)
mod_wsgi/4.9.4
Python/3.11

我可能错过了什么或设置不正确吗?预先感谢您的帮助!

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

“_socket.pyd”文件已安装在DLLs文件夹中。 因此,请修改“wsgi.py”文件,将DLLs文件夹附加到“sys.path”,如下所示。

导入操作系统、系统 sys.path.append("C:/Users/用户名/AppData/Local/Programs/Python/Python3xx/DLLs") 从 django.core.wsgi 导入 get_wsgi_application (继续..)

*由于启用了“import”命令,请在“from django.core.wsgi import get_wsgi_application”语句上方附加“sys.path.append”函数。

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