Conda Important Commands

Ayon Roy
3 min readMar 18, 2020

Conda is a package manager that comes with Anaconda.

And i wanted to make a list of all this commands so that users can find them quickly when necessary…

To install a package, just substitute the package_name with the package you want to install in the following code.

conda install package_name

Similarly to uninstall or removing a package..

conda remove package_name

You can install multiple packages at the same time. Something like

conda install numpy scipy pandas

It’s also possible to specify which version of a package you want by adding the version number such as

conda install numpy=1.10

To update a package conda update package_name

If you want to update all packages in an environment, which is often useful, use

conda update --all

To list installed packages,

conda list

If you don’t know the exact name of the package you’re looking for, you can try searching with

conda search *search_term*

For example, I know I want to install Beautiful Soup, but I'm not sure of the exact package name. So,

conda search *beautifulsoup*

Note that your shell might expand the wildcard * before running the conda command. To fix this, wrap the search string in single or double quotes like conda search '*beautifulsoup*'

It returns a list of the Beautiful Soup packages available with the appropriate package name, beautifulsoup4

conda package search result

conda can be used to create environments to isolate projects. To create an environment,

conda create -n env_name list of packages

Here -n env_name sets the name of your environment (-n for name) and list of packages is the list of packages you want installed in the environment.

For example, to create an environment named my_env and install numpy in it, type conda create -n my_env numpy

To create an environment with a specific Python version, do something like conda create -n py3 python=3

or

conda create -n py2 python=2

Once you have an environment created, use conda activate my_env to enter it.

To leave the environment, type conda deactivate (on OSX/Linux).

On Windows, use deactivate

Note: conda activate and conda deactivate only work on conda 4.6 and later versions. For conda versions prior to 4.6, run activate or deactivate (on Windows), source activate or source deactivate (on OSX/Linux)

A really useful feature is sharing environments so others can install all the packages used in your code, with the correct versions. You can save the packages to a YAML file with

conda env export > environment.yaml

The first part conda env export writes out all the packages in the environment, including the Python version.

The file environment.yaml can now be shared and others will be able to create the same environment you used for the project.

To create an environment from an environment file use

conda env create -f environment.yaml

This will create a new environment with the same name listed in environment.yaml

If you forget what your environments are named (happens to me sometimes), use conda env list to list out all the environments you've created.

If there are environments you don’t use anymore,

conda env remove -n env_name will remove the specified environment (here, named env_name).

To learn more about conda and how it fits in the Python ecosystem, check out this article by Jake Vanderplas: Conda myths and misconceptions. And here’s the conda documentation you can reference later, and a link to a cheatsheet to help you basic conda commands.

--

--

Ayon Roy

I am a programmer and developer. I have worked and contributed many personal and Open-Sourced projects.