On Unix and Mac systems if you intend to install multiple versions of Python
对 configure 使用相同的安装前缀(—— prefix 参数
脚本) ,您必须注意您的主 Python 可执行文件不是
不同版本的安装所覆盖
使用“ make altinstall”安装的目录包含主目录和次目录
“ make install”还可以创建
${prefix}/bin/python3 which refers to ${prefix}/bin/pythonX.Y. If you intend
安装多个版本使用相同的前缀,你必须决定哪一个
版本(如有)是你的「主要」版本
“ make Install”。使用“ make altinstall”安装所有其他版本。
例如,如果您希望安装 Python 2.5、2.6和3.0,其中2.6是
在主版本中,您将在2.6版本中执行“ make install”
directory and "make altinstall" in the others.
# Install Python plugin for asdf:
asdf plugin-add python
# List all available Python interpreters:
asdf list-all python
# Install the Python interpreters that you need:
asdf install python 3.7.4
asdf install python 3.6.9
# etc...
# If you want to define the global version:
asdf global python 3.7.4
# If you want to define the local (project) version:
# (this creates a file .tool-versions in the current directory.)
asdf local python 3.7.4
$ cd Python-x.x.x
$ sudo ./configure
$ sudo make altinstall
您的新 Python bin 现在位于 /usr/local/bin中。您可以测试新版本:
$ pythonX.X -V
Python x.x.x
$ which pythonX.X
/usr/local/bin/pythonX.X
# Pip is now available for this version as well:
$ pipX.X -V
pip X.X.X from /usr/local/lib/pythonX.X/site-packages (python X.X)
The advantages to these package managers is that it may be easier to set them up and install multiple versions of python with them than it is to install python from source. They also provide commands for easily changing the available python version(s) using shims and setting the python version per-directory.
cd your-project
python3.5 -m venv .venv
source .venv/bin/activate
Side note - I did try the popular 'pyenv', but found that it was doing too much in the bashrc/profile, and was slowing down shell prompt. Also, installations of new Python versions were very slow as it was compiling each version. pyenv is probably better if you need to switch between Python versions a lot for many projects.