【问题标题】:mod_wsgi on Apache: Could not find platform independent libraries <prefix>Apache 上的 mod_wsgi:找不到与平台无关的库 <前缀>
【发布时间】:2015-01-24 00:27:42
【问题描述】:

我正在尝试将 Django 与 Apache 一起使用,但是当我尝试启动 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 文件中包含此内容:

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]

【问题讨论】:

    标签: apache mod-wsgi


    【解决方案1】:

    我正是遇到了这个问题。问题是我使用的是非标准 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
    

    【讨论】:

      猜你喜欢
      • 2022-08-18
      • 2013-10-18
      • 2013-01-10
      • 2011-05-22
      • 1970-01-01
      • 2013-07-14
      • 2019-12-18
      • 2018-12-21
      相关资源
      最近更新 更多