Conda notes
From raju
Note:- This page will be migrated to http://www.kamaraju.xyz/dk/conda_notes. Once the migration is done, it will be deleted.
Contents
- 1 replicate environment
- 2 dummy
- 2.1 Remove an environment
- 2.2 List all the environments
- 2.3 clone an environment
- 2.4 rename an environment
- 2.5 create an environment from a file
- 2.6 Create an environment
- 2.7 Create an environment for python 3.6
- 2.8 update environment
- 2.9 update conda
- 2.10 create and remove environment in nonstandard location
- 2.11 list current environment
- 2.12 install a specific version of a package in an environment
- 2.13 list available package versions
- 2.14 path to python
- 2.15 activate and deactivate environments
- 2.16 activate a conda environement if it is not already activated
- 2.17 where is the package cache
- 2.18 Specifying version numbers
- 2.19 sample environment file
- 2.20 file locations
- 2.21 which package gives jupyter
- 2.22 getting help
- 2.23 useful links
- 2.24 breaking changes
- 2.25 Anaconda channel vs defaults channel
- 3 Anaconda
- 4 Troubleshooting
replicate environment
Method 1
Check the environments installed
conda info --envs
Export the environment
conda env export --name FOO | grep -v "^prefix: " > environment.yml
Note: By default, the output of "conda env export" contains a line
prefix: /path/to/the/environment
This line is not necessary in order to recreate the environment. Grepping it out so that the replicating user will not know what the original environment's path is.
Another way
- On Windows
activate myenv conda env export | grep -v "^prefix: " > environment.yml deactivate
- On Linux
source activate myenv conda env export | grep -v "^prefix: " > environment.yml source deactivate
To recreate it
conda env create -f environment.yml activate myenv
Ref:-
- https://conda.io/docs/user-guide/tasks/manage-environments.html
- https://stackoverflow.com/questions/41274007/anaconda-export-environment-file
Method 2
Get the list of packages
$ conda list --export --name old_environment > req.txt
or
$ conda list -e -n old_environment > req.txt
Create a new environment using
$ conda create -n new_environment --file req.txt
Ref:- https://docs.conda.io/projects/conda/en/latest/commands/list.html
dummy
Remove an environment
without asking any questions
conda env remove --name foo --yes
Ask for confirmation
conda env remove --name foo
tags | delete
related commands:
conda info --envs conda remove --help
List all the environments
conda info --envs
clone an environment
tags | copy environment
conda create --name new_environment --clone old_environment
Ref:- https://conda.io/docs/user-guide/tasks/manage-environments.html#cloning-an-environment
rename an environment
conda create --name $newName --clone $oldName conda remove --name $oldName --all
Ref:-
- https://github.com/conda/conda/issues/3097#issuecomment-308814104 - contains a bash function to do this.
- https://stackoverflow.com/questions/42231764/how-can-i-rename-a-conda-environment
create an environment from a file
conda env create -f env.yml
Create an environment
Always specify the python version you want while creating the environment. For example
conda create --name foo python=2.7
If python version is not specified, there will not be a python.exe under the corresponding environment directory /c/ProgramData/Continuum/Anaconda/envs/foo . The python.exe is needed to link this environment in pycharm when choosing the python interpreter path.
Sample commands I used in the past:
conda create -n market_data_processor python=3.6 pandas pep8 pandas-datareader
Sample commands I came across:
conda create -n py37 python=3.7.0 pandas=0.23.4 line_profiler=2.1.2
Create an environment for python 3.6
conda create -n py36 python=3.6 anaconda
Switch to the new environment
activate py36
update environment
conda env update -f FILE
where FILE 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
create and remove environment in nonstandard location
To create environment foo
conda env create -p foo -f env.yml
This will create a foo directory under the current working directory and place all environment specific files underneath it.
To remove
conda env remove -p foo
list current environment
Use $CONDA_DEFAULT_ENV to get the current environment name. For example
$ source activate py36 $ echo $CONDA_DEFAULT_ENV py36
This is useful to activate a conda environment if it is not the current environment. See for example https://github.com/KamarajuKusumanchi/rutils/blob/master/bin/windows/python3
install a specific version of a package in an environment
conda install -n <env> <package>=<version>
For example
conda install -n py27 pandas=0.19.2
list available package versions
List all packages in the current environment
$ conda list # packages in environment at C:\ProgramData\Continuum\Anaconda\envs\numpy_issue: # # Name Version Build Channel certifi 2019.3.9 py27_0 numpy 1.16.4 pypi_0 pypi pip 19.1.1 py27_0 python 2.7.16 hcb6e200_0 setuptools 41.0.1 py27_0 sqlite 3.28.0 h0c8e037_0 vc 9 h7299396_1 vs2008_runtime 9.00.30729.1 hfaea7d5_1 wheel 0.33.4 py27_0 wincertstore 0.2 py27hf04cefb_0
Show the channel urls
$ conda list --show-channel-urls # packages in environment at C:\ProgramData\Continuum\Anaconda\envs\numpy_issue: # # Name Version Build Channel certifi 2019.3.9 py27_0 defaults numpy 1.16.4 pypi_0 pypi pip 19.1.1 py27_0 defaults python 2.7.16 hcb6e200_0 defaults setuptools 41.0.1 py27_0 defaults sqlite 3.28.0 h0c8e037_0 defaults vc 9 h7299396_1 defaults vs2008_runtime 9.00.30729.1 hfaea7d5_1 defaults wheel 0.33.4 py27_0 defaults wincertstore 0.2 py27hf04cefb_0 defaults
Related:
- conda search -f <package_name> - search packages available in Anaconda
path to python
The python used by an activated conda environment is ${CONDA_PREFIX}/bin/python
activate and deactivate environments
To activate environment foo
conda activate foo
To deactivate
conda deactivate
activate a conda environement if it is not already activated
current_env=$CONDA_DEFAULT_ENV # desired environment is set to py36. Change it as needed. desired_env=py36 if [[ $current_env != $desired_env ]]; then echo "setting environment to $desired_env" source activate $desired_env fi
In action | https://github.com/KamarajuKusumanchi/rutils/blob/master/bin/windows/python3
where is the package cache
conda info
tags | conda cache directory
Related commands:
conda clean --all --dry-run conda clean --packages --dry-run
Specifying version numbers
shows how to | specify minimum version in the environment file
Constraint type | Specification | Result |
---|---|---|
Fuzzy | numpy=1.11 | 1.11.0, 1.11.1, 1.11.2, 1.11.18 etc. |
Exact | numpy==1.11 | 1.11.0 |
Greater than or equal to | "numpy>=1.11" | 1.11.0 or higher |
OR | "numpy=1.11.1|1.11.3" |
1.11.1, 1.11.3 |
AND | "numpy>=1.8,<2" | 1.8, 1.9, not 2.0 |
Ref:- https://docs.conda.io/projects/conda/en/4.6.0/_downloads/52a95608c49671267e40c689e0bc00ca/conda-cheatsheet.pdf -> pg-2 -> "Specifying version numbers" section
sample environment file
name: sample_py36 channels: - conda-forge - defaults dependencies: - python=3.6.8 - pandas=0.24.1 - pip: - fastavro==0.21.18
file locations
- pep8 - /c/ProgramData/Anaconda3/Scripts/pep8.exe
- python interpreter - /c/ProgramData/Anaconda3/python
which package gives jupyter
jupyter
getting help
conda create --help
This command helped me to find out that '-p' is a shortcut for --prefix in the command 'conda env create -p PATH'.
useful links
- https://conda.io/docs/user-guide/getting-started.html
- using (Ana)conda within PyCharm - https://stackoverflow.com/questions/28390961/using-anaconda-within-pycharm
- cheatsheet - https://kapeli.com/cheat_sheets/Conda.docset/Contents/Resources/Documents/index
breaking changes
- Starting from conda 4.4.0, the 'root' environment is referred to as the 'base' environment.
Ref:- https://github.com/conda/conda/releases/tag/4.4.0 -> "Deprecations/Breaking Changes" section -> first point.
Anaconda channel vs defaults channel
The anaconda channel on anaconda.org is a mirror and is not the place to install packages from. The default channels/packages are hosted from repo.anaconda.com. So if a package such as prompt_toolkit is uploaded to the defaults channel, it will first show up in https://repo.anaconda.com/pkgs/main/noarch/ and then eventually in https://anaconda.org/anaconda/ .
Ref:-
- https://repo.anaconda.com/pkgs/ -> FAQ -> What about the 'anaconda' channel on anaconda.org at https://anaconda.org/anaconda?
- https://github.com/ContinuumIO/anaconda-issues/issues/11841
links:-
- https://repo.anaconda.com/pkgs/main/win-64/
- https://repo.anaconda.com/pkgs/main/noarch/
- https://repo.anaconda.com/pkgs/ - high level page
Anaconda
uninstall anaconda
useful links
- https://docs.anaconda.com/anaconda/install/linux/ - contains instructions to install Anaconda on Linux
- To download Anaconda for Linux - https://www.anaconda.com/distribution/#linux
- Hashes for Anaconda installer with Python 3 on 64-bit Linux - https://docs.anaconda.com/anaconda/install/hashes/lin-3-64/
- conda release notes - https://docs.conda.io/projects/conda/en/latest/release-notes.html
- Anaconda release notes - https://docs.anaconda.com/anaconda/reference/release-notes
- Download Anaconda - https://www.anaconda.com/download/
- Anaconda installer file hashes - https://docs.anaconda.com/anaconda/install/hashes/
- install miniconda - https://docs.conda.io/en/latest/miniconda.html
- miniconda installers - https://repo.anaconda.com/miniconda/ - contains latest, previous installers on all platforms.
- anaconda installers - https://repo.anaconda.com/archive/ - contains latest, previous installers on all platforms.
Troubleshooting
NoPackagesFoundError
I was getting
NoPackagesFoundError: Package missing in current linux-64 channels: - python 3.8*
on a system running:
% conda --version conda 4.3.22
I was able to fix the issue by removing the existing anaconda installation and installing the latest miniconda (Miniconda3-py37_4.8.2-Linux-x86_64.sh). For reference, I now have
% conda --version conda 4.8.
[Errno 13] Permission denied
If you get
[Errno 13] Permission denied: 'C:\\Path\\to\\libEGL.dll'
Close the git bash and relaunch it.
TypeError: '<' not supported between instances of 'NoneType' and 'str'
"conda env export --name foo" was giving the following error
TypeError: '<' not supported between instances of 'NoneType' and 'str'
I was able to fix it by upgrading conda from 4.6.14 to 4.9.1