Understanding Conda: Your Guide to Virtual Environment Management
Anaconda Distribution is a free Python/R data science distribution. It contains:
conda
- a package and environment manager for your command line interface.conda
is also written in python and is a python package.- Anaconda Navigator - a desktop application built on
conda
, with options to launch other development applications from your managed environments - over 250 scientific and machine learning packages
How is it different compared to other virtual environment managers?
- Python - In
conda
you can also chose the version of the python you want. It will then download the version of python that you asked for and then install it for your virtual environment. - Channels - Conda channels are the locations where packages are stored. You can have multiple channels from where you can get packages, and you can set there priority. Also they are prebuilt packages, so you won't have to compile the whole package yourself. Some famous channels are -
conda-forge
,anaconda
- History/Revisions - whenever you make some change to the environment it is stored as a revision to the environment, and if you want to revert back to a previous revision you can do that.
How to install packages in a conda
environment?
In conda
environment you can install packages using normal pip
, that will download the latest version of packages that your according the python you selected.
To install packages using conda you can use conda install pkgname
. This will install packages form the conda repository. There are channels
in conda, each channel is connected to a specific repository for packages.
What happens when you do conda install
?
When you do conda install, conda first look for the channels to which it have to search in, then it check for other dependencies and conflicts and find a suitable match which package to install, which package to upgrade and which to downgrade to meet the user need.
This take more time if the metadata is more and more packages are installed in an environment through conda. So it is advised to install all the packages in the starting when creating an environment.
Some basic operations in conda
conda info
- Display information about current conda install.conda info -e
- Display information about all the conda environments.conda activate
- activate the default base environmentconda activate envname
- activate theenvname
environmentconda deactivate
- deactivate the active environmentconda config --set auto_activate_base false
- this will create a.condarc
file in the home directory and then add this option there. This option will stop the base environment form activating automatically every time you start a shell.conda create --name env
- create a environment with name envconda create -n temp python=3.4
- create a environmenttemp
withpython 3.4
versionconda list
- List linked packages in a conda environment.conda install -c channel-name pkg
installpkg
form channelchannel-name
conda install ipykernel
- installipykernel
in current environment so we can open it in Jupiter notebook.conda update --all --yes
- update all packagesconda remove --name env --all
- removeenv
packageconda config --show channels
- show list of channels for current envconda config --show default_channels
- show default channelsconda config --add channels channel-name
- add channelchannel-name
to current envconda config --get channels
- show channels and there priority also.conda config --set channel_priority strict
- set the channel priority to strictconda list --revision
- show the list of revisions a env haveconda search -f pkg
- search for a package in conda.conda clean
- Remove unused packages and caches.
References
Subscribe to my newsletter
Read articles from Shivanshu Semwal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Shivanshu Semwal
Shivanshu Semwal
Software Developer. Interested in finding innovative solutions to problems.