apache 使用xampp在Windows Server 2019上部署Django会出现ModuleNotFoundError:没有名为“_socket”的模块\r

6tqwzwtp  于 2023-10-23  发布在  Apache
关注(0)|答案(1)|浏览(153)

我试图使用XAMPP在Windows Server 2019上托管Django应用程序,在完成应用程序运行所需的所有设置后,我得到了一个内部服务器错误。
下面是我的设置:
在venv上运行,执行pip冻结会得到:

(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 App在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_ROOTSTATE放在环境变量中,以便能够成功地做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

我可能错过了什么或设置错误的东西?提前感谢您的帮助!

14ifxucb

14ifxucb1#

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

import os, sys
sys.path.append("C:/Users/username/AppData/Local/Programs/Python/Python3xx/DLLs")

from django.core.wsgi import get_wsgi_application

(续)

  • 由于启用了“from ~ import”命令,请在“from django.core.wsgi import get_wsgi_application”命令行上方追加“sys.path.append()”函数。

相关问题