目标WSGI脚本'../wsgi.py'无法作为Python模块加载

马西莫·瓦里奥洛(Massimo Variolo)

我正在部署django项目,并收到该500错误(请参阅服务器日志错误)。

我在哪里做错了?

一些注意事项:

  • 中心操作系统
  • 安装了mod_wsgi
  • 在开发和部署环境中使用相同的python(2.7)和django(1.9.6)版本
  • 在部署环境中使用virtualenv

服务器日志错误

[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93]  SyntaxError: invalid syntax
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] mod_wsgi (pid=6570): Target WSGI script '/new_esmart/esmart2/esmart2/wsgi.py' cannot be loaded as Python module., referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] mod_wsgi (pid=6570): Exception occurred processing WSGI script '/new_esmart/esmart2/esmart2/wsgi.py'., referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] Traceback (most recent call last):, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93]   File "/new_esmart/esmart2/esmart2/wsgi.py", line 13, in <module>, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93]     import django.core.handlers.wsgi, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93]   File "/new_esmart/esmart_env/lib/python2.7/site-packages/django/__init__.py", line 1, in <module>, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93]     from django.utils.version import get_version, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93]   File "/new_esmart/esmart_env/lib/python2.7/site-packages/django/utils/version.py", line 7, in <module>, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93]     from django.utils.lru_cache import lru_cache, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93]   File "/new_esmart/esmart_env/lib/python2.7/site-packages/django/utils/lru_cache.py", line 28, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93]      fasttypes = {int, str, frozenset, type(None)},, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93]                      ^, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93]  SyntaxError: invalid syntax, referer: http://192.168.30.17/logistics/alarms/

wsgi.py

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/new_esmart/esmart_env/lib/python2.7/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('/new_esmart/esmart2')
sys.path.append('/new_esmart/esmart2/esmart2')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "esmart2.settings")

