Table of Contents
dummy
Remove an environment
To do it with no questions asked
conda env remove --name foo --yes
Ask for confirmation
conda env remove --name foo
If the environment was installed in a non standard location
conda env remove -p foo
where foo is the path of the environment.
tags | delete
related commands:
conda info --envs conda remove --help
update environment
conda env update -f environment.yml
where environment.yml is the path of the environment file
Ref:- https://conda.io/docs/commands/env/conda-env-update.html
update conda
conda update -n <env_name> -c defaults --yes conda
For example
conda update -n base -c defaults --yes conda
To specify a particular version number, X.Y.Z (ex:- 4.5.4)
conda update -n base -c defaults --yes conda=X.Y.Z
To downgrade to a specific version
conda config --set allow_conda_downgrades true conda install -n base -c defaults conda=4.6.14
tags | upgrade conda
Ref:-
- https://anaconda.org/anaconda/conda - shows the latest conda version available
find the package version
tags | check package version, list packages in environment, show the package version
To find the version of a package installed
conda list -n env_name package_name
For example
$ conda list pandas -n py39 # packages in environment at C:\ProgramData\Continuum\Anaconda\envs\py39: # # Name Version Build Channel pandas 1.2.4 py39hd77b12b_0 pandas-datareader 0.9.0 py_0
You can also use this technique to check if a package is installed.
For multiple packages
conda list -n env_name | grep -E "pkgA|pkgB"
For example
$ conda list -n py39 | grep -E "pandas|numpy" numpy 1.20.1 py39h34a8a5c_0 numpy-base 1.20.1 py39haf7ebc8_0 pandas 1.2.4 py39hd77b12b_0 pandas-datareader 0.9.0 py_0
reduce disk space usage
conda clean --dry-run --all conda clean --all
Ref:-
- https://github.com/conda/conda/issues/8630 - recommends
conda clean –all
to fixconda json.decoder.JSONDecodeError: Unterminated string starting at: line xxxxxx column xx (char xxxxxxxx)
sample environment file
name: sample_py36 channels: - conda-forge - defaults dependencies: - python=3.6.8 - pandas=0.24.1 - pip: - pywinauto - fastavro==0.21.18
where is the package cache
conda info
tags | conda cache directory
Related commands:
conda clean --all --dry-run conda clean --packages --dry-run
where is my condarc file?
$ conda info | grep "user config file" user config file : C:\Users\raju\.condarc
documentation links
activate conda environment
tags | activate conda environment through shell script
source activate vs. conda activate
For conda >= 4.4.0, use “conda activate” instead of “source activate”. The former is faster and the command remains same across OSes.
From https://github.com/conda/conda/blob/master/CHANGELOG.md#440-2017-12-20 → “New Feature Highlights” section
conda activate: The logic and mechanisms underlying environment activation have been reworked. With conda 4.4,conda activate
andconda deactivate
are now the preferred commands for activating and deactivating environments. You'll find they are much more snappy than thesource activate
andsource deactivate
commands from previous conda versions. Theconda activate
command also has advantages of (1) being universal across all OSes, shells, and platforms, and (2) not having path collisions with scripts from other packages like python virtualenv's activate script.
See also: conda activate, source activate
conda activate
# As described in https://github.com/conda/conda/issues/8186 # The conda activate command is failing with # conda.sh: line 55: PS1: unbound variable # Until the issue is fixed, set +eu before calling "source activate" # and set -eu afterwards set +eux # If the conda.sh is not sourced, then 'conda activate' is giving # CommandNotFoundError: Your shell has not been properly configured # to use 'conda activate'. source "$(dirname $(which conda))/../etc/profile.d/conda.sh" conda activate $ENV_NAME set -eux
tested with conda 4.8.3 on a machine running RHEL 7.6
See also: source activate vs. conda activate, source activate
source activate
# As described in https://github.com/conda/conda/issues/8186 # The conda activate command is failing with # conda.sh: line 55: PS1: unbound variable # Until the issue is fixed, set +eu before calling "source activate" # and set -eu afterwards set +eux source activate $ENV_NAME set -eux
tested with conda 4.8.3 on a machine running RHEL 7.6
See also: source activate vs. conda activate, conda activate
dummy
create an environment on the fly
Sample commands:
conda create -n <myenv> python ipython prompt_toolkit=2 jupyter pandas numpy scipy scikit-learn matplotlib conda create -n <myenv> python=3.9 pandas pandas-datareader
commands I came across
$ conda config --add pinned_packages defaults::conda
To revert
$ conda config --remove-key pinned_packages
What is the difference between conda, pip, and virtualenv?
- https://docs.conda.io/projects/conda/en/latest/commands.html#conda-vs-pip-vs-virtualenv-commands → scroll down to see a table that shows how to accomplish different tasks by using either conda or a combination pip and virtualenv.