
Python is a high-level programming language for developing modern applications. Python has many use cases including data science and machine learning. Pip is a package manager for Python that allows you to install and manage Python packages that are not part of the standard Python library.
This article explains how to install Pip on Rocky Linux 9 for Python Package Management. You'll install multiple Python versions and create a virtual environment using the virtualenv module on your server.
Before you begin:
By default, Python version is available on Rocky Linux 9. Follow the steps below to view the default version and install the latest Python package using the DNF package manager.
View the default Python version.
Output:
Search all Python packages available in the default DNF repositories.
Output:
Install the latest Python version based on the above repository results. For example, run the following command to install Python 3.12.
List all available Python versions.
Output:
Based on the above output, the python3 command is a symbolic link to the default python3.9. Running python3 --version displays this version as the default unless you change it using the alternatives command.
Output:
Verify the new Python version.
Output:
Pip allows you to install and manage Python packages. Follow the steps below to install a specific Pip version based on the Python version on your server.
Install Pip on Rocky Linux 9. For example, Pip for python3.12.
View the Pip version.
Output:
If you're using Ubuntu, check out our detailed guide on how to install Pip on Ubuntu for managing Python packages efficiently. Follow the steps to set up Pip and streamline your development workflow.
Follow the steps below to access the Python shell and create a basic program to test your installation.
Open the Python shell.
Print a new message in the Python console.
Output:
Exit the Python shell.
Python allows multiple versions to run on the same server and you can switch between them or choose a preferred default version using the alternatives command. Multiple Python versions allow you to work on different projects requiring specific versions. Follow the steps below to install multiple Python versions and set the default version on your server.
Install another Python version, such as 3.11.
Verify the available Python versions on the server.
Output:
Use the alternatives command to enable multiple Python versions and set the default version. Replace python3.12 with your preferred default version and python3.11 with the other installed version.
List all Python versions you can switch between on the server.
Output:
Choose the Python version you want to set as the default and type your choice by specifying a number. Then, press Enter to apply the changes.
A virtual environment in Python allows you to work on multiple isolated projects that require different dependencies. Isolated environments remove dependency conflicts between projects. Follow the steps below to create a Python virtual environment.
Install the virtualenv module.
Create a sample virtual environment, such as test.
Output:
Activate the virtual environment.
Verify that your terminal prompt changes to the new virtual environment.
Deactivate the virtual environment with the following command.
You have installed Pip on Rocky Linux 9 and enabled multiple Python versions on your server. You also created a virtual environment to isolate your Python project and avoid conflicts when installing dependencies. For more information and configuration options, please visit the Python documentation.
0 Comments
Be the first to comment and share your perspective with the community.