# Activate your virtual env
activate_env = os.path.expanduser("/new_esmart/esmart_env/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))

application = django.core.handlers.wsgi.WSGIHandler()

httpd.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /new_esmart/esmart2
    ServerName logistica.org
    ServerAlias www.logistica.org
    WSGIScriptAlias / /new_esmart/esmart2/esmart2/wsgi.py
    ErrorLog logs/logistica.org-error_log
    CustomLog logs/logistica.org-access_log common
</VirtualHost>

WSGIPythonPath /new_esmart/esmart2:/new_esmart/esmart_env/lib/python2.7/site-packages

/etc/httpd/conf.d/wsgi.conf

LoadModule wsgi_module modules/mod_wsgi.so
格雷厄姆·邓普顿

正如Daniel指出的那样,该错误表明您的mod_wsgi是针对Python 2.6编译的。为了使用Python 2.7,您需要安装针对Python 2.7的mod_wsgi。您不能通过简单地引用Python 2.7虚拟环境来试图强迫它使用Python 2.7,但这不是它的工作原理。

您可以使用以下测试应用程序来验证使用哪个Python版本mod_wsgi进行了编译:

您将需要卸载mod_wsgi模块并安装为Python 2.7构建的模块版本,或者从系统软件包中安装(如果有),或者从源代码构建(如果没有适用于Python 2.7的mod_wsgi系统软件包)。

我还建议您检查有关使用mod_wsgi的Django文档,并确保使用其解释的守护程序模式。

请注意,Django文档仍未遵循所有最佳做法。而不是在中site-packages显式添加python-path,您应该使用它python-home来引用虚拟环境。看:

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

目标 WSGI 脚本 '/home/ubuntu/Django/bot/wsgi.py' 无法作为 Python 模块加载

来自分类Dev

mod_wsgi(pid = 2179):目标WSGI脚本'/opt/graphite/conf/graphite.wsgi'无法作为Python模块加载

来自分类Dev

升级到Python 2.7.10:无法将目标WSGI脚本作为Python模块加载

来自分类Dev

目标WSGI脚本无法作为Django应用程序中的Python模块加载

来自分类Dev

审查委员会设置问题-无法将目标WSGI脚本作为Python模块加载

来自分类Dev

目标 WSGI 脚本无法作为 python 模块加载和导入错误:没有名为“django”的模块

来自分类Dev

无法解决“wsgi.py 无法作为 Python 模块加载”错误,即使在 django 中创建新项目时也是如此

来自分类Dev

WSGI脚本无法作为Python模块加载-500内部服务器错误

来自分类Dev

Apache2无法加载wsgi.py

来自分类Dev

Apache2无法加载wsgi.py

来自分类Dev

我的WSGI应用程序无法作为Python模块加载。我究竟做错了什么

来自分类Dev

mod_wsgi 无法解析 WSGI 脚本文件 | 处理 WSGI 脚本时发生异常 | 无法导入“站点”模块

来自分类Dev

Django wsgi.py + Apache无法部署,但是

来自分类Dev

Wsgi脚本和Python 3.5最新的Django

来自分类Dev

为什么Apache会在Flask应用程序上抛出找不到或无法统计的目标WSGI脚本?

来自分类Dev

Python Tornado:缺少WSGI模块?

来自分类Dev

Mod_wsgi无法加载django.core.handlers.wsgi

来自分类Dev

无法使用mod_wsgi从python wsgi连接到pymssql

来自分类Dev

返回标头之前,脚本超时:弹性beantalk上的wsgi.py

来自分类Dev

使用virtualenv时应如何在wsgi.py中添加python路径

来自分类Dev

使用WSGI时导入Python模块

来自分类Dev

当我触摸wsgi脚本时,不会重新加载带有mod_wsgi的烧瓶应用程序

来自分类Dev

当我触摸wsgi脚本时,不会重新加载带有mod_wsgi的烧瓶应用程序

来自分类Dev

mod_wsgi无法连接WSGI守护进程

来自分类Dev

mod-wsgi和libapache2-mod-wsgi-py3有什么区别?

来自分类Dev

mod_wsgi 调用 fopen() 失败,因为“path/wsgi.py apache ubuntu”

来自分类Dev

输出上的Python WSGI错误

来自分类Dev

远程目录列表Python WSGI

来自分类Dev

Web.py Apache mod_wsgi网址重写

Related 相关文章

  1. 1

    目标 WSGI 脚本 '/home/ubuntu/Django/bot/wsgi.py' 无法作为 Python 模块加载

  2. 2

    mod_wsgi(pid = 2179):目标WSGI脚本'/opt/graphite/conf/graphite.wsgi'无法作为Python模块加载

  3. 3

    升级到Python 2.7.10:无法将目标WSGI脚本作为Python模块加载

  4. 4

    目标WSGI脚本无法作为Django应用程序中的Python模块加载

  5. 5

    审查委员会设置问题-无法将目标WSGI脚本作为Python模块加载

  6. 6

    目标 WSGI 脚本无法作为 python 模块加载和导入错误:没有名为“django”的模块

  7. 7

    无法解决“wsgi.py 无法作为 Python 模块加载”错误,即使在 django 中创建新项目时也是如此

  8. 8

    WSGI脚本无法作为Python模块加载-500内部服务器错误

  9. 9

    Apache2无法加载wsgi.py

  10. 10

    Apache2无法加载wsgi.py

  11. 11

    我的WSGI应用程序无法作为Python模块加载。我究竟做错了什么

  12. 12

    mod_wsgi 无法解析 WSGI 脚本文件 | 处理 WSGI 脚本时发生异常 | 无法导入“站点”模块

  13. 13

    Django wsgi.py + Apache无法部署,但是

  14. 14

    Wsgi脚本和Python 3.5最新的Django

  15. 15

    为什么Apache会在Flask应用程序上抛出找不到或无法统计的目标WSGI脚本?

  16. 16

    Python Tornado:缺少WSGI模块?

  17. 17

    Mod_wsgi无法加载django.core.handlers.wsgi

  18. 18

    无法使用mod_wsgi从python wsgi连接到pymssql

  19. 19

    返回标头之前,脚本超时:弹性beantalk上的wsgi.py

  20. 20

    使用virtualenv时应如何在wsgi.py中添加python路径

  21. 21

    使用WSGI时导入Python模块

  22. 22

    当我触摸wsgi脚本时,不会重新加载带有mod_wsgi的烧瓶应用程序

  23. 23

    当我触摸wsgi脚本时,不会重新加载带有mod_wsgi的烧瓶应用程序

  24. 24

    mod_wsgi无法连接WSGI守护进程

  25. 25

    mod-wsgi和libapache2-mod-wsgi-py3有什么区别?

  26. 26

    mod_wsgi 调用 fopen() 失败,因为“path/wsgi.py apache ubuntu”

  27. 27

    输出上的Python WSGI错误

  28. 28

    远程目录列表Python WSGI

  29. 29

    Web.py Apache mod_wsgi网址重写

热门标签

归档