How to Install PIP on Arch Linux

PIP is a tool for installing, upgrading, and managing Python packages. It is popular among Python developers because it makes handling packages easier. For example, you can use pip to install a package like pandas, which can be used to count files by reading directories into a DataFrame and then using DataFrame methods to count files.

This article covers PIP installation on Arch Linux in two different ways.

Key Takeaways

  • To install PIP on Arch Linux, use the "sudo pacman -S python-pip" command. This will install PIP system-wide on your Arch Linux.
  • You can also install PIP using the "get-pip.py" installation script. Download the script and install using the "python get-pip.py" command.

1. How to Install PIP on Arch Linux

To install PIP on Arch Linux, you can use the default package manager Pacman or directly download the PIP using the official PIP installer. Both these methods required Python to be installed on your Arch machine.

Before you begin, ensure that you have the following prerequisites:

  • Python 3: Pip requires Python 3 to function; therefore, ensure that Python 3 is installed on your Arch Linux system.
  • User with Sudo Privileges: You must have a user account with sudo privileges to install pip.
  • Access to Terminal: You must have an active terminal for installation.

Before installing pip, it is a good practice to update your system to ensure you have the latest packages and security patches:

sudo pacman -Syu

The first step is to check whether you have an updated Python version available or not. To check the Python version, run this:

python --version

Arch Linux terminal with Python version displayed

If Python is missing, install it using the Pacman package manager:

sudo pacman -S python

Now that the Python is set, you can proceed with the PIP installation.

As described above, PIP can be installed using the default Pacman package manager and the official PIP installer.

1.1. Installing PIP on Arch Linux Using Pacman

To install PIP using Pacman, run this command:

sudo pacman -S python-pip

Arch Linux terminal with the pip installation command

This will install the PIP on Arch Linux for the latest Python version.

1.2. Installing PIP on Arch Linux Using the Official PIP Installer

Another method to get PIP on Arch Linux is to use the PIP installer. This method involves using a Python script to handle the installation for you.

First, download the PIP installer script using the wget command:

wget -q https://bootstrap.pypa.io/get-pip.py

Arch Linux terminal with wget command to download pip Python script

Once downloaded, navigate to the directory where the get-pip.py file is saved. Then, execute the installer script with Python:

python get-pip.py

This script will download and install pip, setuptools, and wheel into your Python environment. Setuptools and Wheel are essential tools for creating and distributing Python packages.

1.3. Handling the Externally Managed Environment Error

You will get the externally-managed-environment error when installing PIP using the Python script method. This issue arises because the Arch Linux system’s package manager manages the Python environment. This protective measure prevents conflicts between the system and user-installed packages.

Arch Linux terminal with externally managed error while PIP installation

To resolve this error, you can create a virtual environment using the following commands:

python3 -m venv path/to/venv
source path/to/venv/bin/activate

Once activated, you can install pip in this isolated environment without affecting system-wide packages. However, if you want to install the PIP system-wide, consider using the next method.

Another quick fix to this error is to remove the EXTERNALLY-MANAGED file:

sudo rm -rf /usr/lib/python3.12/EXTERNALLY-MANAGED

Arch Linux terminal with remove command

Remember to change the Python version in the above command.

Warning
Removing the Externally Managed File may temporarily fix the issue, but it is generally not recommended. This action can disrupt system package management and lead to stability and update problems.

 

After removing the EXTERNALLY-MANAGED file, rerun the pip installer script:

python get-pip.py

Arch Linux terminal with Python command to install PIP

This time, PIP should be installed without any issues.

Arch Linux terminal with Successful installation of PIP message

To ensure you can use PIP from any location in your terminal, add its installation directory to your system’s PATH:

export PATH=$PATH:/home/linux/.local/bin

Arch Linux terminal with the export command for the PIP path

This command adds the PIP installation directory to the PATH environment variable, allowing the system to locate and execute PIP from any directory.

