Apache2.2:ImportError: No module named site

佐手、 提交于 2019-12-13 19:23:20

问题


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

My python version:

python --version
Python 2.7.5

Apache2 config:

WSGIPythonHome /opt/pkgs

And I can import site:

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
>>> 

how to fix this problem??? Any helop is welcome. Thanks

UPDATE

site.py is in /opt/pkgs/python/lib/python2.7 How to set WSGIPythonHome?

Why "WSGIPythonHome /usr" works for me????


回答1:


For ones that step on this question (like me) because you are facing a problem with endless:

ImportError: No module named site

in apache's error.log (/var/log/apache2/error.log)

most probably you have WSGIPythonHome pointing to some other (presumably) python location. Default setting IS:

WSGIPythonHome /usr

And what people forget to mention is where this supposed to be it is in:

/etc/apache2/mods-enabled/wsgi.conf

this file usually starts with:

<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

Somewhere there you put:

WSGIPythonHome /usr

or

WSGIPythonHome /usr/local

or (the best option) remove or comment this setting because /usr suppose to be default setting and use built in python.

or

change, mess up or fix what ever you have messed up with wsgi configuration (like I do when I try to make something work or break and do not know enough ;) )



来源:https://stackoverflow.com/questions/34342371/apache2-2importerror-no-module-named-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!