Anaconda provides a command-line utility called conda
for installing and managing different versions of the Python programming language and third-party packages.
Anaconda is a package manager, an environment manager, a Python/R data science distribution, and a collection of over 1,500+ open source packages. Anaconda is free and easy to install, and it offers free community support. - Anaconda website
Because new versions of the Python language and third-party Python packages get released from time to time, and because sometimes code that works with an older version may no longer work with a newer version, we need a way to manage which version of Python our project is using, and also the versions of all its third-party package dependencies.
Anaconda helps us maintain project-specific environments with the right versions of Python and third-party packages, so we can easily switch between different environments when working on different projects.
To check to see if Anaconda is already installed:
conda --version
#> conda 4.5.12
# Mac Terminal:
which conda
#> /anaconda3/bin/conda
# Windows Anaconda Prompt or Git Bash:
where conda
#> C:\Users\YOUR_USERNAME\Anaconda3\Library\bin\conda.bat
#> C:\Users\YOUR_USERNAME\Anaconda3\Scripts\conda.exe
On a Mac, you can invoke the detection commands directly in the Terminal:
On Windows, you can search for the "Anaconda Prompt" application to know whether or not you have Anaconda installed (although we will not ususally be using this application):
After the Anaconda Prompt is installed, we can invoke conda
commands from within it (although we will not usually be using this application):
NOTE: we don't want to use the Anaconda Prompt, because it is harder to integrate with other tools. Instead, we want to be running our
conda
commands in Git Bash instead (see below).
If Anaconda is installed the way we need it to be, we should ultimately be able to invoke conda
commands from within the Git Bash console:
NOTE: if Git Bash doesn't recognize
conda
commands ("conda command not found"), you might have to uninstall Anaconda and when re-installing it, make sure to check the "Add Anaconda to my PATH environment variable" option (see installation instructions below).
If not yet installed, download Anaconda for either Mac or Windows.
NOTE: This might take a while, so prefer to do it over a strong WiFi connection. And feel free to ignore any email capture forms which may pop up afterwards.
After the download has finished, run the installer program and accept all the default options, except for this important exception to "Add Anaconda to my PATH environment variable", which will allow other programs like Git Bash to recognize the Anaconda installation:
The installation will take a few minutes to complete.
NOTE: After installing Anaconda on a Mac, you will need to restart your terminal for the changes to take effect.
After the installation is complete, try repeating the detection commands again, as described in the section above.
Once you are able to successfully detect your installation of Anaconda, you are ready to proceed!
References:
View a list of existing virtual environments:
conda info --envs
Create a new virtual environment, and name it something like "my-first-env" (we'll always want to specify the Python version):
conda create -n my-first-env python=3.8
Enter into, or "activate", the virtual environment:
conda activate my-first-env
NOTE: when using conda to activate a virtual environment for the first time, Windows Git Bash users may need to run
conda init bash
, and Mac Zsh profile users may need to runconda init zsh
, when prompted to do so.
After activating the environment, you should be able to detect and use its installations of Python and Pip (see notes on the python
utility and the pip
utility):
python --version
pip --version
pip list
# etc.
To deactivate the current environment:
conda deactivate
It is possible to delete environments, although this might not be necessary unless trying to free up space on the computer:
conda env remove -n my-first-env