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 theconda
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.
- https://docs.conda.io/projects/conda/en/latest/commands/index.html (conda commands)
- Conda Environments
- Managing Environments(lots of useful knowledge)
Create an environment
conda create --name $ENVIRONMENT_NAME python=3.10
Example
conda create --name ros2_humble python=3.10
conda create --name pangolin python=3.8
Locally
DANGER
Make sure to pass
python
into theconda 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 thenPython: 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
Delete an environment
conda remove -n ENV_NAME --all
Switch to
mamba
I recently switched to
mamba
, which is basically the same asconda
, 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 installingconda
, but it is very buggy. I just removed myminiconda
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 doconda 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:
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?
- Conda Environments
- Managing Environments(lots of useful knowledge)
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.
- 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.- 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:
mamba
is a drop-in replacement and uses the same commands and configuration options as conda
.
Usage
mamba activate ros_env