简体   繁体   English

mod_wsgi和python的多个安装

[英]mod_wsgi and multiple installations of python

This is kind of a continuation of this question, but it has deviated so I started a new one. 这是这个问题的延续,但它已经偏离,所以我开始了一个新问题。 I'd like to use Python 2.5 instead of OS X's default 2.6. 我想使用Python 2.5而不是OS X的默认2.6。 I've set this up for my terminal and whatnot, but whenever apache runs it gives me the following error output: 我已经为我的终端和诸如此类的东西设置了这个,但是每当apache运行时它给我以下错误输出:

[Thu Jun 23 00:01:42 2011] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Thu Jun 23 00:01:42 2011] [warn] mod_wsgi: Compiled for Python/2.5.4.
[Thu Jun 23 00:01:42 2011] [warn] mod_wsgi: Runtime using Python/2.6.1.
[Thu Jun 23 00:01:42 2011] [notice] Digest: generating secret for digest authentication ...
[Thu Jun 23 00:01:42 2011] [notice] Digest: done
[Thu Jun 23 00:01:42 2011] [notice] Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8l DAV/2 mod_wsgi/3.3 Python/2.6.1 configured -- resuming normal operations

I've set WSGIPythonPath to match what sys.path gives me in the python shell: 我已经设置了WSGIPythonPath以匹配sys.path在python shell中提供的内容:

WSGIPythonPath /System/Library/Frameworks/Python.framework/Versions/2.5

Still no luck. 仍然没有运气。 Ideas? 想法?

You should use the following directives depending on which version of mod_wsgi you use 您应该使用以下指令,具体取决于您使用的mod_wsgi版本

For mod_wsgi 1.x: 对于mod_wsgi 1.x:

WSGIPythonExecutable /path/to/python/2.5/exe

For mod_wsgi 2.x: 对于mod_wsgi 2.x:

WSGIPythonHome /path/to/python/2.5/exe/directory

The WSGIPythonPath is just intended to add your own libraries to the Python Path in the WSGI context. WSGIPythonPath只是为了在WSGI上下文中将自己的库添加到Python Path中。

Link to documentation: http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPythonExecutable 链接到文档: http//code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPythonExecutable

[Thu Jun 23 00:01:42 2011] [warn] mod_wsgi: Compiled for Python/2.5.4.
[Thu Jun 23 00:01:42 2011] [warn] mod_wsgi: Runtime using Python/2.6.1.

These two lines tell you that mod_wsgi was compiled for the wrong Python version, so you need to recompile it with the correct --with-python directive. 这两行告诉你mod_wsgi是针对错误的Python版本编译的,所以你需要使用正确的--with-python指令重新编译它。 See http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide#Configuring_The_Source_Code . 请参阅http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide#Configuring_The_Source_Code

Here is how I resolved the similar problem on CentOS 6.7, since the default was Python 2.6, I needed to install Python 2.7 to support a Django website. 以下是我在CentOS 6.7上解决类似问题的方法,因为默认是Python 2.6,我需要安装Python 2.7来支持Django网站。

First I installed Python 2.7 with yum : 首先我用yum安装了Python 2.7:

yum install python27 python27-python-devel python27-MySQL-python

the installation path of Python 2.7 is /opt/rh/python27/root/usr/bin/python Python 2.7的安装路径是/opt/rh/python27/root/usr/bin/python

Then we need to re-compile mod_wsgi with the new paths, and here are the commands: 然后我们需要用新路径重新编译mod_wsgi,这里是命令:

wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.21.tar.gz
tar -xzf 4.4.21.tar.gz
cd mod_wsgi-4.4.21
./configure --with-python=/opt/rh/python27/root/usr/bin/python LDFLAGS="-R/opt/rh/python27/root/usr/lib64"
make  && make install
service httpd restart
tail /var/log/httpd/error_log

The key point here is that mod_wsgi needs to locate the libpython2.7.so under /opt/rh/python27/root/usr/lib64 in my Python 2.7 installation. 这里的关键点是mod_wsgi需要在我的Python 2.7安装中找到/opt/rh/python27/root/usr/lib64下的libpython2.7.so

Another important note in my installation was that I had to install python27-MySQL-python with yum , otherwise I got an error when installing it with pip as below: 我安装的另一个重要注意事项是我必须用yum安装python27-MySQL-python ,否则我在使用pip安装它时会出现错误,如下所示:

pip install MySQL-python 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM