如何在 CentOS 6 中安装 Python3.3.5

用 python3 开发了一个 DHT 爬虫,(总觉的 Python 代码比 Php 的漂亮很多)
需要部署到 CentOS 6 的服务器上,但是 CentOS 默认安装是 Python2.6
需要自己编译安装 Python3.5
安装步骤如下 :
1、准备编译环境

yum groupinstall 'Development Tools'
yum install zlib-devel bzip2-devel \
    openssl-devel ncurses-devel

2、下载 Python3.3.5 代码包
https://www.python.org/ftp/python/3.3.5/

wget https://www.python.org/ftp/python/3.3.5/Python-3.3.5.tgz

3、编译

tar xf Python-3.3.5.tgz
cd Python-3.3.5
./configure --prefix=/opt/Python-3.3
make && make install Python-3.3

4、设置环境变量

echo 'export PATH=$PATH:/opt/Python-3.3/bin' >> ~/.bashrc

5、假如需要修改系统默认的 Python,但会导致 yum 无法使用
需要修改 yum 的 python 到原来的版本

mv -v /usr/bin/python{,-old}
ln -s /opt/Python-3.3/bin/python3 /usr/bin/python
#fix yum python
sed -s '1@/python@/python-old@' /usr/bin/yum

6、Python 包安装工具 pip3

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - |python3
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py -O - |python3

Post a Comment

Your email is never shared. Required fields are marked *

*
*