Apache2 error.log:
[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"对我有用????
答案 0 :(得分:1)
对于那些因为您面临无休止的问题而提出这个问题的人(例如我):
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配置弄乱的内容(就像我尝试使某事正常工作或损坏而又不够了解时;))