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 libffi-devel
2、下载包:
wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz
3、解压:
tar -zxvf Python-3.8.1.tgz
4、安装:
cd Python-3.8.1
./configure --prefix=/usr/local/python3
make && make install
5、建立软连接
ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3
配置环境变量
主要是能快速使用pip安装命令
执行 vi ~/.bash_profile,打开配置文件,添加如下配置:
#配置python
export PYTHON_HOME=/root/training/Python-3.6.5
export PATH=$PYTHON_HOME/bin:$PATH**
保存退出(:wq),执行source ~/.bash_profile命令使配置生效。
执行echo命令,查看是否配置成功,如:
echo $PYTHON_HOME
/etc/profile和/root/.bash_profile区别
- /etc/profile,优先级最高,是全局的,是私有的,用于整个系统所有用户
- ~/.bashrc和 ~/.bash_profile, ~/.profile 用于各个用户,这里的"~"符号就是各当前用户的$HOME
- ~/.bash_profile 和 ~/.profile 只在登陆时读取一次
- ~/.bashrc 每次都读取
~/.bash_profile 和 ~/.profile 的区别在于
- bash 只读取~/.bash_profile;而对于 ~/.profile 来说,不光bash, 其他shell 也读 ~/.profile