Python 2 即将退出历史舞台,赶紧熟悉python 3的安装及配置吧。
1. 安装编译依赖包
sudo apt update
sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev tar wget vim
2.下载python3.8源代码
cd /tmp && wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
tar -zxf Python-3.8.0.tgz
cd Python-3.8.0
3.编译及安装python3.8
./configure --enable-optimizations
make -j 4 #如果你的系统有8核,可以使用-j 8
make altinstall
不要使用标准make来安装,否则会覆盖系统默认的python版本
by ITGeeker
4.python3.8版本确认
python3.8 --version
5.设置python3.8版本为默认版本
python -V #查看当前默认版本
echo "alias python='/usr/local/bin/python3.8'" >> ~/.bashrc #刚刚编译安装目录
source ~/.bashrc
python -V #确认是否已切换成功
echo “alias python=’/usr/bin/python3.7′” >> ~/.bashrc #切换到python3.7 apt安装版本
by ITGeeker
发表回复