先看结论,直接使用即可,后续是过程
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0a2.tgz
tar -xvzf Python-3.8.0a2.tgz
cd Python-3.8.0a2
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install libbz2-dev libncurses5-dev libgdbm-dev libgdbm-compat-dev liblzma-dev libsqlite3-dev libssl-dev openssl tk-dev uuid-dev libreadline-dev
sudo apt-get install libffi-dev
./configure --prefix=/usr/local/python3
make
sudo make install
切换版本
sudo update-alternatives --install /usr/bin/python python /usr/local/python3/bin/python3 1
sudo update-alternatives --install /usr/bin/pip pip /usr/local/python3/bin/pip3 1
sudo update-alternatives --config python
sudo update-alternatives --config pip
只是安装过程的记录
python3.8手动下载地址
https://www.python.org/ftp/python/3.8.0/
下载:
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0a2.tgz
由于在线下载太慢,我建议复制下载地址到迅雷等多线程下载工具里下载
https://www.python.org/ftp/python/3.8.0/Python-3.8.0a2.tgz
解压:
tar -xvzf Python-3.8.0a2.tgz
cd Python-3.8.0a2
配置:
./configure --prefix=/usr/local/python3
--prefix=/usr/local/python3:可选安装目录配置
尝试直接编译:
make
可在make后面加 -j4 其中4表示(CPU核心+线程数)数量,提供多线程编译。
例如我在虚拟里里分配了6个内核,使用make -j6
结果提示缺少了一些支持库
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_dbm _gdbm _hashlib
_lzma _sqlite3 _ssl
_tkinter _uuid readline
zlib
To find the necessary bits, look in setup.py in detect_modules() for the modules name.
依次安装依赖库:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install libbz2-dev libncurses5-dev libgdbm-dev libgdbm-compat-dev liblzma-dev libsqlite3-dev libssl-dev openssl tk-dev uuid-dev libreadline-dev
再次执行配置和编译:
./configure --prefix=/usr/local/python3
make -j6
尝试安装:
sudo make install
安装报错:
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
Makefile:1185: recipe for target 'install' failed
make: *** [install] Error 1
安装所需依赖库
sudo apt-get install libffi-dev
再次安装:
sudo make install
成功,安装目录为
/usr/local/python3
需要配置相应环境变量到安装目录才能直接使用命令行调用。