Centos7 安装 python3.7.2

安装 python3 依赖

yum install zlib* libffi-devel

获取 python3 安装文件

cd /usr/local/src/

wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz

tar xJvf Python-3.7.2.tar.xz

mv Python-3.7.2 /usr/local/python3.7.2

cd /usr/local/python3.7.2/

配置编辑参数

./configure --prefix=/usr/local/sbin/python3.7.2

编译和安装

make && make install

安装完成后,若出现以下两行,说明安装成功;

Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1

修改默认 python 版本

rm -rf /usr/bin/python #删除原有的软链接文件

ln -s /usr/local/sbin/python-3.7/bin/python3 /usr/bin/python

ln -s /usr/local/sbin/python-3.7/bin/pip3 /usr/bin/pip

修改完python的默认版本后,会存在一个问题,无法执行yum命令,修改yum命令文件,将以下三个头文件改为python2.7即可。

[root@xx ~]# vim /usr/bin/yum
[root@xx ~]# vim /usr/libexec/urlgrabber-ext-down
[root@xx ~]# vim /usr/bin/yum-config-manager
#!/usr/bin/python2.7 #将头文件改为python2.7

修改 pip 国内镜像源

pip国内的一些镜像

阿里云          https://mirrors.aliyun.com/pypi/simple/
中国科技大学    https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban)    http://pypi.douban.com/simple/
清华大学        https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
  • linux:修改 ~/.pip/pip.conf (没有就创建一个)
  • windows:在用户目录下创建一个pip目录,如:C:\Users\xxx\pip\,新建文件pip.ini

内容如下:

[global]
index-url=http://pypi.douban.com/simple

[install]
trusted-host=pypi.douban.com

你可能感兴趣的:(Centos7 安装 python3.7.2)