cd
mkdir project
cd project
python -m venv .venv
Windows
.venv\Scripts\Activate.ps1
Linux/macOS
source .venv/bin/activate
Windows
Get-Command python
Linux/macOS
which python
python -m pip install --upgrade pip
deactivate
When you install Python, it creates some directories with some files in your computer.
Some of these directories are the ones in charge of having all the packages you install.
Then it will extract all those files and put them in a directory in your computer.
By default, it will put those files downloaded and extracted in the directory that comes with your Python installation, thatβs the global environment.
The solution to the problems of having all the packages in the global environment is to use a virtual environment for each project you work on.
A virtual environment is a directory, very similar to the global one, where you can install the packages for a project.
This way, each project will have its own virtual environment (.venv directory) with its own packages.