===== Conda ===== .. program:: conda During installation (Anaconda), *conda* creates a generic environment called ``base`` which is activated by default. Therefore, when installing a package with ``conda install``, the package will be installed in that environment. .. prompt:: bash conda activate your_env .. prompt:: bash conda deactivate To have a full in depth introduction to environment management with conda read the official documentation: `Manage Environments `_. .. contents:: :local: Channels ======== To see the configured channels use the command ``conda info``. The defaults channel points to several channels at the `repo.anaconda.com `_ repository. .. list-table:: Defaults channels (https://repo.anaconda.com/pkgs/) :widths: auto :header-rows: 0 :stub-columns: 1 * - pkgs/main - Includes packages built by Anaconda, Inc. with the new compiler stack * - pkgs/msys2 - Windows only. Included in conda's defaults channel. Necessary for Anaconda, Inc.'s R conda packages and some others in pkgs/main and pkgs/free * - pkgs/r - Microsoft R Open conda packages and Anaconda, Inc.'s R conda packages. .. list-table:: Other channels :widths: auto :header-rows: 0 :stub-columns: 1 * - conda-forge - A community repository that provides conda packages for a wide range of software. (`more channel info `_) * - anaconda - A mirror of the packages available in main, free, and pro hosted on repo.anaconda.com Common commands =============== .. option:: search Search a package within the configured channels. .. option:: install Install a package. Use ``-c`` to specify a particular channel, e.g. ``conda install -c conda-forge ``. .. option:: env list List conda environments .. option:: list List installed packages in the current environment. Use ``-n`` to specify a particular environment. .. option:: info Print some information about conda. Example: .. code-block:: text active environment : None user config file : C:\Users\user.name\.condarc populated config files : C:\Users\user.name\.condarc conda version : 4.8.4 conda-build version : 3.18.11 python version : 3.8.3.final.0 virtual packages : __cuda=10.2 base environment : C:\ProgramData\Anaconda3 (read only) channel URLs : https://repo.anaconda.com/pkgs/main/win-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/win-64 https://repo.anaconda.com/pkgs/r/noarch https://repo.anaconda.com/pkgs/msys2/win-64 https://repo.anaconda.com/pkgs/msys2/noarch package cache : C:\ProgramData\Anaconda3\pkgs C:\Users\user.name\.conda\pkgs C:\Users\user.name\AppData\Local\conda\conda\pkgs envs directories : C:\Users\user.name\.conda\envs C:\ProgramData\Anaconda3\envs C:\Users\user.name\AppData\Local\conda\conda\envs platform : win-64 user-agent : conda/4.8.4 requests/2.24.0 CPython/3.8.3 Windows/10 Windows/10.0.17134 administrator : False netrc file : None offline mode : False .. option:: pip freeze | cut -d "@" -f1 | xargs pip uninstall -y Uninstall all pip packages Configuration ============= Official docs about conda configuration: `Configuration User-Guide `_ Conda configuration is stored in ``.condarc`` which is usually in your home directory. If that file isn't present, you can either create it manually or run ``conda config`` a first time to generate it. You can either edit it manually, or use the command bellow to set parameters: .. prompt:: bash conda config --add channels conda-forgeaaaaaa .. option:: config --get Get all configuration keys and values Useful configuration -------------------- If you have a very fast SSD, you might increase the number of threads to shorten the time it takes for conda to create environments and install/remove packages (`More config info `_). .. prompt:: bash conda config --set default_threads 6 Add ``conda-forge`` channel but with lowest priority: .. prompt:: bash conda config --append channels conda-forge As of version 4.6.0, Conda has a strict channel priority feature. Strict channel priority can dramatically speed up conda operations and also reduce package incompatibility problems. .. prompt:: bash conda config --set channel_priority strict Your ``.condarc`` file should looks like this: .. code-block:: txt ssl_verify: true channels: - defaults - conda-forge default_threads: 6 channel_priority: strict Export an environment for sharing ================================= .. prompt:: bash conda env export > environment.yml The newly created ``environment.yml`` file contains all packages installed within the current environment. The file contains the parameter ``prefix`` at the end of the file which points to your local installation. This information can be ignored or removed from the file without any impact when creating a new environment on a different machine. .. important:: The command ``conda list --export > req.txt`` is not recommanded to be used to export an environment because if a package have been installed from a different channel than the default one, conda is unable to find that package when installing the environment with ``conda create --name myenv --file req.txt``. Create an environment from file =============================== .. prompt:: bash conda env create -f condaenv.yml If you don't specify a name for the new environment with ``-n myenv``, the name configured in the ``.yml`` will be used. Update an environment from file =============================== .. prompt:: bash conda env update -f condaenv.yml Without activating the environment use ``--n myenv``. Show conda environments in Jupyter notebook/lab =============================================== If you want all your conda environments to be listed in Jupyter notebook and lab, make sure you've installed the packages ``ipykernel`` and ``nb_conda_kernels`` in the environment from which you run Jupyter. .. prompt:: bash conda install -n myenv ipykernel nb_conda_kernels Howerver, with many environments installed the view can gets messy: .. figure:: img/jupyterlab_show_envs.png It is recommanded to add the kernel manually and give an explicit name. To do so, while in the environment, run the following command: .. prompt:: bash python -m ipykernel install --user --name=myenv Rename an environment ===================== You can't! You need to clone the environment and give a new name: .. prompt:: bash conda create --name new_name --clone old_name conda remove --name old_name --all Delete an environment ===================== Ooh poor environment :( .. prompt:: bash conda env remove --name myenv Packages installation revisions =============================== Show all revisions: .. prompt:: bash conda list --revisions Revert back to a specific revision: .. prompt:: bash conda install --revisions N where N is the revision number :tag:`Python` :tag:`Conda` :tag:`Tool`