Skip to content

Instantly share code, notes, and snippets.

@lindacmsheard
Last active August 26, 2022 11:04
Show Gist options
  • Save lindacmsheard/928b21764d0fa2c1324804de9e38953e to your computer and use it in GitHub Desktop.
Save lindacmsheard/928b21764d0fa2c1324804de9e38953e to your computer and use it in GitHub Desktop.

Working with Conda

Generic badge

Conda helps you manage python environments on your local machine, keeping your system python free of packages that you may need for your python experiments.

Install Miniconda on Linux or WSL

-> See this gist

Install Conda on Windows

-> https://docs.conda.io/en/latest/miniconda.html

This also installs the Anaconda Prompt on your system, which can be launched from the start menu.

The Anaconda Prompt allows you to manage your conda environments.

It launches with the base environment activated, denoted by (base) before the prompt.

Managing Environments

To create a new environment, for example with python 3.6 and the scipy package:

conda create -n myenv python=3.6 scipy

Then activate that environment with

conda activate myenv

For more options on managing environments, see the documentation here.

To use Conda from within Powershell on windows

Conda started supporting Powershell from v 4.6. Assuming the Anaconda Prompt is available from the above installation, firstly update conda from within that shell to ensure you're on version >4.6.

conda update -n base conda

Then run:

conda init

Next time you open Powershell, you can use conda commands from there.

To use Conda within VScode on Windows

The above installation recommends not to add conda to the system PATH, and instead to use the Anaconda Prompt that the installation provisions.

To be able to execute conda commands, such as those for managing environments, from within the VSCode terminal:

  • restart VScode from the Anaconda Prompt (using code .), after the conda installation and after creating any new environments that need to be available to VScode in the anaconda prompt
  • install the VScode python extension, if not present
  • set python interpreter (Ctrl + Shift + P) to bring up the command pallette, type "Python: Select Interpreter" and select your miniconda installation and desired environment.

The conda environment in use is noted in the VSCode footer.


Useful links

Further notes about working with conda

Where is my python

If you're working in conda and have activated an environment, then your conda-provided python will be in the path. It should not be necessary to make manual additions to your path. On Windows, with a default Miniconda installation, this will be located in

# Base environment
C:\Users\<username>\Miniconda3\
# Other environments
C:\Users\<username>\Miniconda3\envs\<env name>\

This will be in your path when you activate the environment, and contains the version specified when you create the environment. The relevant scripts folder is

# Base environment
C:\Users\<username>\Miniconda3\Scripts
# Other environments
C:\Users\<username>\Miniconda3\envs\<env name>\Scripts

So your system python should not have anything to do anymore! 😴

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment