Sign In
Sign In

How to Install Python and Pip on Ubuntu 24.04

How to Install Python and Pip on Ubuntu 24.04
Adnene Mabrouk
Technical writer
Ubuntu
06.09.2024
Reading time: 4 min

Python is one of the most popular programming languages, widely used for web development, data analysis, artificial intelligence, and more. Pip, the package installer for Python, allows you to install and manage additional Python libraries and tools. Ubuntu 24.04, being a robust and user-friendly Linux distribution, makes it relatively simple to install both Python and Pip. This guide will walk you through the process step-by-step.

Prerequisites

Before you begin, make sure you have the following:

  • A local computer or a cloud server with Ubuntu 24.04 installed.
  • A regular user with sudo access.
  • A stable internet connection.
  • Basic knowledge of terminal commands.

Updating the Package List

Before installing any software, it's essential to update your system's package list to ensure you're downloading the latest versions. To do this, open your terminal and run the following command:

sudo apt update

This command updates the list of available packages and their versions but does not install or upgrade any packages.

Installing Python

Ubuntu 24.04 comes with Python pre-installed with version 3.12. However, you might need a specific version or the latest version. To install Python, use the following command:

sudo apt install python3

This command installs the latest version of Python 3 available in the Ubuntu repositories.

Verifying the Python Installation

Once the installation is complete, you should verify that Python is installed correctly. To check the installed version of Python, run:

python3 --version

You should see output displaying the version of Python installed, for example, Python 3.12.3. This confirms that Python is successfully installed on your system.

Installing Pip

Pip is the package manager for Python, which allows you to install additional libraries and packages. To install Pip for Python 3, run the following command:

sudo apt install python3-pip

This command installs Pip and its dependencies.

Verifying the Pip Installation

After Pip is installed, verify the installation by checking its version:

pip3 --version

You should see output similar to pip 24.0 from /usr/lib/python3/dist-packages/pip (python 3.12), confirming that Pip is installed and linked to the correct Python version.

Setting Up Virtual Environments

Virtual environments are useful for managing dependencies for different projects separately. To create a virtual environment, you first need to install the venv module if it's not already installed:

sudo apt install python3-venv

Next, create a virtual environment in your project directory:

mkdir project && cd project
python3 -m venv myenv

Replace myenv with the desired name of your virtual environment. To activate the virtual environment, use:

source myenv/bin/activate

Your terminal prompt will change, indicating that you are now working within the virtual environment. To deactivate, simply run:

deactivate

Troubleshooting Common Issues

  1. Python Command Not Found: If the python3 command is not recognized, ensure that Python is installed and properly linked by running sudo apt install python3 and verifying the installation again.

  2. Pip Command Not Found: If the pip3 command is not recognized, re-install Pip using sudo apt install python3-pip and verify its installation.

  3. Permission Denied Errors: If you encounter permission errors when installing packages with Pip, consider using pip3 install package-name --user or ensure you are using sudo when necessary.

  4. Outdated Pip Version: If you need the latest version of Pip, upgrade it using pip3 install --upgrade pip.

Conclusion

Installing Python and Pip on Ubuntu 24.04 is a straightforward process that enables you to start developing and managing Python projects quickly. With Python and Pip installed, you can now explore the vast ecosystem of Python libraries and tools. Setting up virtual environments further enhances your ability to manage project-specific dependencies, keeping your development environment clean and organized. By following this guide, you’ve laid a solid foundation for Python development on your Ubuntu system.

Ubuntu
06.09.2024
Reading time: 4 min

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start
Email us
Hostman's Support