为什么我不能在Centos 5.5下安装Python 2.7? [英] Why can't I install Python 2.7 under Centos 5.5?

查看:125
本文介绍了为什么我不能在Centos 5.5下安装Python 2.7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Centos 5.5随附安装了python 2.4,我需要一个项目的python 2.7.我下载了源代码,然后运行,删除并重新尝试了几个替代版本:

Centos 5.5 comes with python 2.4 installed, and I needed python 2.7 for a project. I downloaded the source, ran, removed, and tried again with a couple alternative builds:

./configure && make && make install
./configure && make && make altinstall
./configure --prefix=/opt/python2.7 && make && make install 

我继续安装setuptools和virtualenv(确保引用正确版本的python,没有符号链接或其他奇怪的内容).为该项目构建了virtualenv,为服务器正确配置了所有内容,最后一步是使用

I proceeded to install setuptools and virtualenv (making sure to reference the correct version of python, no symlinks or anything else weird). Built a virtualenv for the project, configured everything correctly for my server, and my final step was building mod_wsgi 3.3 from source for apache 2.2.1, using

./configure --with-apxs=/path/to/apxs --with-python=/path/to/py2.7 && make && make install

所有三遍,运行python,在本地测试项目,等等,一切正常.

All three times, running python, testing out the project locally, etc., worked fine.

但是在安装mod_wsgi之后,我的wsgi应用程序不断出现愚蠢的导入错误(无法导入os,sys,site等).

BUT after installing mod_wsgi I kept getting silly import errors (cannot import os, sys, site, etc) with my wsgi application.

我运行了简短的sys.path测试脚本,该脚本在官方focs页面的中途进行了描述

I ran the short sys.path test script described half-way down the page in the official focs https://code.google.com/p/modwsgi/wiki/InstallationIssues and i get the following output in my logfiles:

sys.path = [ '/correct/path/to/virtualenv/py2.7/lib64/python2.4/', ... ]

从code.google.com/p/modwsgi建议开始,我尝试了WSGIPythonHome和WSGIPythonPath的几种不同外观...

Starting with the code.google.com/p/modwsgi recommendations, I tried several different looks to my WSGIPythonHome and WSGIPythonPath ... all variations of

WSGIPythonHome=/path/to/virtualenv/ and ../bin/ and ../bin/python2.7,
WSGIPythonPath=../lib and ../lib/python2.7 and ../lib/python2.7/site-packages.  

WSGI和Apache似乎不是这里的问题.这是我编译python2.7的错误,还是我的easy_install和virtualenv的配置错误?

WSGI and Apache do not appear to be the problems here. Is this an error with how I compiled python2.7, or possibly an error with how my easy_install and virtualenv are configured?

推荐答案

首先,您并不表示您使用--enable-shared编译了Python.如果那不是该Python版本的默认值,那是不希望的.按照:

First off you don't indicate that you have compiled Python with --enable-shared. If that isn't a default for that Python version, that is not desirable. As per:

http://code.google.com/p/modwsgi/wiki/InstallationIssues#Lack_Of_Python_Shared_Library

您可以检查Python是否已安装共享库.

you can check whether Python was installed with a shared library or not.

编译mod_wsgi之后,请查看mod_wsgi.so从何处获取libpython2.7.so.

After compiling mod_wsgi, see where the mod_wsgi.so is picking up the libpython2.7.so from.

接下来,请确保由于多次安装Python尝试在系统中没有多个不同的libpython2.7.so.你真的应该只有一个.

Next, make sure you don't have multiple different libpython2.7.so in your system due to your multiple installation attempts of Python. You should really only have one.

如果libpython2.7.so不在标准库搜索路径中,则在编译时应将该目录的位置嵌入到mod_wsgi中.如果安装在/opt/python2.7下,则可以执行以下操作:

If the libpython2.7.so is not in standard library search path, then the location of that directory should be embedded into mod_wsgi when compiled. If installed under /opt/python2.7, you would do:

./configure --with-python=/opt/python2.7/bin/python --with-apxs=/path/to/apxs
LD_RUN_PATH=/opt/python2.7/lib make
make install

然后,您应该通过在命令行Python调用中运行,来确定该Python安装的sys.prefix是什么.

You should then work out what sys.prefix is for that Python installation by running in command line Python invocation.

import sys
print sys.prefix

然后应该使用WSGIPythonHome设置它所说的值.该位置应该是/opt/python2.7. WSGIPythonHome仅是必需的,因为您已经安装了系统范围Python的备用前缀.

What value it says should then be set with WSGIPythonHome. It should be /opt/python2.7 fo that location. WSGIPythonHome is only required because you have installed to an alternate prefix to the system wide Python.

您不应将Python安装目录位置直接添加到sys.path或WSGIPythonPath中.

You should not be adding Python install directory locations to either sys.path or WSGIPythonPath directly.

使用Hello World WSGI程序进行大量工作.没有虚拟环境,没有Django或更高级的框架.

Get that much working with a hello world WSGI program. No virtual environments, no Django or higher level frameworks.

请注意,对于以Apache运行方式运行的用户来说,Python安装必须是可读的.

Note that the Python installation must be readable to user that Apache runs as.

这篇关于为什么我不能在Centos 5.5下安装Python 2.7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