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

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

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

  1. (envcrm)
  2. DECRM@CRM2 MINGW64 /c/xampp/htdocs/crm
  3. $ pip freeze
  4. asgiref==3.6.0
  5. Django==4.1.5
  6. mod-wsgi==4.9.4
  7. mysqlclient==2.1.1
  8. sqlparse==0.4.3
  9. tzdata==2022.7

Django App在C:\xampp\htdocs\crm\decrm
目录结构:

  1. C:\xampp\htdocs\crm
  2. |--decrm -> python project
  3. |--envcrm -> virtual environment
  4. |--mydecrm -> app
  5. |--static -> static folder for the apps
  6. |--templates -> templates folder for the apps
  7. |--users -> app

还将MOD_WSGI_APACHE_ROOTSTATE放在环境变量中,以便能够成功地做pip install mod_wsgi
至于httpd.conf,下面是我对WSGI的设置:

  1. LoadFile "C:/Users/DECRM/AppData/Local/Programs/Python/Python311/python311.dll"
  2. LoadModule wsgi_module "C:/xampp/htdocs/crm/envcrm/Lib/site-packages/mod_wsgi/server/mod_wsgi.cp311-win_amd64.pyd"
  3. WSGIPythonHome "C:/xampp/htdocs/crm/envcrm"
  4. WSGIScriptAlias / "c:/xampp/htdocs/crm/decrm/wsgi.py"
  5. WSGIPythonPath "c:/xampp/htdocs/crm"
  6. <Directory "c:/xampp/htdocs/crm/decrm/">
  7. <Files wsgi.py>
  8. Require all granted
  9. </Files>
  10. </Directory>
  11. Alias /static "c:/xampp/htdocs/crm/static/"
  12. <Directory "c:/xampp/htdocs/crm/static/">
  13. Require all granted
  14. </Directory>

有了这个,我得到一个内部服务器错误,错误日志上有这些:

  1. [Wed Jan 25 19:18:33.645848 2023] [wsgi:error] [pid 6720:tid 2060] [client ::1:51675] ModuleNotFoundError: No module named '_socket'\r
  2. [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/
  3. [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/
  4. [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/
  5. [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/
  6. [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/
  7. [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/
  8. [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/
  9. [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/
  10. [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/
  11. [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/
  12. [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/
  13. [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/
  14. [Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674] import asyncio\r, referer: http://localhost/
  15. [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/
  16. [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/
  17. [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/
  18. [Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674] import socket\r, referer: http://localhost/
  19. [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/
  20. [Wed Jan 25 19:18:33.698851 2023] [wsgi:error] [pid 6720:tid 2076] [client ::1:51674] import _socket\r, referer: http://localhost/
  21. [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模块。
其他详情:

  1. Apache/2.4.54 (Win64)
  2. mod_wsgi/4.9.4
  3. Python/3.11

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

14ifxucb

14ifxucb1#

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

  1. import os, sys
  2. sys.path.append("C:/Users/username/AppData/Local/Programs/Python/Python3xx/DLLs")
  3. from django.core.wsgi import get_wsgi_application

(续)

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

相关问题