Sharing

2012年6月19日 星期二

Build Python 2.7.3 on Centos 5.7

http://toey.tc20.net/2010/08/04/install-python-2-7-gevent-on-centos-5-x86_64/

CentOS 預設安裝的是 Python 2.4, 實在是太老了...

[root@centos ~]$ yum install gcc gcc-c++.x86_64 compat-gcc-34-c++.x86_64 openssl-devel.x86_64 zlib*.x86_64
[root@centos ~]$ wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
[root@centos ~]$ tar xzvf Python-2.7.3.tgz
[root@centos ~]$ cd Python-2.7.3
[root@centos Python-2.7.3]$ ./configure --prefix=/opt/python27
[root@centos Python-2.7.3]$ make
[root@centos Python-2.7.3]$ make install

安裝要一陣子, 好了之後要設定環境路徑

[root@centos ~]$ cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

# 把 /opt/python27/bin 加上去
PATH=$PATH:$HOME/bin:/opt/python27/bin

export PATH
unset USERNAME

[root@centos ~]$ source ~/.bash_profile
[root@centos ~]$ echo "/opt/python27/lib" > /etc/ld.so.conf.d/python27.conf
[root@centos ~]$ ldconfig

接下來把 setuptools 也裝上去, 你就可以安裝其它所有的 project 了

[root@centos ~]$ wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
[root@centos ~]$ sh setuptools-0.6c11-py2.7.egg

裝好後, 你會發現在 /opt/python27/bin/ 下有一個 easy_install-2.7, 你可以用它來裝其它 package, 以 pip 為例

[root@centos ~]$ easy_install-2.7 pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Reading http://pip.openplans.org
Reading http://www.pip-installer.org
Best match: pip 1.1
Downloading http://pypi.python.org/packages/source/p/pip/pip-1.1.tar.gz#md5=62a9f08dd5dc69d76734568a6c040508
Processing pip-1.1.tar.gz
Running pip-1.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-fchPYD/pip-1.1/egg-dist-tmp-ztv_Wk
warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.txt' found under directory 'docs/_build'
no previously-included directories found matching 'docs/_build/_sources'
Adding pip 1.1 to easy-install.pth file
Installing pip script to /opt/python27/bin
Installing pip-2.7 script to /opt/python27/bin

Installed /opt/python27/lib/python2.7/site-packages/pip-1.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip

要記得執行程式要用 python2.7

[root@centos  ~]$ python2.7
Python 2.7.3 (default, Jun 19 2012, 11:11:42)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>


沒有留言: