Doing things with conda environments

python
conda
Author

Teresa Kubacka

Published

October 8, 2022

Update the Python version

It’s scary, but needs to be done sometimes (e.g. when you have a perfectly working old environment built on Python 3.6, but then one dependency stops behaving and requires P3.8+).

If in a conda environment:

conda activate my_env
conda install -c anaconda python=<version>

src

Clone an environment

If you want to make a clone of the environment for a backup purpose:

conda create --name <target_environment> --clone <source_environment> 

If you want to clone the base:

conda create --name <myenv> --clone base

Solve the libarchive error

https://github.com/ContinuumIO/anaconda-issues/issues/11104#issuecomment-510285329

  • install miniconda to a separate folder. Tell it not to run conda init
  • activate that installation with source /path/to/new/miniconda/bin/activate
  • run conda install -p /path/to/broken/anaconda –force python-libarchive-c conda-package-handling libarchive

Similar here: https://github.com/conda/conda/issues/7714#issuecomment-417553149

Install packages when creating environment

Packages can be defined at env creation, which supposedly helps with resolving conflicts

Basics

List environments:

conda info --envs 

Install ipykernel pointing to a venv:

pip install ipykernel 
python -m ipykernel install --name my_venv