How to install packages from Pip on Ubuntu 23.04

Ubuntu is an ideal environment for programming in Python.

If you have no idea what this article is about, you don't need to read it, as it's not something everyone needs to know. Only those who program in Python using Ubuntu 23.04 need to know how to install packages using Pip.

For those who don't know what I'm talking about, but are curious, Python is a very powerful programming language suitable for both beginners and professionals. It has a number of libraries ( programs for specific functions that can be used by other programs) that can be installed in two ways: through the distribution's traditional package manager or through its own package manager, known as Pip.

The issue is that the developers of Debian (the distribution on which Ubuntu is based) found conflicts between packages installed by one method versus the other , and from now on, when you try to install using Pip, you receive a message warning you that you are trying to install a package from an external source and suggesting two paths:

  1. Install from official repositories.
  2. Create a virtual environment

If you are going to install from repositories I recommend installing the Synaptic package manager first. since the Ubuntu Software Center search engine is a real headache. do it with
sudo apt install synaptic.

How to install packages from Pip

The first thing we need is to install the following packages: python3-full y python3-pip
The first guarantees us to have all the tools to work with Python and the second installs the Pip package manager.
The commands are:
sudo apt install python3-full
sudo apt install python3-pip.

Creating virtual environments

In Python it is possible to create a sandbox of the main Python installation in which to install dependencies and libraries without modifying the main system or the other virtual environments. This allows for example to run test versions of a future version of a library or to check how a program works in different versions of Python.

Next, we create the virtual environment with the command:

python3 -m venv titulo_entorno
And we launch it with:

source titulo_entorno/bin/activate
And we installed the package that we wanted to install with
pip3 install nombre_paquete
We leave the virtual environment with
deactivate


Add as preferred source in Google