Conda/Mamba #
Warning: This post hasn't been updated for over a year. The information may be out of date.
References:
Managing Environments #
Toggling channel priority:
# see the current setting
$ conda config --describe channel_priority
# set to flexible if environment conflict just won't resolve
$ conda config --set channel_priority flexible
# set to strict if feeling lucky
$ conda config --set channel_priority strictCreate an environment from file:
$ conda env create --file environment.yml
$ conda env create -f environment.ymlUpdate an environment:
$ conda env updateDelete an environment:
$ conda remove --name my-env --all --yes
$ conda remove -n my-env --all -yManage Jupyter Notebook Installation #
dependencies:
- ipykernel
# If need Jupyter Lab
- jupyterlab
# If need extensions
- jupyter_contrib_nbextensions
… (List of extensions that need installation)Managing Packages #
Check Package Version #
$ conda list --full-name <package-name>Force Re-installation #
First, deactivate the current environment and activate again.
If that doesn’t work:
$ conda install --force-reinstall <a-bad-package>If that doesn’t work:
- Open conda’s package directories. (example: Miniconda)
- Check:
conda info /opt/miniconda3/pkgs//opt/miniconda3/envs/my-env/lib/python3.7/site-packages/
- Check:
- Remove the package.
- Run
conda env update.
If that doesn’t work:
- Switch to base environment or run
conda deactivate - Delete
my-envwithconda remove -n my-env --all -y - Create it again with
conda env create -f environment.yml
Magic commands #
Doc: Built-in magic commands — IPython 8.21.0 documentation
System commands #
# Prints current working directory
%pwdShow function definition #
Ref: Can Python print a function definition? - Stack Overflow
# help
function_name?
# definition
function_name??Use with direnv #
Auto activate environment #
.envrc:
cd /usr/local/Caskroom/miniconda/base/bin
source activate myenv
cd -Use local package #
.envrc:
export PROJECT_ROOT=$PWD
export PYTHONPATH=$PROJECT_ROOT:$PYTHONPATH # prioritise local packagesThe environment directory must look like this:
.
├── .envrc
├── environment.yml
├── my_package
│ ├── __init__.py
│ └── ...
└── ...