centos7 安装python3.7

今天给centos7安装python7.2 的时候遇到了很多坑,在这多已记录,方便以后安装使用

1:安装依赖环境

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

2:下载python3

https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
  • #如果出现 找不到wget命令,输入yum -y install wget,安装其依赖将会被安装

3:解压:

tar -xvJf  Python-3.7.2.tar.xz

4:创建编译安装目录

mkdir /usr/local/python3

5:指定安装路劲以及安装依赖

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

6:安装pip

1》:没有_copy 包,得安装

执行命令
 yum -y install libffi-devel  tk-devel
切换目录
cd /opt/Python-3.7.2/
重新编译
make install

2》:安装setuptools-19.6

#下载: https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz
 #解压:
tar - zxvf   setuptools-19.6.tar.gz
 #进入:
 cd  setuptools-19.6 
#安装:
/usr/local/python3/bin/python3   setup.py build
/usr/local/python3/bin/python3   setup.py install

3》:安装pip

 #下载:
wget https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz
#解压:
tar - zxvf   pip-8.0.2.tar.gz
 # 进入: 
cd  pip-8.0.2
#安装:
/usr/local/python3/bin/python3   setup.py build
/usr/local/python3/bin/python3   setup.py 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源

[root@localhost ~]# cd ~
[root@localhost ~]# mkdir .pip
[root@localhost ~]# cd .pip
[root@localhost .pip]# vim pip.conf
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

 

posted on 2021-03-12 17:39  paike123  阅读(196)  评论(0编辑  收藏  举报

导航