Ana/Mini/Conda
or “How to completely wipe and reinstall your complete
scientific Python stack in under 5 minutes” (if you have to)
K.-Michael Aye
Scripts at this gist OpenPlanetary virtual lunch, 2020-03-31
Conda vs Anaconda vs
Miniconda
• Questions to audience:
• How many here use any conda-based system?
• How many understand the differences between the
different conda terms in the title of this slide?
• Before we expunge/reinstall, let’s understand it
better.
Conda vs Anaconda vs Miniconda (2)
Miniconda is a minimal set of
packages, to be expanded
… Metapackage
by the advanced user. Anaconda
…
Miniconda
… dependencies
Tool manages all
conda spiceypy matplotlib
of packages
some dependency
basic
packages
numpy
Standard conda package (grey)
Conda also manages virtual envs
•If you only ever need one environment, you could stay
with graphical Conda installer, however…
conda create -n py37 python=3.7 spiceypy matplotlib numpy
Legacy Python:
spiceypy py37 conda create -n py2 python=2
python2_package
matplotlib
…and all
packages
required Use “conda activate <env-name>”
numpy for these. to switch between environments.
My python package search tree
• First conda: conda install <pkg_name>
• The dependency resolver will tell if it would lead to downgrades of other packages,
you can inspect and reject at this point.
• What if a Python package is not available conda?
• pip install pkg_name
• NOTE: Always do conda activate <env_name> before this (or anything
really). Because otherwise a different “pip” command might be used on your
computer and install goes somewhere else.
• Pip ALWAYS depends on current active conda environment (or PATH if no conda)
• If you ever did “pip install” and then Python couldn’t find it, it didn’t install where
you think it did.
• What if pkg not even on Pypi server? Find it on GitHub:
• git clone <url_copied_from_GitHub && cd <cloned_repo> && pip install (-e) .
• I use this mix for many years successfully.
Conda vs Anaconda vs
Miniconda (3)
• So, in summary:
• conda is the executable that manages packages (not only Python,
e.g. HDF binaries, FORTRAN, OpenCV, GDAL libraries etc.)
• “miniconda” is a minimum set of packages for proper operation of
conda, installed into a “base”. Use this if you understand conda
well.
• “anaconda” is a meta-package with a huge list of scientific
packages (dependencies) (Recommended for beginners)
• Hence: after installing miniconda and executing “conda install
anaconda”, you would have the same python env as
somebody that DL-ed the Anaconda distribution.
Everyday conda (terminal) tips
• If you have installed it before, and it’s older than conda 4.6, remove and reinstall everything.
• New version (now at 4.8.x) is much faster in adding a new package
• Too many changes that make it better to delete “old cruft”
• If you still have changed PATH changes that point to your conda install in your ba/c/tc-sh configs,
remove it!
• Call of “conda init <shell_name>” configures things correctly, adding an init section to config files.
• Leaving the manual PATH change in can create problems.
• Advise: Don’t use the initial conda “base” environment for general work.
• Eventually some of your installs (or Anaconda, Inc.) will mess up something.
• Always create a new default environment:
• conda create -n py37 python=3.7
• conda activate py37
• Find packages:
• conda search <package_name>
• If list shows what you need:
• conda install <package_name> (will also drag in dependencies)
Conda channels
• Channels are different
locations/sources for
packages.
• By default, an env is
pointed to the default
channel, you can confirm
like so:
• The top-most channel has
the highest priority for
package searches.
Conda channels (2)
• What if you want to have one environment pointing
to defaults and one to try out conda-forge?
• -> ENV-dependent configuration!
• Activate the env you want to configure, then:
• conda config --env --add channels conda-forge
• Good tip: Don’t mix channels within one env. And
pin packages to be sure.
Pinning packages
• Because conda sometimes finds “better” packages
at default, conda did sometimes mix from different
channels.
• To avoid this (catastrophic for gdal), pin packages
per env to your desired channel:
• conda config --env --add pinned_packages
conda-forge::gdal
nb_conda_kernels
• JNotebook: find menu “Kernel-
• If you are working mostly >change kernel”
• JLab: click on kernel name in the
in Jupyter and (anticipate upper right
to) have more than one
conda env, this is the
most important conda
package.
• It finds your existing
conda envs at every
launch of a Jupyter
server
• It then offers kernel for
each conda env in the list
How to reinstall env in 5 min
• Even a “stable” env is rotting at some point
• The trick is to have:
• File with a list of your conda packages
• File with a list of your pip packages
• If you develop new packages: file with a list of your
own package folders and GH installs
• a (couple of) bash script(s)
How to reinstall env in 5 min(2)
• conda deactivate
• ./reinstall_env.sh py37 3.7
• conda activate py37
• ./install_my_libs.sh