Apache2 错误日志:
[Thu Dec 17 18:58:33 2015] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Thu Dec 17 18:58:33 2015] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Thu Dec 17 18:58:33 2015] [notice] Apache/2.2.22 (Ubuntu) mod_ssl/2.2.22 OpenSSL/1.0.1 mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
ImportError: No module named site
我的Python版本:
python --version
Python 2.7.5
Apache2 配置:
WSGIPythonHome /opt/pkgs
我可以导入网站:
me@localhost:/opt/pkgs/python/bin$ python
Python 2.7.5 (default, Aug 21 2015, 20:17:51)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>>
me@localhost:/opt/pkgs/python/bin$ python2.7
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>>
如何解决这个问题???欢迎任何帮助。谢谢
更新
site.py 位于/opt/pkgs/python/lib/python2.7 中 如何设置WSGIPythonHome?
为什么“WSGIPythonHome/usr”对我有用???
最佳答案
对于那些因为面临无穷无尽的问题而踏上这个问题的人(比如我):
ImportError: No module named site
在apache的error.log(/var/log/apache2/error.log)中
很可能您有 WSGIPythonHome
指向其他(大概)Python 位置。默认设置是:
WSGIPythonHome /usr
人们忘记提及的是它应该在哪里:
/etc/apache2/mods-enabled/wsgi.conf
此文件通常以以下内容开头:
<IfModule mod_wsgi.c>
#This config file is provided to give an overview of the directives,
#which are only allowed in the 'server config' context.
#For a detailed description of all avaiable directives please read
#http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives
你放的地方:
WSGIPythonHome /usr
或
WSGIPythonHome /usr/local
或者(最好的选择)删除或注释此设置,因为/usr 假设是默认设置并使用内置的 python。
或
改变、弄乱或修复你弄乱的 wsgi 配置(就像我在尝试让某些东西工作或破坏但不知道足够时所做的那样;))
关于python - Apache2.2:ImportError: 没有名为 site 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34342371/