Create a Virtual Environment in Python with Conda

The present gist is a hybrid between a 'go-to' cheat sheet and a tutorial when starting a new Data Science Project.

Its purpose is to create a virtual environment for Python with the package manager Conda.


Table of contents



System Settings

Settings at the time of writing this gist (20th of January 2021).

Microsoft Windows Operating System

Microsoft Visual Studio Code

Miniconda 3

NOTE: Python is automatically installed when installing Miniconda. This gist does not explain how to install Miniconda.



Steps to creating a Conda virtual environment

Create a folder for the project

There are 2 options:

  1. Create a repository on GitHub.com BEFORE creating the new project folder on the local machine.

    Once the repository is created, clone it onto the local machine.

    NOTE: This procedure will not be covered here but it will be in a future Gist.

    OR

  2. Create the new project folder locally (see below gist)

    • First, open a Terminal Prompt within VS Code.

    • Then, go to the folder where the new project is to be created, i.e. go to the 'working folder'.

      For example, if the main folder is called python_projects, go to

      Hence, for the relative path, type:

    • Create a folder for the project called project_name and check if it was created in the working folder

    • cd into this folder

    • Open the project folder project_name from the menu in VS Code


Create a virtual environment for the project


Create 'default' folders and files

These will be needed for the project, e.g.:

OPTION: if the project is to be hosted on GitHub, the following files can be created, or done automatically when creating a repository.

NOTE: the 'LICENSE' and '.gitignore' files do NOT take a file extension. Only 'README.md' does.


Manage Conda


Manage Environments

There are 2 ways:

  1. Manage environments from the default environment folder
  2. Manage environments from a specific location

Manage environments from the default environment folder

i.e. from /miniconda3/envs


Manage environments from a specific location

i.e. not in Miniconda's envs folder (see previous section)


Manage Python


Manage Packages


Use a package list to create a NEW (identical) environment

There are 2 ways:

  1. Use a package list from a requirements.txt file
  2. Use a package list from an environment.yaml file

Use a package list from a requirements.txt file


Use a package list from an 'environment.yaml' file

Other options for managing Conda environments and packages