Daily Tips - Manage your Environment with conda/mamba 🐍

Hi there,

Some crap.

I’m writing this post because I see two typical groups of people active in the forum with different preferences, that are data workers and developers, who work in different environments. Today I want to talk about package managers.

As you know, there are two types of package managers, one is pip and the other is conda, and it goes without saying that developers love pip and data workers love conda. (I group pip and related environment and dependency managers in one category. Because my focus is not on the tools themselves, but how they are used.) Actually, they represent two different ideas. As a developer, of course, I hope that my project is pure and free of useless dependencies, then I will orient to the project to prepare dependencies and manage the environment, which is very suitable for using pip. On the other hand, as a data worker, I face specific problems, and I may have several toolboxes at hand to deal with different problems. And I don’t mind having an extra screwdriver in the toolbox just in case.

Funny that they don’t seem to understand each other very well. I just made two PR to advise developers to pay attention to conda support. And what they first thought was to support poetry. You know, that’s a scaffolding tool like cookiecutter. What? Let people be engineers before using Dash? In fact, Dash also didn’t pay attention to this issue in the first place. So you can now see ‘Dash Enterprise support Conda’ prominently on their website. I guess there must be a story. In fact, the plotly team has done a lot of work on multilingual support, but they seem to ignore that there is a tool that can manage multiple languages ​​at the same time. On the other hand, a couple of posts popped up two weeks ago saying they all hit a bug. It’s actually just a simple dependency conflict issue, and they’re all using pip. I can’t ask them all to have enough development knowledge, otherwise solving that problem will be less effort than posting for help.

You can easily find a summary of the differences between these two types of package managers somewhere. In short, the ideas are different as mentioned above so that their dependency and package management strategies are different. All pip does is help you build Python software. Conda helps you solve problems, everything from C to R can be dependencies.

Conda was originally released with out-of-the-box software Anaconda, and it quickly became popular with data scientists, analysts, and other data workers. Given that’s commercial software, I’m going to skip it.

We now have miniforge and mambaforge, which are the efforts to provide Anaconda-like installers by conda-forge. And we also pull the libraries from their channel. There is also a new version of the package manager called mamba, which is much faster than conda. I used mamba here, which I learned from dask.

Conda has a built-in environment manager, and we usually deploy a new environment like this.

mamba create --name my_env_py310 python=3.10

Switch environment.

mamba activate my_env_py39

View environment.

mamba info --envs

View packages.

mamba list -n my_env_py39

Query package information.

mamba search dash

Install a package.

mamba install nodejs
mamba install dash=2.3.1

Update packages.

mamba update dash
mamba update --all -n my_env_py39

Delete a package.

mamba remove yapf

Delete an environment.

mamba remove -n my_env_py39 --all

Specify the channel.

mamba install -c conda-forge dash
mamba install -c conda-forge/label/gcc7 dash
mamba install -c conda-forge/label/cf201901 dash
mamba install -c conda-forge/label/cf202003 dash

Or edit the ~/.condarc file.

channel_priority: strict
channels:
  - conda-forge
  - defaults

Environment moves.

mamba list --explicit > spec-list.txt
mamba create  --name my_env --file spec-list.txt
mamba env export > environment.yml
mamba env create -f environment.yml

Users using zsh or others may require:

mamba init zsh
mamba init fish
mamba init powershell





Hope you like this. XD

Keywords: Anaconda, Conda, Mamba, Conda-forge, Pip, Environment, Interpreter

Other Daily Tips series:
Daily Tips - If I have a Bunch of Triggers
Daily Tips - Share the Function
Daily Tips - How many Ways to share Dash in a company?
Daily Tips - Give your Component a Name
Daily Tips - Share Dash to Social Media
Daily Tips - Double-click to open Dash
Daily Tips - What rows of data have I modified?
Daily Tips - Write the Simplest Client-side Callback
Daily Tips - Some simple Expressions
Daily Tips - IoT? Real Real-time Data and Live Update
Daily Tips - Which formatter is your favorite?
Daily Tips - Convert a React Component to Dash
Daily Tips - Real-time Logs on Dash
Daily Tips - Control Permissions Precisely

2 Likes