How to install a virtual development environment for different versions of Python?

How to install a virtual development environment for Python?

How to install a virtual development environment for Python?

Nowadays, Python is one of the most influential and versatile programming languages In the field of programming and software development. And although it goes without saying, Python stands out far above others due to its clear syntax, extensive documentation/multilingual support, and enormous global community. It's also suitable for both beginners and students, as well as advanced users and expert developers. Furthermore, its full potential is most successfully realized when implemented on Linux systems. But what happens when we need to work with multiple projects that require different versions of Python or specific dependencies? Well, this is where Python comes into play. the creation of a "virtual development environment for each version of Python" additional that we install and use.

And while it is true that, on other past occasions, we have offered a quick guide to solve this problem or need through the software tool called “Pyenv”In this article, we will explore step by step another alternative and more native or official way. So, if You are a Linux user, especially Ubuntu and Debian or a derivative thereof.If you occasionally need to use multiple versions of Python for various reasons, then keep reading to learn another effective way to achieve this goal.

pyenv

But, before starting this quick little guide on this frequent requirement or need for development, that is, on "How to set up a virtual development environment for Python"We recommend that after finishing reading this publication, you explore the following previous publication related to the same topic:

Pyenv is a tool based on rbenv and ruby-build, modified to work with the Python programming language. In short, it's a fork of Python. This excellent tool helps us install, manage, and switch between multiple versions of Python, which is often done when testing code in multiple Python environments.

pyenv
Related article:
Pyenv: Install multiple versions of Python on your system

How to install a virtual development environment for different versions of Python on Linux?

How to install a virtual development environment for Python?

Steps to install a virtual development environment for a specific version of Python

Before we begin, it is important to note that, regardless of whether you are using Ubuntu or Debian, or any Distro derived from or compatible with one of them, this tutorial is ideal in principle for these, due to the use of the Team Deadsnakes PPA Repository in its first steps.

But yes In the repositories of your current Distro (other than Ubuntu/Debian) you have several versions of Python, you can easily replace these first steps with simply install a higher or lower version directly, which you already use by default, in your operating system:

Step 1:

  • We open a Terminal Emulator on Ubuntu/Debian or Derivative
  • We execute the following command orders:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update

Additionally, and in case we are using a Debian Distro or a derivative of this, the additional thing to do will be edit the “sources.list” file required with the following command:

sudo nano /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-$VersionDebianDetectada.list

Then, replace the word "bullseye," "bookworm," or "trixie," for example, or any other word corresponding to Debian and its derivatives, with the words "jammy," "focal," or "noble," corresponding to Ubuntu. This will result in, for example, the following repository line (software source):

deb https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ jammy main

And update the package lists in the repositories again.

Step 2:

Then the next step will be install a full version of Python desired or necessary along with the “python3.XX-venv” package, which installs the “pyvenv” command. For example, to install version 3.14 you will need to run the following command:

sudo apt-get install python3.14-full python3.14-venv

Step 3:

At this point, the next step is to create any folder, preferably within the user's workspace, and then specify to the operating system that we want to assign it to a specific version(s) of Python. To do this, we'll need to run, for example, the following commands:

mkdir mi_carpeta_python-v-xx
python3.14 -m venv mi_carpeta_python-v-xx

Step 4:

And to test everything and finish, we could now run some commands to check and prove that everything works outside and inside the installed Python virtual environment.

python3.14 --version #Para chequear la versión nueva instalada.
python3 --version #Para chequear la versión previa instalada.
python3 -m pip --version #Para chequear la versión actual del Gestor PIP en la versión previa instalada de Python.
python3.14 -m pip --version #Para chequear la versión actual del Gestor PIP en la nueva versión instalada de Python.
python3.14 -m pip install --upgrade pip setuptools wheel #Instalación y actualización de paquetes Python esenciales.
pip3.14 install --upgrade pip #Actualización a la última versión disponible del Gestor PIP.
pip3.14 install speedtest-cli #Instalación del paquete Python SpeedTest CLI instalado con el Gestor PIP.
speedtest-cli #Ejecución del paquete Python SpeedTest CLI instalado con el Gestor PIP.

Another last thing is to keep in mind that, many times, we will need to make use of the installed Python virtual environment, executing any command order with the full path to that version of Python within that virtual environment, as shown below:

./mi_carpeta_python-v-xx/bin/pip3.14 install --upgrade pip setuptools wheel
./mi_carpeta_python-v-xx/bin/pip3.14 install speedtest-cli

The pyvenv command (or more correctly, the Python venv module) It's a fundamental tool for creating isolated virtual environments in Python development projects. Its main objective is to isolate the dependencies of a specific project, avoiding conflicts between libraries and Python versions in different applications.

Example screenshots of the process explained

MilagrOS Ubuntu: Desktop

Python development virtual environment: Screenshot 1

Python development virtual environment: Screenshot 2

Python development virtual environment: Screenshot 3

Python development virtual environment: Screenshot 4

Screenshot 5

Screenshot 6

Screenshot 7

El Team Deadsnakes PPA Repository has proven, for a long time, to be a reliable supplier of packages of different python versions to Ubuntu, Debian, and its derivative distros. Furthermore, to use it and install some versions of Python, the steps are really easy to understand and quick to implement.

How to install the latest version of Python on Ubuntu and Debian?
Related article:
How to install the latest version of Python on Ubuntu and Debian?

Summary 2023 - 2024

Summary

In short, we hope that this new quick guide on This frequent requirement or need for development, that is, on "How to set up a virtual development environment for Python" be useful to both novices and beginners in the field of programming and in the use of different GNU/Linux and BSD Distros. However, and as usual, if you know another alternative way to solve said requirement or need for development, we invite you to mention it via comment for everyone's knowledge and use.

Lastly, remember to share this useful and fun post with others, and visit the beginning of our «site» in Spanish or other languages (adding 2 letters to the end of the URL, for example: ar, de, en, fr, ja, pt and ru, among many others). Additionally, we invite you to join our Official Telegram channel to read and share more news, guides and tutorials from our website.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.