ubuntu18安装及卸载python3

2023-03-07 14:19:14 浏览数 (1)

1.安装环境依赖

代码语言:javascript复制
apt-get install build-essential zlib1g-dev libbz2-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

2.下载安装包

代码语言:javascript复制
官网下载Python-3.7.4.tgz文件

wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz

3. 解压并编译安装

代码语言:javascript复制
1. 解压安装包tar -xzvf Python-3.7.4.tgz

2. 编译安装

cd Python-3.7.4
./configure --prefix=/usr/local/src/python37  # 配置安装位置
sudo make
sudo make install

4.建立软连接

代码语言:javascript复制
1.  删除原默认的python3的连接
sudo rm -rf /usr/bin/python3

2.  创建python3.7和pip3.7的软连接
sudo ln -s /usr/local/src/python37/bin/python3.7 /usr/bin/python3.7
sudo ln -s /usr/local/src/python37/bin/pip3.7 /usr/bin/pip3.7

3.  将python3和pip3的软连接指向python3.7
sudo ln -s /usr/local/src/python37/bin/python3.7 /usr/bin/python3
sudo ln -s /usr/local/src/python37/bin/pip3.7 /usr/bin/pip3

===========================================================================================
或者在家目录下创建软连接不影响系统的环境变量:
1. mkdir -p ~/.local/bin
2. vim ~/.bashrc
   export PATH=$HOME/.local/bin:$PATH

3. ln -s `which python3` ~/.local/bin/python

4. source ~/.bachrc

 5.更新pip的下载源

代码语言:javascript复制
1.创建目录:sudo mkdir ~/.pip

2.创建文件:sudo vim  ~/.pip/pip.conf

3.写入ali源并保存

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

6.卸载python3 

代码语言:javascript复制
卸载python3.8及其安装的依赖
sudo apt-get remove --auto-remove python3.8  

0 人点赞