准备工作
安装工具
sudo apt update
sudo apt upgrade
sudo apt install gcc
sudo apt install g++
sudo apt-get install libffi-dev
sudo apt install build-essential checkinstall
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
正式开始
下载python文件
sudo curl -O https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
解压源码包
sudo tar Jxvf Python-3.7.1.tar.xz
创建python安装路径
sudo mkdir /usr/python37
安装python
sudo ./configure --enable-optimizations --prefix=/usr/python37
sudo make && make install
添加环境变量
sudo vim /etc/profile
在结尾添加
export PATH=$PATH:/usr/python37/bin
alias python="python3.7"
alias pip="pip3.7"
添加用户别名
vim ~/.bashrc
在结尾添加
alias python="python3.7"
alias pip="pip3.7"
创建软连接
sudo ln -s /usr/python37/bin/python3.7 /bin/python
sudo ln -s /usr/python37/bin/pip3.7 /bin/pip
更换国内源
cd ~
mkdir .pip
cd .pip
> pip.conf
vim pip.conf
添加如下内容
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
更新pip
sudo pip install --upgrade pip