
Python is a versatile, high-level programming language widely used for web development, automation, data analysis, and more. Pip is Python’s package installer, allowing you to easily install and manage additional libraries and dependencies not included in the standard library. Installing Python and Pip on Debian 12 sets up a solid foundation for a wide range of development and scripting tasks.
This article explains how to install Python and Pip on Debian 12. You will install multiple Python versions and create a virtual environment to develop applications on your server. If you're using Ubuntu instead, check out how to install Python and Pip on Ubuntu 24.04.
Before you begin:
Debian 12 comes with a specific version of Python pre-installed by default. While Python is also available in the official package repositories, it may not be the latest release. For those interested in installing Python on Debian with the most up-to-date features, the recommended approach is to compile it from source. Follow the steps below to install the latest Python version on your server.
View the default Python version on your server.
Output:
Install all Python dependency packages.
Visit the Python downloads page and verify the latest version. For example, version 3.13.0. Then, download the archive file.
Extract all files from the archive.
Switch to the new Python directory, such as Python-3.13.0.
Run the configure script to prepare the Python source code before compiling.
Compile the Python source code into executable binaries using the make command.
Install the new Python version as an alternative without replacing the default version on your server.
View the new Python version to verify the installation is successful.
Output:
Pip is a Python package manager that installs and manages dependency packages in a development environment. Pip uses Python Package Index (PyPI) third-party libraries and other repositories to install dependencies in a Python environment. Python automatically installs Pip on the server. Follow the steps below to verify the Pip version depending on the Python version on your server.
View the default Pip version on your server.
Output:
View the new Pip version that matches the Python 3.13 version you installed earlier.
Output:
To set up Python and streamline package management in Rocky Linux 9, follow this guide to Install Pip on Rocky Linux 9.
Follow the steps below to create a basic web server that listens for HTTP connections on port 5000 and test the Python installation on your server.
Create a new hello.py Python file using a text editor like nano.
Add the following contents to the hello.py file.
Save and close the file.
The above Python application listens for connections on all addresses on the server and outputs the Greetings from Vultr message when you access it using an HTTP client such as Curl or web browser.
Allow network connections to port 5000 through the firewall.
Run the application using your latest Python version as a background process.
Output:
Access your server's public IP address using a web browser like Chrome on port 5000.
When developing multiple Python projects, you may require different Python versions on your server. The default package repositories on Debian 12 do not include multiple Python versions. Follow the steps below to install and switch between multiple versions using the asdf tool on your server.
Install asdf dependency packages.
Clone the asdf project repository. Visit the releases page to verify the latest version.
Open the .bashrc file in your shell environment.
Add the following configurations at the end of the file.
Save and close the file.
Reload the .bashrc file to apply changes in your session.
View the new asdf version.
Output:
Install the asdf plugin for Python.
List all available Python versions available in the asdf sources.
Output:
Install a specific Python version, such as 3.10.0.
List all installed Python versions.
Output:
Change the default Python version to the new version.
View the active Python version to verify your changes.
Output:
Run the following command to switch back to the pre-installed Python version on your server.
A virtual environment creates an isolated environment to store Python project files with all necessary dependencies and libraries. You can use the native venv module to manage the Python virtual environments on your server. Follow the steps below to create a new Python virtual environment.
Install the python3-venv package.
Create a new myproject directory.
Switch to the myproject directory.
Create a new myenv virtual environment.
Activate the virtual environment.
Output:
Install a specific Python module, such as Flask to use in the environment.
View the Flask version.
Output:
Run the deactivate command to exit the virtual environment.
You have installed Python and Pip on a Debian 12. In addition, you've installed and activated multiple Python versions using asdf to meet your project needs. You can integrate Python with other packages like database servers to develop and manage applications. For more information, please visit the Python documentation.
0 Comments
Be the first to comment and share your perspective with the community.