How to Install Python and pip on Arch Linux

This guide will walk you through the process of installing Python and pip on Arch Linux, ensuring you have a robust and clean environment for Python development.

Arch Linux, known for its simplicity, transparency, and cutting-edge software, is a favorite among advanced users and developers. One of the most common development tools you’ll need on Arch is Python—a versatile and powerful programming language used for everything from scripting and automation to web development and data analysis.

In this article, we’ll walk through how to install Python and pip on Arch Linux, ensuring you have a robust and clean environment for Python development. We’ll also explore how to manage multiple Python versions and virtual environments effectively.


Why Python?

Python is widely regarded for its readability, simplicity, and a vast ecosystem of packages and libraries. Whether you’re a beginner or a seasoned developer, Python offers the tools and flexibility to build a variety of applications efficiently.

Most Linux distributions come with Python pre-installed, including Arch Linux. However, it’s important to know how to manage it correctly, especially when it comes to package management and virtual environments.


Step 1: Check If Python Is Already Installed

Arch Linux often comes with Python pre-installed as it’s used by several system utilities. You can check the current version by running:

python --version

or

python3 --version

Typical output:

Python 3.12.2

If the command is not found or returns an error, it means Python isn’t installed, or it’s not properly linked.


Step 2: Install Python on Arch Linux

Arch uses the pacman package manager, which provides access to the official Arch repository. To install Python:

sudo pacman -S python

This command installs the latest stable version of Python 3 and the standard library. After installation, confirm the version again:

python --version

Linking python to python3

By default, the command python should point to Python 3 on Arch. If it doesn’t, you can add a symbolic link:

sudo ln -s /usr/bin/python3 /usr/bin/python

⚠️ Be cautious when creating symlinks for system binaries, as some scripts may expect specific versions.


Step 3: Installing pip (Python Package Installer)

pip is the standard tool for installing Python packages from the Python Package Index (PyPI). It often comes bundled with Python 3.4+ via ensurepip, but it can also be installed separately.

To install pip using pacman

sudo pacman -S python-pip

After installation, verify it:

pip --version

You should see something like:

pip 24.0 from /usr/lib/python3.12/site-packages/pip (python 3.12)

Note: If you installed Python via pacman, pip should automatically correspond to python-pip. However, always ensure that the pip version matches your Python version.


Step 4: Using pip to Install Python Packages

Once pip is installed, you can use it to install packages globally (not recommended) or inside virtual environments (recommended). Here’s a quick example of installing the popular requests library:

pip install requests

To upgrade pip itself:

pip install --upgrade pip

If you receive a permission error, try using:

python -m pip install --upgrade pip --user

Step 5: Managing Virtual Environments

Working in virtual environments is a best practice in Python development. It keeps dependencies isolated and avoids polluting the global package namespace.

Creating a Virtual Environment

First, install the venv module if it’s not already included:

sudo pacman -S python-virtualenv

Now, create a new virtual environment:

python -m venv myenv

This creates a new directory called myenv containing a standalone Python interpreter and pip.

Activating the Environment

To activate it:

source myenv/bin/activate

You’ll notice your shell prompt changes to reflect the active environment. While it’s active, any package installed via pip goes inside this environment only.

To deactivate:

deactivate

Step 6: Installing Multiple Versions of Python (Optional)

Sometimes you need to test code against multiple versions of Python. For this, you can use the AUR (Arch User Repository).

Installing pyenv

A popular way to manage multiple versions is via pyenv. Install it from the AUR using an AUR helper like yay:

yay -S pyenv

Add the following lines to your shell config (e.g., ~/.bashrc or ~/.zshrc):

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"

Then restart your shell or source your config:

source ~/.bashrc

Now you can list and install different Python versions:

pyenv install 3.11.6
pyenv install 3.10.13

And set a global or local version:

pyenv global 3.11.6
pyenv local 3.10.13

pyenv compiles Python from source, so the build process might take some time.


Step 7: Tips for pip on Arch Linux

Arch Linux’s philosophy leans toward using the system package manager (pacman) for installing software, including Python modules when possible.

Use pacman for System-Wide Packages

Some Python libraries (e.g., numpy, matplotlib) are available in the official repo:

sudo pacman -S python-numpy python-matplotlib

These are pre-built and optimized for Arch, so they are generally preferred over pip installations for system-wide use.

Avoid Using sudo pip

Using sudo pip install can overwrite system files or cause conflicts. Instead:

  • Use pip install --user for per-user installations.
  • Use virtual environments for isolated environments.
  • Use pacman or yay for system-wide installations.

Troubleshooting

1. pip: command not found

Ensure that python-pip is installed via pacman.

sudo pacman -S python-pip

2. ModuleNotFoundError After Installing a Package

Ensure that you’re using the correct Python environment where the package was installed. Activate the virtual environment or use:

python -m pip list

To confirm installation in the expected context.

3. Conflicts Between System and User Packages

Use --user flag with pip or virtual environments to avoid clashes.


Conclusion

Installing Python and pip on Arch Linux is straightforward, thanks to its minimalistic and user-controlled environment. By understanding how to manage Python, pip, and virtual environments effectively, you can maintain a clean and productive development workflow.

Recap:

  • Use pacman to install Python and pip.
  • Prefer virtual environments for package management.
  • Use pyenv to manage multiple Python versions.
  • Avoid sudo pip install—use --user or virtual environments instead.

Whether you’re scripting simple tasks or building complex applications, a well-configured Python environment on Arch Linux sets a strong foundation for success.