Working With Virtual Environments In Python Using Anaconda’s CLI
In order to help with environment issues, using virtual environments can be a lifesaver. Not only that, it allows your projects to only have the packages it needs and saves space on deployment websites like heroku, aws, and more. In this article, I’ll break down how to use Anaconda’s Command Line Interface (CLI) to create and work with virtual environments.
How To Install Anaconda’s CLI
I’m not going to reinvent the wheel. Anaconda has a great resource here that shows how to install it on multiple operating systems.
Navigate to Anaconda Prompt (like the image below) and open it up.
Once it’s open, you can verify the version using the code below.
If you need to update a version, you can use the code below
conda update conda
Creating a virtual environment
Once your CLI is all setup, navigate to the directory you’re working on code, and use the following code to create a new environment. (Note: anything in <> is what you will replace with what you want it to be)
conda create --name <env-name> python=<version>
After a minute or so, it will be created. You can activate this environment and deactivate it by using the two different lines of code below
conda activate <env-name># Deactivate
If you forgot the names of your environments, you can use the code below to give a list of all of them
conda env list
Lastly, if you need to delete an enviornment, use the code below to do that
conda env remove --name <env-name>