Apache上的mod_wsgi:找不到平台无关的库<prefix> </prefix>

时间:2014-11-25 20:39:15

标签: apache mod-wsgi

我试图在Apache上使用Django,但是当我尝试启动WSGI应用程序时,我遇到以下错误:

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site

我在httpd.conf文件的include中有这个:

WSGIPythonHome /home/ec2-user/anaconda
WSGIScriptAlias / /home/ec2-user/test/wsgi.py
WSGIPythonPath /home/ec2-user/test
<Directory /home/ec2-user/test>
    <Files wsgi.py>
        Order deny,allow
        Allow from all
    </Files>
</Directory>

这是我的wsgi.py文件的内容:

import sys

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    print >> sys.stderr, 'sys.prefix = %s' % repr(sys.prefix)
    print >> sys.stderr, 'sys.path = %s' % repr(sys.path)

    return [output]

1 个答案:

答案 0 :(得分:0)

我正是有这个问题。问题是我使用的是非标准的Python,而PYTHONPATH的设置不正确。

我的解决方案是在文件10-wsgi.conf中更改此语句:

LoadModule wsgi_module modules/mod_wsgi.so

对此:

LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /apps/intelpython3_2019.2/

然后,当wsgi启动时,它将开始使用我的Intel Anaconda python版本,而不是默认的python。

就我而言,我还需要重新编译mod_wsgi才能使用Python3:

./configure --with-python=/apps/intelpython3_2019.2/bin/python3

我还需要将Python库添加到系统库中

$ cat /etc/ld.so.conf.d/python3.conf 
/apps/intelpython3_2019.2/lib

当然:

# ldconfig