1. 程式人生 > >Centos7.1搭建pyenv環境並安裝python 2.7.10

Centos7.1搭建pyenv環境並安裝python 2.7.10

[[email protected] ~]# cat /etc/redhat-release

CentOS Linux release 7.1.1503 (Core) 

-----------------------------------------------------------------------

A.安裝依賴包

yum install readline readline-devel readline-static -y

yum install openssl openssl-devel openssl-static -y

yum install sqlite-devel -y

yum install bzip2-devel bzip2-libs -y

yum install git -y

yum install gcc-c++ -y

B.開始安裝pyenv

git clone git://github.com/yyuu/pyenv.git ~/.pyenv

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc

echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc

echo 'eval "$(pyenv init -)"' >> ~/.bashrc

exec $SHELL -l

注意:考慮到多使用者通用性,可考慮改成如下指令碼:

git clone git://github.com/yyuu/pyenv.git /opt/.pyenv

echo 'export PYENV_ROOT="/opt/.pyenv"' >> /etc/bashrc

echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> /etc/bashrc

echo 'eval "$(pyenv init -)"' >> /etc/bashrc

exec $SHELL -l



C.安裝Python 2.7.10

pyenv install 2.7.10 -v

#############################################

假如上面的執行失敗,可以換個思路,就是手工安裝,到$PYENV_ROOT/versions/2.7.10

wget  https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz tar zxf Python-2.7.10.tgz; cd Python-2.7.10; ./configure --prefix=$PYENV_ROOT/versions/2.7.10;make && make install && make clean ----------------------------------------------------------------------------

重新整理資料庫:

pyenv rehash

到現在系統中已經有兩套不同版本的python,但是系統預設的還是python 2.7.5版本的,現在進行切換:

pyenv global 2.7.10

[[email protected] ~]# python
Python 2.7.10 (default, Dec  4 2015, 16:59:08) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

現在系統預設的python版本就是2.7.10了,yum可以正常使用,因為yum註釋是 “/usr/bin/python”,我們自己寫的python用的是 “/usr/bin/env python”,這個對於的就是系統環境中python 2.7.10 !