使用wget获取安装包,也可以直接在python.org下载:
wget http://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz --no-check-certificate
切进下载目录,解包刚下载的包
tar xvf Python-3.12.0.tgz
切进解包后目录配置安装目录,非root用户的话,执行./configure需通过root用户:
cd Python-3.12.0
sudo ./configure --prefix=/usr/local/python312
创建安装目录
sudo mkdir /usr/local/python312
开始编译
sudo make&&make install
成功后有Successfully installed pip-21.2.3 setuptools-57.4.0 类似语句
Installing collected packages: pip
WARNING: The scripts pip3 and pip3.12 are installed in '/usr/local/python312/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-23.2.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
如果之前已存在python3 的其他版本可以重命名后在建立链接
sudo mv /usr/bin/python3 /usr/bin/python3.bak
sudo ln -s /usr/local/python310/bin/python3 /usr/bin/python3
说明:
替换之前建议查询一下是否有麒麟系统使用了当前的python版本,如果使用了当前的版本版本,建议原python3链接不变,新建一个软链接:
sudo ln -s /usr/local/python312/bin/python3 /usr/bin/python312
创建venv时,使用python312 -m venv .venv的方式创建。
替换之前建议查询一下是否有麒麟系统使用了当前的python版本,如果使用了当前的版本版本,建议原python3链接不变,新建一个软链接:
sudo ln -s /usr/local/python312/bin/python3 /usr/bin/python312
创建venv时,使用python312 -m venv .venv的方式创建。