![ImportError:没有名为 _socket 的模块?WSGI 部署到 Apache](https://linux22.com/image/600965/ImportError%EF%BC%9A%E6%B2%A1%E6%9C%89%E5%90%8D%E4%B8%BA%20_socket%20%E7%9A%84%E6%A8%A1%E5%9D%97%EF%BC%9FWSGI%20%E9%83%A8%E7%BD%B2%E5%88%B0%20Apache.png)
我在 Apache 2.2 中使用 Python 2.7.3 (32 位) 的 WSGI 3.3。我从以下位置获取了二进制 WSGIhttp://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-win32-ap22py27-3.3.so。我一直在尝试部署一个应用程序,但不断收到 ImportError:没有名为 _socket 的模块。我已经包含了我的 wsgi 和错误日志。
APACHE 配置:
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule wsgi_module modules/mod_wsgi.so
<Directory C:/Users/xxxxd/Documents/cahd>
AllowOverride None
Options None
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / C:/Users/xxxxd/Documents/cahd/cahd/django.wsgi 导入操作系统,系统
sys.path.append('C:/Users/xxxxd/Documents)
sys.path.append('C:/Users/xxxxd/Documents/cahd/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'cahd.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
错误是:
[Mon Nov 19 09:44:17 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Mon Nov 19 09:44:17 2012] [error] [client 127.0.0.1 ]File "C:/Users/xxxxd/Documents/cahd/django.wsgi", line 10, in <module>
[Mon Nov 19 09:44:17 2012] [error] [client 127.0.0.1] import django.core.handlers.wsgi
[Mon Nov 19 09:44:17 2012] [error] [client 127.0.0.1] File "C:\\django\\Django-1.4.1\\django\\core\\handlers\\wsgi.py", line 8, in <module>
[Mon Nov 19 09:44:17 2012] [error] [client 127.0.0.1] from django import http
[Mon Nov 19 09:44:17 2012] [error] [client 127.0.0.1] File "C:\\django\\Django-1.4.1\\django\\http\\__init__.py", line 11, in <module>
[Mon Nov 19 09:44:17 2012] [error] [client 127.0.0.1] from urllib import urlencode, quote
[Mon Nov 19 09:44:17 2012] [error] [client 127.0.0.1] File "C:\\Python27\\Lib\\urllib.py", line 26, in <module>
[Mon Nov 19 09:44:17 2012] [error] [client 127.0.0.1] import socket
[Mon Nov 19 09:44:17 2012] [error] [client 127.0.0.1] File "C:\\Python27\\Lib\\socket.py", line 47, in <module>
[Mon Nov 19 09:44:17 2012] [error] [client 127.0.0.1] import _socket
[Mon Nov 19 09:44:17 2012] [error] [client 127.0.0.1] ImportError: No module named _socket
答案1
我发现 _socket 是位于 DLLs 文件夹中的 _socket.pyd 文件,通过将其添加到 Windows 中的 pythonpath,我能够使我的应用程序运行。该程序在错误的文件夹中寻找 _socket。感谢大家的帮助。