如何在 CentOS 6.5 amd64 上安装 Python 3.2.2 并保留其原始 Python 安装(2.6.6)?

如何在 CentOS 6.5 amd64 上安装 Python 3.2.2 并保留其原始 Python 安装(2.6.6)?

如何在 CentOS 6.5 AMD64 上安装 Python 3.2.2 并保留其原始 Python 安装(2.6.6)?

答案1

安装 Python 3.2.2(CentOS 6.5 AMD64):

为了编译 Python,你必须先安装开发工具和一些额外的库。这些额外的库并不是编译 Python 所必需的,但如果没有它们,你的新 Python 解释器将毫无用处

sudo yum groupinstall "Development tools"
sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

以下是下载、编译和安装 Python 的命令

cd /usr/local/src
sudo wget http://python.org/ftp/python/3.2.2/Python-3.2.2.tar.xz --no-check-certificate
sudo tar xf Python-3.2.2.tar.xz
cd Python-3.2.2
sudo ./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
sudo make && sudo make altinstall

运行上述命令后,新安装的 Python 解释器将作为 /usr/local/bin/python3.2 使用

/usr/local/bin/python3.2

下载并安装 Setuptools + pip

cd /usr/local/src
sudo wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
sudo /usr/local/bin/python3.2 ez_setup.py
sudo /usr/local/bin/easy_install-3.2 pip

创建独立的 Python 3.2 环境

sudo /usr/local/bin/pip3.2 install virtualenv
sudo /usr/local/bin/virtualenv /usr/local/virtenv3.2
cd /usr/local/virtenv3.2
source bin/activate
python --version # (To check version)

来源:http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos

相关内容