conda
is a package manager like pip
. However, there are important differences: (i) it is not restricted to python (via PyPI), (ii) has better dependency resolution, and (iii) has excellent environment management capabilities.
This last difference allows us to create isolated environments that can contain different versions of Python and packages, making it easier to manage dependencies and avoid conflicts between packages.
There are two broad ways to get conda. The first involves installing Anaconda which comes with a large number of other packages (7500+) relevant for ML and scientific computing. If you want just the basics then you should get miniconda.
Detailed instructions are here. For example, here are specific instructions to install on Linux.
After installation, the terminal prompt shows the conda environment (base)
by default. Suppose you find this appearance annoying, or you want use the system-wide base python install.
If you want to default to the system-wide base python install on startup, run the following command in your terminal once.
conda config --set auto_activate_base false
When you activate a conda environment, you will see that before the prompt
$ conda activate myenv
(myenv) $
If you want to use conda, but never see the environment in parenthesis (base or otherwise), then run the following command once.
conda config --set changeps1 False
By default jupyter notebook
will use the system-wide python installation. To use a particular conda environment in jupyter notebooks there are several strategies.
The most useful (to me) seems to be option 2. It avoids a separate jupyter installation in each conda environment (option 3). You install nb_conda_kernels
in the base conda distribution, and ipykernel
in each conda environment.
conda activate my-conda-env # this is the environment for your project and code
conda install ipykernel
conda deactivate
conda activate base # could be also some other environment
conda install nb_conda_kernels
jupyter notebook
-
Create a new environment
conda create --name myenv python=3.8
-
Activate an environment
conda activate myenv
-
Deactivate the current environment
conda deactivate
-
List all environments
conda env list
-
Remove an environment
conda env remove --name myenv
-
Export an environment to a YAML file
conda env export --name myenv > environment.yml
Create an environment from a YAML file
conda env create --file environment.yml
-
Install a package in the active environment
conda install package-name
-
Install a specific version of a package
conda install package-name=1.2.3
-
Update a package
conda update package-name
-
Remove a package
conda remove package-name
-
List installed packages in the active environment
conda list
-
Search for packages
conda search package-name