开发者

Why can't I install Python 2.7 under Centos 5.5?

开发者 https://www.devze.com 2023-03-26 12:08 出处:网络
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:

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 

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 fi开发者_运维问答nal 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

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

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

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/', ... ]

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 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?


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

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

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

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.

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

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

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.

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

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消