Anaconda / MambaForge

I didn’t really understand anaconda deeply, but I like it now. It’s basically combining virtualenv + pyenv into 1 thing.

The thing is, some libraries really really recommend using conda as it makes your life “easier”, like conda install tensorflow-gpu.

  • I now prefer using conda through mambaforge (micromamba), because it is faster, and I use the conda command by setting up an alias

pip vs. conda?

The age old question. Anaconda wrote an article themselves, which you should read to understand the differences.

But I kind of get it now! Pip installs Python packages whereas conda installs packages which may contain software written in any language

Conda is also better because it uses a satisfiability (SAT) solver to verify that all requirements of all packages installed in an environment are met.

Create an environment

conda create --name $ENVIRONMENT_NAME python=3.10

Example

conda create --name ros2_humble python=3.10

Locally

conda create --prefix ./conda python=3.8

DANGER

Make sure to pass python into the conda create, don’t just create the environment name alone. Else it’s not going to install anything, and it will use the the global python environment.

In VSCode

In VSCode, you can create the environment by doing Command + Shift + P and then Python: Create Environment... Source. Though I would argue that it is still important to know the raw commands.

Activate an environment

source activate $ENVIRONMENT_NAME
  • conda actiate works in conda 4.6 and later versions

Deactivate an environment

conda deactivate

List installed packages

conda list

# List for a particular environment
conda list --name $ENVIRONMENT_NAME

List all environments

conda info --envs

Delete an environment

conda remove -n ENV_NAME --all

Switch to mamba

I recently switched to mamba, which is basically the same as conda, but faster and a few more features, because I wanted to install ROS on Mac, and the people at Robostack enabled this direct installation https://robostack.github.io/GettingStarted.html.

You can install mamba after installing conda, but it is very buggy. I just removed my miniconda installation, and installed from here https://github.com/conda-forge/miniforge#mambaforge

There are lots of different terms, it is important to know all of the differences.

Conda-forge

What is conda-forge?

Conda packages are maintained by Anaconda, Inc., while Conda-Forge packages are maintained by the community: https://conda-forge.org/.

  • Sometimes, you can’t directly do conda install, so you do conda install mamba -c conda-forge

Miniconda vs. conda?

Miniconda vs. miniforge?

https://stackoverflow.com/questions/60532678/what-is-the-difference-between-miniconda-and-miniforge

So how does Anaconda ACTUALLY work?

So how does Anaconda mix the pip and conda packages?

Turns out, they are put inside the same folder:

 which pip3
/Users/stevengong/miniconda3/bin/pip3
 
 pip3 list -v
Package                                           Version     Location                                                  Installer
 
------------------------------------------------- ----------- --------------------------------------------------------- ---------
 
aiohttp                                           3.8.4       /Users/stevengong/miniconda3/lib/python3.10/site-packages pip
 
aiosignal                                         1.3.1       /Users/stevengong/miniconda3/lib/python3.10/site-packages pip
 
appnope                                           0.1.3       /Users/stevengong/miniconda3/lib/python3.10/site-packages conda

My issue was that I activate the conda environment, but i still have access to all these other libraries??? Like what is the point.

I never took the time to understand this, like why is that happening?

So yea, from what I remember from virtualenv, the packages just get installed at the level of the project. But that is not the case with conda?

but then, if you can just conda install, you don’t need brew anymore?

Ahhh, I see. So conda works a lot differently than virtualenv. What virtualenv does is create a venv/ folder, but with conda, all of these environments are created at a specific folder:

testenv                  /Users/stevengong/miniconda3/envs/testenv

So it doesn’t matter where you run source activate testenv.

No, that is partially true: You can control where a conda environment lives by providing a path to a target directory when creating the environment

conda create --prefix ./envs jupyterlab=3.2 matplotlib=3.5 numpy=1.21

Warning

There are a few things to be aware of when placing conda environments outside of the default envs folder.

  1. Conda can no longer find your environment with the --name flag. You’ll generally need to pass the --prefix flag along with the environment’s full path to find the environment.
  2. Specifying an install path when creating your conda environments makes it so that your command prompt is now prefixed with the active environment’s absolute path rather than the environment’s name.

Okay, but I am still confused, when I do pip install, it installs at the global directory.

Ahhh, you gotta do conda install pip first.

Mamba / MambaForge

https://github.com/mamba-org/mamba https://mamba.readthedocs.io/en/latest/

What is mamba?

mamba is a reimplementation of the conda package manager in C++, but FASTER.

I now use mamba:

 where conda
...
/Users/stevengong/mambaforge/condabin/conda
 where mamba
...
/Users/stevengong/mambaforge/condabin/mamba

mamba is a drop-in replacement and uses the same commands and configuration options as conda.

Usage

mamba create -n ros_env
mamba activate ros_env

Conda Inside Docker

https://fabiorosado.dev/blog/install-conda-in-docker/