If you’ve changed your mind after ignoring the warning, don’t worry! You can recreate the file with these commands:

cd /usr/lib/python3.12
sudo touch EXTERNALLY-MANAGED

Arch Linux terminal recreating the Externally Managed File

PIP is successfully installed on Arch Linux. Now we will confirm its installation.

2. How to Quickly Verify PIP Installation on Arch Linux

To quickly verify the PIP installation, you can run the version command:

pip --version

If you have used Pacman for PIP installation, you will get this output:

Arch Linux terminal with PIP version output

And for the PIP installation script, the output will look like this:

PIP version of get-pip.py script method

We’ve successfully installed and verified PIP for Python3 on Arch Linux.

3. How to Use PIP: Essential Operations for Arch Linux Users

You can now use PIP to install, upgrade, and manage Python packages. Here are some common pip commands:

To upgrade a current PIP version, you can run the PIP command with the install and upgrade flag:

pip install --upgrade pip

While searching for Python packages with the pip search command used to be the go-to method, it’s getting phased out due to high traffic. You can still find the Python packages you need online. Websites like PyPI act as a search engine specifically for Python packages.

To install a package using PIP, run this command:

pip install <package_name>

Now, if you want to install a specific version of the Python package using the PIP command, use the == operator along with the version number:

pip install <package_name>==<package_version>

To install a package from an alternative index instead of the default PyPI, use the –index-url option.

For example, to install pandas from the PyPI simple index run:

pip install --index-url https://pypi.org/simple/ pandas

You can also install a Python package from a local directory by providing the path to the pip command.

For example, the following command will install [my_package] from the current directory:

pip install ./my_package

List all the installed Python packages using the list command:

pip list

Arch Linux terminal with pip list command output

To get details for an installed Python package, use the show flag with the PIP command:

pip show <package_name>

For uninstalling a Python package using PIP, run this command:

pip uninstall <package_name>

Now to get details of all the PIP-supported commands, run the PIP help command:

pip help

Arch Linux terminal with pip help command output

So these are the PIP basic commands to use in Arch Linux.

4. How to Set up Python Virtual Environments in Arch Linux

To set up a Python virtual environment, ensure you have Python installed by typing python in your shell.

Now create a virtual environment using venv command:

python -m venv project1

This will create a virtual environment named project1. When you list the directories, you will see a directory called project1.

ls -l

Arch Linux terminal with virtual environment

To list the contents of the project1 directory:

ls project1

Inside the virtual environment

You will see directories, some files, and executables like bin, lib, and configuration files related to the virtual environment.

To check the content of the virtual environment configuration file, run:

cat pyvenv.cfg

Now, activate the virtual environment, type:

source path_to_project1/bin/activate

Adding the PIP path to the system directory

Your terminal will change to the Python virtual environment, indicating it’s activated.

Now, install some packages. For example, you can get the latest version of the requests package:

pip install requests

Arch Linux terminal with Installation of Requests using PIP

To deactivate the virtual environment, type:

deactivate

deactivate command to exit the virtual environment

In this way, the Python virtual environment will be deactivated, and you will be back to your local system.

5. How to Safely Remove PIP from Arch Linux

To uninstall the PIP that was installed using Pacman, execute the following command:

sudo pacman -R python-pip

Arch Linux terminal displaying the PIP removal command using Pacman

If you used the get-pip.py script to install pip, you can remove both pip and setuptools with this command:

python -m pip uninstall pip setuptools

Arch Linux terminal with PIP removal command

You can add the -y option to the command to confirm the uninstallation automatically.

We have successfully now removed the PIP from the Arch Linux system.

6. Conclusion

To install PIP on Arch Linux, you can use the default Arch Linux package manager Pacman. Another method to get PIP is using the official PIP installer script. While Pacman is straightforward, the PIP installer script causes externally managed errors. These can be resolved by removing the externally managed file or installing PIP in a Python virtual environment. Additionally, we have also covered basic PIP usage commands for Arch Linux.

Leave a Comment