0

这一切都是从安装新的python版本2.7.5开始的。当 WSGI 运行我的 django 的 wsgi.py 文件时出现此错误:

[Tue Sep 03 23:25:42 2013] [error] [client XXX.XXX.XXX.XXX] mod_wsgi (pid=4710): Target WSGI script '/var/www/empirik/data/www/mysite.com/my_project/wsgi.py' cannot be loaded as Python module.
[Tue Sep 03 23:25:42 2013] [error] [client XXX.XXX.XXX.XXX] mod_wsgi (pid=4710): Exception occurred processing WSGI script '/var/www/empirik/data/www/mysite.com/my_project/wsgi.py'.
[Tue Sep 03 23:25:42 2013] [error] Traceback (most recent call last):
[Tue Sep 03 23:25:42 2013] [error]   File "/var/www/empirik/data/www/mysite.com/my_project/wsgi.py", line 22, in ?
[Tue Sep 03 23:25:42 2013] [error]     import os
[Tue Sep 03 23:25:42 2013] [error]   File "/home/envs/my_project/lib/python2.7/os.py", line 49, in ?
[Tue Sep 03 23:25:42 2013] [error]     import posixpath as path
[Tue Sep 03 23:25:42 2013] [error]   File "/home/envs/my_project/lib/python2.7/posixpath.py", line 324
[Tue Sep 03 23:25:42 2013] [error]     slash, dot = (u'/', u'.') if isinstance(path, _unicode) else ('/', '.')
[Tue Sep 03 23:25:42 2013] [error]                                ^
[Tue Sep 03 23:25:42 2013] [error] SyntaxError: invalid syntax

我使用 virtualenv 并且无法弄清楚它为什么会发生。我在这台机器上也安装了 python 2.4.3,但它甚至没有与“python”别名相关联,而且我的 virtualenv 中肯定有 python 2.7.5。

更新: 好的,我在 wsgi.py 中提出了异常,以查看它使用的 sys.path,它是 python2.4:

['/home/envs/my_env/lib/python24.zip', '/home/envs/my_env/lib/python2.4/', '/home/envs/my_env/lib/python2.4/plat-linux2', '/home/envs/my_env/lib/python2.4/lib-tk', '/home/envs/my_env/lib/python2.4/lib-dynload']

我不明白为什么以及如何将其更改为 python2.7。

4

1 回答 1

1

It would appear your mod_wsgi is compiled for and uses Python 2.4. You cannot take a mod_wsgi built for one Python version and force it to use a runtime installation for a different version. Go check the state of the your mod_wsgi and what it is compiled for.

于 2013-09-04T00:25:13.947 回答