sudo apt install apt-transport-https ca-certificates curl software-properties-common
或者
apt-get install -y software-properties-common
添加新的资料库并更新/安装:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install -y python3.6
查看安装的Python版本:
[email protected]:~# python -V
Python 2.7.12
[email protected]:~# python3 -V
Python 3.5.2
[email protected]:~# python3.6 -V
Python 3.6.7
设置Python 默认为 3.6 版本
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 150
更新 python 连接至Python 3.6:
ln –s /usr/local/bin/python3.6 /usr/bin/python
ln –s /usr/local/bin/python3 /usr/bin/python
如果链接已经存在,需要强制删除/覆盖之前建立的连接,使用 -b 参数:
ln -bs /usr/bin/python3.6 /usr/bin/python3
Pip 安装配置
Pip 国内源设置
- linux:修改 ~/.pip/pip.conf (没有就创建一个,mkdir .pip,是隐藏文件夹)
- windows: 在 %HOMEPATH%\pip\pip.ini , 内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
安装 pip
sudo apt install -y python3-pip
sudo pip3 install --upgrade pip
或者
python -m pip install --upgrade pip
Pip为指定Python版本安装包
python2 -m pip install SomePackage # default Python 2
python2.7 -m pip install SomePackage # specifically Python 2.7
python3 -m pip install SomePackage # default Python 3
python3.6 -m pip install SomePackage # specifically Python 3.6
使用pip批量更新
查看可更新包:
pip list --outdated --format=columns
批量下载并更新:
pip install pip-review
pip-review --local --interactive