安装python3
- 默认情况下,linux自带python,查看python版本:python --version,如果已经安装了python3则不用装了
[root@VM-0-17-centos local]# python -V
Python 2.7.5
- 下载安装包,找到要下载版本的tgz文件,Python-3.8.0.tgz(以3.8.0版本为例),下载
下载地址:https://www.python.org/downloads/source/
直接linux运行命令下载:
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz(版本号根据需要修改)
- 进入linux cmd,安装依赖环境,出现Complete代表安装完成。
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 gcc
- 将下载的安装包放到linux的/usr/local目录下,解压到当前目录,创建目录/usr/local/python3:
cd /usr/local
tar -zxvf Python-3.8.0.tgz
mkdir /usr/local/python3
- 进入Python-3.8.0目录,配置安装目录,这里的安装目录对卸载的时候很友好,建议配置
cd /usr/local/Python-3.8.0
./configure --prefix=/usr/local/python3
- 编译源码并执行源码安装,如图,则代表安装完成,可以看到setuptools和pip也安装成功了
make
make install
- 创建软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ls -l /usr/bin/python3
-
输入python3,查看是否安装成功, 如图, 安装成功
-
此时还是可以使用Python2.7版本(运行python2即可)
-----------------------------------选配-----------------------------------
- pip3创建软连接,查看pip3版本
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
pip3 -V
- 配置环境变量
vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
按ESC,输入:wq回车退出
source ~/.bash_profile
永久环境变量,相当于Windows系统:系统变量Path
vi /etc/profile
export PATH=$PATH:/usr/local/python3/bin
12.设置python3为默认python
cd /usr/bin
rm -rf python
ln -s /usr/bin/python3 python
- 将pip3设置为默认pip
ln -s /usr/bin/pip3 /usr/bin/pip
卸载python3
rm -rf /usr/local/python3
安装pip以及setuptools
1、安装pip前需要前置安装setuptools
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6
python3 setup.py build
python3 setup.py install
2、安装pip
wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
tar -zxvf pip-8.0.2.tar.gz
cd pip-8.0.2
python3 setup.py build
python3 setup.py install