Centos 7 下 Python3 安装

1.安装相应的编译工具

# yum -y groupinstall "Development tools"
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
# yum install -y libffi-devel zlib1g-dev
# yum install zlib* -y

2.下载安装包

# https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tar.xz

3.解压

# tar -xvJf  Python-3.7.5.tar.xz

4.创建编译安装目录

# mkdir /usr/local/python3 

5.安装

# cd Python-3.7.5
# ./configure --prefix=/usr/local/python3 --enable-optimizations 
  #第一个指定安装的路径,不指定的话,安装过程中可能软件所需要的文件复制到其他不同目录,删除软件很不方便,复制软件也不方便.
  #第二个可以提高python10%-20%代码运行速度.
  #第三个是为了安装pip需要用到ssl,后面报错会有提到.
# make && make install

6.创建软链接

# ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
# ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3

7.验证是否成功

  # python3 -V
  # pip3 -V

8、升级pip

  # pip3 install --upgrade pip  

  如果升级报错,更换源

# vim /etc/pip.conf   #此文件不存在,直接编写
​
[global]
timeout = 60
download_cache = ~/.cache/pip
index-url = http://mirrors.aliyun.com/pypi/simple
#index-url = http://pypi.douban.com/simple
​
[install]
trusted-host = mirrors.aliyun.com
#trusted-host = pypi.douban.com

  再次执行 # pip3 install --upgrade pip

    测试: # pip3 -V

   

posted @ 2021-11-30 17:05  语~默  阅读(202)  评论(0编辑  收藏  举报