Set up virtual environment with Anaconda

Set up virtual environment with Anaconda

🌐 What is a virtual environment?

A virtual environment is a special directory for holding a specific version of Python and other modules.

πŸ€” Why do we need them?

Creating a virtual environment prevents packages with different versions from interfering with each other. This prevents the dependencies from causing conflict issues that stop the app from operating smoothly.

πŸ”„ Types of virtual environments

  • venv - an inbuilt virtual environment tool from Python

  • pipenv - the combination of pip and venv

  • conda - an open-source tool for virtual environments (widely used for data science projects)

Let's explore how to create a virtual environment using conda:

πŸš€ Setting up your virtual environment

1. Install conda πŸ’»

You can download and install conda from the official Anaconda or Miniconda website

2. Navigate to a directory of your choice in the terminal πŸ“‚

cd replace_this_with_your_directory_here

3. Create the Conda environment file πŸ“œ

Create a new file and name it (this one is called my_first_conda_venv.yml).

Then add the information about the environment to it:

name: my_first_conda_venv
  - defaults
  - python=3.10
  - pip
  - pip:
    - -r requirements.txt

4. Create the requirements.txt file πŸ“

List the Python libraries you need later on into the requirements.txt file:


5. Create and activate your environment 🌿

Use these commands to set up and access your environment:

conda env create -f my_first_conda_venv.yml
conda activate my_first_conda_venv

6. Deactivate your environment πŸ›‘

Always shut down the environment after you’re done working in it:

conda deactivate

Happy coding!✨