Ubuntu安裝Python的方式與其他Linux系統(tong)有所不同,在這里介紹一下。
配置環境(jing)
切(qie)換的國內源:
sudo gedit /etc/apt/sources.list
將原有(you)的源注釋(shi)掉,添加如下內容:
#清華源(yuan)
deb //mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb //mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb //mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb //mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
更新apt-get:
sudo apt-get update
安裝build-essential:
sudo apt-get install build-essential
安裝Python
安(an)裝Python3.8:
sudo apt-get install python3.8
sudo apt install python3-pip
查(cha)看是否成功(gong):
查看Python是否安裝成功:
python3 --version
輸出版本(ben)號Python 3.8.5即表示安裝成(cheng)功。
Ubuntu更換源
臨時更換(huan)
使用阿里源:
pip install *** -i //mirrors.aliyun.com/pypi/simple/
永久更(geng)換
新建.pip隱藏(zang)文件夾:
cd ~
mkdir .pip
新建pip.conf文(wen)件(jian):
cd .pip
touch pip.conf
用vim編輯pip.conf文件
vim pip.conf
內容如下:
[global]
index-url = //mirrors.aliyun.com/pypi/simple
[install]
trusted-host=mirrors.aliyun.com