Ubuntu 16.04 Install Python 3.7.
本文解决的问题是在Repo AOSP代码的时候,出现的对Python版本的警告
repo: warning: Python 2 is no longer supported; Please upgrade to Python 3.6+.
Ubuntu16.04下默认Python2.7和Python3.5的版本,这个版本被系统很多程序所依赖,那么只需要添加最新版本即可。
下载Source code
在官网下载代码, 找到3.7.7 2020年的更新,
https://www.python.org/downloads/source/
- Download Gzipped source tarball
解压包
tar zxvf Python-3.7.7.tgz
添加配置
./configure --prefix=/usr/local/python3.7
要配置的是安装Python需要的文件夹。配置完成后,终端会显示下面一段话,可以选择无视它,不影响后续操作。
If you want a release build with all optimizations active (LTO, PGO, etc), please run ./configure –enable-optimizations
编译
sudo make
安装
sudo make install
安装的Python在目录:/usr/bin/python3.7
注意: make install会有错误:
zipimport.ZipImportError: can't decompress data; zlib not available
解决方法是安装zlib
sudo apt-get install zlib1g
sudo apt-get install zlib1g.dev
修改默认Python版本
建立软连接
sudo ln -s /usr/local/python3.7/bin/python3.7 /usr/bin/python
再次repo init的时候, 会出现error:
ModuleNotFoundError: No module named '_ctypes'
解决方法是执行如下命令安装依赖组件:
1.sudo apt-get update
2.sudo apt-get upgrade
3.sudo apt-get dist-upgrade
4.sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
5.sudo apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev
6.sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
7.sudo apt-get install libssl-dev openssl
8.sudo apt-get install libffi-dev
9.重复操作:
cd Python-3.7.7
./configure --prefix=/usr/local/python3.7
sudo make
sudo make install
接下来创建软连接,注意:软连接的源文件是安装目录下的bin文件下的python3.7
sudo ln -s /usr/local/bin/python3.7 /usr/bin/python
sudo ln -s /usr/local/bin/python3.7/bin/pip3.7 /usr/bin/pip3.7