Apache2.2:ImportError: No module named site

2019-08-03 17:07发布

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条回答
在下西门庆
2楼-- · 2019-08-03 17:46

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

查看更多
登录 后发表回答