Python & Virtual Environments - Miniconda

Why do we need Virtual Environments?
 

Django projects depend on several tools and packages to run properly.
The most obvious one is Django itself.
Another important one is Python.
 

Imagine you created a Django project many years ago.
That project could depend on an old version of Django
and an old version of Python.


Years later, you may create a new project
using a modern version of Django,
such as Django 5.2,
and a modern version of Python,
such as Python 3.10 or newer.





If both projects shared the same Python installation,
their dependencies could conflict with each other.

For this reason, we use virtual environments.
Each project can have its own isolated environment.
Each environment can have its own Python version,
Django version, and installed packages.



 

Creating a Virtual Environment with Miniconda

 

  1. Installing Miniconda:
    https://www.anaconda.com/download/success
     
  2. Creating a virtual environment
    conda create -n jaimedcsilva python=3.10
    In this example, we create a virtual environment named jaimedcsilva with Python 3.10 installed.

    Note: You may be asked if you want to install additional packages. Choose yes, because those packages are needed to create the environment correctly.
     
  3. Activating the virtual environment
    conda activate jaimedcsilva
    You know that the virtual environment is activated when its name appears between parentheses in your command line:

    (jaimedcsilva) C:\Users\jaime>

 

 

 

Other useful Miniconda commands

 

Deactivating a virtual environment

conda deactivate



Removing a virtual environment permanently

conda remove -n jaimedcsilva --all



Listing all existing virtual environments

conda info --envs