Creating virtual environments for coding in Python
Installing Python on your computer is a simple task. Go to python.org and install the version of Python that you require.
It is not the best practice to use these installation of Python, though. One of the reasons for the great success of Python, is its package ecosystem. There are thousands of packages that extend the capabilities of the Python language.
Packages have dependencies. Dependencies exists for the version of Python, and in many cases, on specific versions of other packages. Installing multiple packages can cause issues. If the installed versions of packages are incompatible, you can end up in what is referred to as dependency hell. In the worst case, you can end up with unusable installations of Python.
To avoid this, it is recommended to use virtual environments. These are copies of Python, created for specific tasks. These copies mean that the base installation(s) of Python are never altered.
There are two approaches to creating these environments. Miniconda (that runs in the Terminal), or the full Anaconda (graphical user interface), can be used to create system-wide virtual environments. Specific packages can then be installed in each environment. I have three such envirnoments on my main computer. One for data science, one for geospatial data science, and one for mathematics.
The alternative is to create a virtual environment for each project, which in my case, lives in a folder (for each project). The built-in virtual environment manager venv and the newer, and much faster, environment and package manager is uv. It may be effective to use these per-project environments, but it does mean that your system can end up with many, many virtual environments. that can take up a lot of space. It may also be required not to install these in folders that are available in the cloud, such as OneDrive folders.
I have made a video tutorial about setting up all three of these environments.