You can install multiple versions and implementations of Python independently of your distro's package manager using pyenv.
- Install pyenv with
sudo pacman -S pyenv
.
- Set up your shell for usage with pyenv https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv
- Install the Python version of your choice (please note that CPython will be built from source).
pyenv install -l # This will list all available versions
pyenv install 3.11.1 # This will install CPython 3.11.1
- Select the Python version as the default.
pyenv shell 3.11.1 # Use this version only for this shell session
pyenv local 3.11.1 # Use this version only when you are in this directory
pyenv global 3.11.1 # Use this version as the default version
Note that this will not replace Python installed by the package manager located at /usr/bin/python
. Pyenv will only change the PATH to point python
to its Python binary.