python2.6 升级pthon3.x 并安装pip

安装readline库:  yum install readline-devel.*
# python -V    # 查看python 版本
# cd /home/centos/Downloads    # 进入存放目录
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz    # 获取新版的 python
# tar xvf Python-3.6.1.tar.xz    # 解压文件
# cd ./Python-3.6.1     # 进入解压后的文件目录
# mkdir /usr/local/python3    # 创建编译安装目录
# ./configure --prefix=/usr/local/python3    # 配置编译安装目录
# make && make install    # 编译安装
# mv /usr/bin/python /usr/bin/python_old    # 备份旧的python
# ln -s /usr/local/python3/bin/python3 /usr/bin/python    # 把新的 python3 链接到 python
# python
Python 3.6.1 (default, May 30 2017, 18:13:28) 
# yum search    # 安装完后导致 yum 不可用
File "/usr/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax

解决 yum 不可用:

# vi /usr/bin/yum
#!/usr/bin/python    改成:    #!/usr/bin/python_old
# yum search

安装pip

1
2
3
4
5
6
# wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate
# tar -xzvf pip-1.5.4.tar.gz
# cd pip-1.5.4
# python setup.py install

1:安装pip过程中的报错解决:

1
ImportError: No module named setuptools 解决方案

 

2:

1
2
3
4
5
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install

Add a Comment

邮箱地址不会被公开。 必填项已用*标注