CondaPkg - acitvate environment

I am using CondaPkg and installed two Python packages. After installation I get the message:

To activate this environment, use:

    micromamba activate /home/ufechner/repos/Tethers.jl/.CondaPkg/env

But that does not work, if I try it I get the error:

micromamba: command not found

This works:

using CondaPkg
CondaPkg.withenv() do
    run(`python src/Tether_01.py`)
end

Is it possible to activate this conda environment and run a python script in it WITHOUT starting Julia first?

That’s likely an error from micromamba itself, and you do have it, just not in your path.

CondaPkg.jl depends on it i.e. MicroMamba.jl depending on which likely provides it:

Here might be a clue how to use it/where it’s stored:
https://github.com/search?q=repo%3AJuliaPy%2FMicroMamba.jl micromamba&type=code

micromamba is an implementation detail, a clone of conda program, should be invisible detail I think, so I’m not sure why you’re getting the error. Maybe it shouldn’t happen?

As @Palli said, you must have it installed, so the simplest solution (workaround) is to provide the full file path to where ever micromamba is stored, which is going to be in ~/.julia somewhere. It looks like you’re on Linux, so maybe do a locate or find?

One thing I like to do with my conda envs is add an alias so I don’t have to type conda activate all the time. So you could do something similar when you find the binary. Just add some version of this to your .bashrc file

alias my_env='micromamba activate /path/to/micromamba'

MicroMamba.jl depends on micromamba_jll

https://juliahub.com/ui/Packages/JuliaBinaryWrappers/micromamba_jll

The JLL should have a Cmd to run micromamba.

OK, I did: locate micromamba and found the path.
I then created a link:

cd .local/bin
ln -s /home/ufechner/.julia/artifacts/87052ac9aec71548f804b30280151288cb1ed40e/bin/micromamba

Now I can run micromamba, and can activate my environment, but there are still issues when using ipython3 . Well I guess I need to read some more of the micromamba documentation.

1 Like

You can get the path to micromamba with MicroMamba.executable(). Micromamba is totally self contained so you can copy/link this to somewhere in your PATH.

Though for interactive usage I’d probably recommend installing Mamba instead via the MiniForge distribution: GitHub - conda-forge/miniforge: A conda-forge distribution.. Conda/Mamba/MicroMamba environments are all the same so you can mix and match tools.

2 Likes

Summary:
To use the Python environment that you have installed with CondaPkg the following
steps are needed:

  1. find the path to the micromamba exectable:
using CondaPkg
CondaPkg.MicroMamba.executable()
  1. create a link in ./local/bin
cd .local/bin
ln -s <PATH>
  1. initalize the shell
micromamba shell init --shell bash --root-prefix=~/micromamba
  1. activate the environment
micromamba activate /home/ufechner/repos/Tethers.jl/.CondaPkg/env

I used CondPkg to add ipython:

using CondaPkg
]
conda add ipython

I can run now ipython and interactively debug Python scripts. In VSCode I activated the
interpreter .CondaPkg/env/bin/python, so syntax highlighting etc works also fine.

2 Likes