To install different versions of Python on Arch Linux without affecting the system's built-in Python, it is recommended to use the following methods:
1. Using pyenv
#
pyenv
is a popular tool that allows you to easily install and manage multiple versions of Python without interfering with the system's default Python version.
It's similar to a virtual machine; you can install different operating systems. If you want to use Windows 7, you create a virtual machine and install Windows 7. If you want to use Windows 10, you create a virtual machine and install Windows 10.
Here, pyenv
is intended to switch the system's Python version to whichever Python version you want to install directly, without needing root permissions to install various versions of Python.
Installing pyenv
#
-
Install dependencies:
pyenv
requires some dependencies needed to compile Python.sudo pacman -S base-devel libffi openssl zlib bzip2 readline sqlite gdbm db gamma libpcap xz tk
-
Install
pyenv
: Usepacman
to installpyenv
.sudo pacman -S pyenv
-
Configure environment variables: Add the
pyenv
initialization script to your shell configuration file (e.g.,~/.bashrc
or~/.zshrc
).If any of the four commands in this step report an error after execution, you can try using other
pyenv
commands. If other commands work, you can ignore this and use it normally.echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(pyenv init --path)"' >> ~/.bashrc echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc source ~/.bashrc
Using pyenv
to Install Python#
-
Install a specific version of Python:
pyenv install 3.8.10
-
Set the global Python version:
pyenv global 3.8.10
-
View installed Python versions:
pyenv versions
-
View available Python versions:
You can use the
pyenv install --list
command to see all available Python versions for installation.pyenv install --list
-
Temporarily switch Python versions
Use the
pyenv shell
command to temporarily set the Python version for the current terminal session. This version is only effective in the current terminal session and will be lost when the terminal is closed.pyenv shell 3.8.10