You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The workaround to load environments is to run cmd.exe, load a conda environment, then run shell and save $PATH to a file. Then explicitly list all paths, and set CONDA_PREFIX. Then manually load this file via source. That works very well, can even do mamba install / uninstall.
~$ cmdMicrosoft Windows [Version 10.0.22631.4169](c) Microsoft Corporation. All rights reserved.C:\Users\ondrejcertik>AppData\Local\miniforge3\Scripts\activate.bat(base) C:\Users\ondrejcertik>bin\shell~$ echo $PATHC:\Users\ondrejcertik\AppData\Local\miniforge3;C:\Users\ondrejcertik\AppData\Local\miniforge3\Library\mingw-w64\bin;C:\Users\ondrejcertik\AppData\Local\miniforge3\Library\usr\bin;C:\Users\ondrejcertik\AppData\Local\miniforge3\Library\bin;C:\Users\ondrejcertik\AppData\Local\miniforge3\Scripts;C:\Users\ondrejcertik\AppData\Local\miniforge3\bin;C:\Users\ondrejcertik\AppData\Local\miniforge3\condabin;C:\Users\ondrejcertik\bin;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\Program Files\dotnet;C:\Program Files\Git\cmd;C:\Users\ondrejcertik\.cargo\bin;C:\Users\ondrejcertik\.pixi\bin;C:\Users\ondrejcertik\AppData\Local\Microsoft\WindowsApps;C:\Users\ondrejcertik\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\ondrejcertik\.dotnet\tools;C:\Users\ondrejcertik\AppData\Local\Programs\AzureAuth\0.8.4
Then we create a shell script ~/.shell-conda like this:
I have been using prefix-dev/shell on Windows for the last week, and it has been working quite nicely, thanks a lot for all the work on it! I see why conda activate does not work, but just as a feedback not being able to do conda activate is what I think is one of the main limitations in suggesting prefix-dev/shell to existing Windows users.
@traversaro I agree, we need a solution. I started using shell on all platforms, and this is the number one issue everywhere.
I got the conda working in the shell yesterday, but I am not on my Windows machine right now, but roughly I created a file ~/bin/activate_myst.bat, I have my ~/bin in my $PATH, and inside the file I have:
and I launch it simply by calling activate_myst. It works well. I have a similar script to activate MSVC.
I think we just need to ship these scripts.
Alternatively, I am not 100% sure what exactly "conda activate" does, but it might be as simple as setting a few environment variables, in which case we can figure out an equivalent solution for the shell.
Let's figure out how to get conda working, and the same approach will work for other such tools.
Conda is using the following bash script that gets sourced
__conda_activate() {
if [ -n"${CONDA_PS1_BACKUP:+x}" ];then# Handle transition from shell activated with conda <= 4.3 to a subseque
nt activation
# after conda updated to >= 4.4. See issue #6173.
PS1="$CONDA_PS1_BACKUP"\unset CONDA_PS1_BACKUP
fi\local ask_conda
ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix "$@")"||\return
\eval "$ask_conda"
__conda_hashr
}
One can also use shell.fish, shell.xonsh. There is also shell.cmd.exe but it doesn't seem to print anything on macOS.
To automate this, we need "aliases with arguments", so that I can make an alias as "alias conda_activate=miniforge3/bin/conda shell.posix activate $1 > /tmp/tmp.sh && source /tmp/tmp.sh". However, it seems that in Bash one uses functions for that. So we might need to implement functions after all (#207). The tricky part is the "source" at the end, which forces us to do this programming in the shell itself. The alternative would be to implement some magics in the shell that would allow 3rd party programs (say in Python) to leave around the above tmp.sh file which the shell would then source afterwards automatically on some signal (error code?). Then we can implement a simple Python or Rust script to extract what needs to happen from conda, and leave around the tmp.sh file.
@traversaro I figured it out on both macOS and Windows, screenshots here: conda-incubator/conda-spawn#9 (comment). I am using conda spawn -n lf and it just works on both platforms in the shell. You must put export SHELL=shell into your ~/.shellrc.
Discovered one blocker: if your environment has certain packages, such as gfortran on macOS, then it is executing complicated Bash scripts that we do not support yet with shell. To fix it, we need to call Bash itself, and extract the environment changes and apply them, or launch the shell from Bash. I created a dedicated issue for this at #221.
Activity
certik commentedon Sep 9, 2024
I can launch
cmd
, activate conda, load anlf
environment, then launch shell. This is the$PATH
:vim
from Pixi does not work anymore, I suspect it segfault but I can't see it due to #89.This is the path in the top-most shell without conda:
This can then be enabled via #90 (comment) and #94 (comment).
certik commentedon Sep 11, 2024
The workaround to load environments is to run
cmd.exe
, load a conda environment, then run shell and save$PATH
to a file. Then explicitly list all paths, and setCONDA_PREFIX
. Then manually load this file viasource
. That works very well, can even domamba install / uninstall
.certik commentedon Sep 15, 2024
Specifically:
Then we create a shell script
~/.shell-conda
like this:And source it like:
In order to make such "path" update scripts additive, we need to fix #130 first.
certik commentedon Oct 2, 2024
Here is a workaround how to get conda working in the shell: #69 (comment).
certik commentedon Jan 16, 2025
On macOS, here is how to activate a conda environment using
zsh
:traversaro commentedon Jan 17, 2025
I have been using
prefix-dev/shell
on Windows for the last week, and it has been working quite nicely, thanks a lot for all the work on it! I see whyconda activate
does not work, but just as a feedback not being able to doconda activate
is what I think is one of the main limitations in suggestingprefix-dev/shell
to existing Windows users.fyi @S-Dafarra
certik commentedon Jan 18, 2025
@traversaro I agree, we need a solution. I started using
shell
on all platforms, and this is the number one issue everywhere.I got the conda working in the shell yesterday, but I am not on my Windows machine right now, but roughly I created a file
~/bin/activate_myst.bat
, I have my~/bin
in my$PATH
, and inside the file I have:and I launch it simply by calling
activate_myst
. It works well. I have a similar script to activate MSVC.I think we just need to ship these scripts.
Alternatively, I am not 100% sure what exactly "conda activate" does, but it might be as simple as setting a few environment variables, in which case we can figure out an equivalent solution for the shell.
certik commentedon Jan 19, 2025
Let's figure out how to get conda working, and the same approach will work for other such tools.
Conda is using the following bash script that gets sourced
This effectively just does the following:
We can now set it into a variable:
But there is a bug that it concatenates the lines. Another issue is that we don't have an
eval
yet.So as a workaround for both of these bugs we can do:
$ miniforge3/bin/conda shell.posix activate lf > /tmp/tmp.sh && source /tmp/tmp.sh
That seems to do the trick! It works for me.
The prompt does not update, since we don't support the PS1 mechanism yet, but everything else seems to work.
To deactivate, follow the same approach:
$ conda shell.posix deactivate > /tmp/tmp.sh && source /tmp/tmp.sh
On Windows we need to see if
shell.posix
sets the Windows paths correctly. If not, we either have to postprocess the paths, or extract them from:One can also use
shell.fish
,shell.xonsh
. There is alsoshell.cmd.exe
but it doesn't seem to print anything on macOS.To automate this, we need "aliases with arguments", so that I can make an alias as "alias conda_activate=miniforge3/bin/conda shell.posix activate $1 > /tmp/tmp.sh && source /tmp/tmp.sh". However, it seems that in Bash one uses functions for that. So we might need to implement functions after all (#207). The tricky part is the "source" at the end, which forces us to do this programming in the shell itself. The alternative would be to implement some magics in the
shell
that would allow 3rd party programs (say in Python) to leave around the abovetmp.sh
file which the shell would then source afterwards automatically on some signal (error code?). Then we can implement a simple Python or Rust script to extract what needs to happen from conda, and leave around thetmp.sh
file.@wolfv, @prsabahrami any ideas what we should do?
certik commentedon Jan 22, 2025
Ok, here is the best way so far that I got working, only tested on macOS so far: conda-incubator/conda-spawn#9 (comment). Works like a charm!
certik commentedon Jan 22, 2025
@traversaro I figured it out on both macOS and Windows, screenshots here: conda-incubator/conda-spawn#9 (comment). I am using
conda spawn -n lf
and it just works on both platforms in the shell. You must putexport SHELL=shell
into your~/.shellrc
.certik commentedon Jan 30, 2025
Things are greatly simplified now. Setup:
Merge these PRs (check them out, install them into your
base
conda environment):Hopefully they'll get merged upstream soon.
On Windows put this into your
~/bin
:Then:
Notice the automatic prompt modification with the environment name, etc. Everything just works.
You can also launch programs directly from the environment:
~/repos/conda-spawn(shell)$ conda spawn myst -- myst --help
certik commentedon Feb 4, 2025
Discovered one blocker: if your environment has certain packages, such as
gfortran
on macOS, then it is executing complicated Bash scripts that we do not support yet with shell. To fix it, we need to call Bash itself, and extract the environment changes and apply them, or launch the shell from Bash. I created a dedicated issue for this at #221.