Setting up Anaconda for Python Development

How to set up Anaconda on Windows

Date9 September 2024
Tags
pythonpythonvenvvenvanacondaanaconda

Configuring Anaconda for Windows 10

Motivations

Why Anaconda? Well, it allows you to install different (and potentially conflicting) version of Python libraries on your computer without the risk of it breaking your base Python installation.

Installing Anaconda

  1. Download miniconda from anaconda.com for the version of Python and your particular operating system.
  2. Follow the installer instructions. I installed it with the following settings:
    • Install for all users
    • Install location: C:\ProgramData\anaconda3
    • Add to PATH
    • Register as default Python installation

Adding Anaconda to PATH

If you didn’t choose the Add to Path option above, complete the following steps:

  1. Edit the PATH system variable:
    • Windows Key -> System Environment Variables
    • Select Environmental Variables -> PATH -> edit
  2. Depending on whether you installed for a single user or for all users, add the following entry in your environment variable:
    • %USERPROFILE%\Anaconda3\condabin for single user
    • C:\ProgramData\Anaconda3\condabin for all users
  3. Test that it works by opening up a new Command Prompt window and run the conda --version command

Allowing Conda to work in Git Bash

  • Open up Git Bash and run cd C:\ProgramData\anaconda3\etc\profile.d (navigate to where your Anaconda3 installation destination is)
  • Running ls should show two files - conda.csh and conda.sh
  • Run the following command to add it to your .bashrc
# If there are no spaces in your path to conda.sh:
echo ". ${PWD}/conda.sh" >> ~/.bashrc
# If there __are__ spaces in your path to conda.sh:
echo ". '${PWD}'/conda.sh" >> ~/.bashrc
  • Run cat ~/.bashrc and check that the following line has been added: . /c/ProgramData/anaconda3/etc/profile.d/conda.sh
  • Restart your terminal and run conda --version to test that it works

Creating Environments in Anaconda

Now that everything is set up, we can create environments in Anaconda using the following command:

conda create --name $envName python=$pyVersion

This command can also be extended, for example to install PyTorch:

conda install pytorch torchvision torchaudio cpuonly -c pytorch