使用自定义路径从源代码在 Linux 上安装 python

Install python on Linux from source with custom paths

我找到了如何从源代码安装它的教程,但在所有教程中都使用了默认配置。

我想安装一个新的 python 版本,与操作系统所在的分区不同,所以不在 /usr/bin 和默认路径中。

因此,如果我从备份恢复主分区,则无需重新安装新的 python 版本。也很容易(小的变化)(重新)将 VisualStudioCode 或 Pycharm 之类的 IDE 指向新的 python 版本。(可能只是添加到路径)。

我不想安装工具来执行此操作。

这个过程非常简单,假设你想安装在你的 $HOME

# 0) Download python source and extracted it to $HOME/tmp/Python3.9.2 directory
# 1)
mkdir $HOME/usr
# 2)
cd $HOME/tmp/Python3.9.2
# 3)
./configure --prefix=$HOME/usr && make
# 4) Now python is built in $HOME/tmp/Python3.9.2, give it a test, then
make install
# Now you should have $HOME/usr/bin/python ready to use.