Setting up Python-Env – mamba [b]eats conda

Mamba aka Miniforge was a package for (and now a spin-off of) Anaconda, intended for a faster environment resolution. In general mamba is [currently] more efficient than conda, esp. if you rely on conda-forge, a community-led anaconda channel

In previous post I have shown how to install The SoS Jupyter in Conda with R4, Python38, Tensorflow and Spyder. The main challenge was to find out the suitable package versions (what conda is, in theory, intended for ... in practice, however, it was only possible by iterative analysis of error messages).
Moreover, the recipe given in the previous post is not always reproducible: sometimes anaconda just hangs, trying to resolve the flexible configuration.

Contrary, mamba works pretty fast and automatically correctly resolves the dependencies (well, with an exception of numpy version, s. below).
So to install the configuration, described in previous post, just run for Python3.8
conda create -n tf210juso38 python=3.8 tensorflow Spyder jupyter jupyterlab-sos sos-notebook sos-python jsonschema-with-format-nongpl r-base r-devtools r-reticulate sos-rmarkdown r-tidyquant -c conda-forge
and for Python3.9
conda create -n tf210juso39 python=3.9 tensorflow Spyder jupyter jupyterlab-sos sos-notebook sos-python jsonschema-with-format-nongpl r-base r-devtools r-reticulate sos-rmarkdown r-tidyquant -c conda-forge

In Linux, it shall straightforwardly work with the tensorflow-gpu (just replace tensorflow with tensorflow-gpu in conda command) but for windows it does not work [on 21.01.2024].
As a matter of fact conda-forge enthusiasts did build the tensorflow-gpu version upto 2.14 for Linux but for whatever reason the latest version for windows is so far tensorflow-gpu 2.6.0
(Remark: according to this the support for the [native] Windows tensorflow-gpu is stopped, 2.10 is the last available release).

Moreover, on the one hand this version seems to require the numpy version>1.20, on the other hand, it throws a [not so] well-known message, which is due to the depreciation np.object alias in numpy>1.20

The problem here turns out to be a bit complex. First, even mamba does not correctly resolve the numpy version, so you need to specify numpy=1.21 explicitely.
Further, the tensorflow 2.3 build on conda-forge is flawed, so you need to specify the cudatoolkit and cudnn (normally, the dependence on them shall be resolved automatically) and finally (s. below) overwrite the tensorflow build.

So run
conda create -n tfgpu23 python=3.8 numpy=1.21 cudatoolkit=10.1 cudnn=7.6 tensorflow-gpu Spyder jupyter jupyterlab-sos sos-notebook sos-python jsonschema-with-format-nongpl r-base r-devtools r-reticulate sos-rmarkdown r-tidyquant -c conda-forge

You should get something

like this

As the last step run
conda install tensorflow-gpu=2.3 tensorflow=2.3=mkl_py38h1fcfbd6_0 (courtesy stackoverflow).

Spoiler

Well, tensorflow-gpu=2.3.0 is a rather old version but better than nothing.
However, there is another unpleasant surprise: some functionaly of tensorflow 2.3 may not function with numpy=1.21 ... so you need to downgrade numpy to 1.19.5 ... in this case you will not be able to use sos-notebook but Spyder remains...
hey, conda-forge guys, would you be so nice to catch-up with tensorflow-gpu 2.10 release for windows?!


P.S.
Note that if mamba cannot resolve the dependency chain, it returns a readable summary of package conflicts. It a big contrast to conda, which normally just hangs.

P.P.S.
In past one installed mamba into the base env of conda like

conda config --add channels conda-forge
conda update -n base --all
conda install -n base mamba

but nowadays it is an obsolete way, since conda and mamba do not co-exist well in a shared terrarium. So you should install mamba separately, you can download the latest distributive from the miniforge github page.

Like this post and wanna learn more? Have a look at Knowledge rather than Hope: A Book for Retail Investors and Mathematical Finance Students

FinViz - an advanced stock screener (both for technical and fundamental traders)