prefix-dev / shell

The ultimate cross-platform, bash-like shell
MIT License
36 stars 8 forks source link

Figure out how to enable Conda environments inside the shell #36

Open certik opened 2 weeks ago

certik commented 2 weeks ago

At first at least some workaround to be able to load an environment.

certik commented 1 week ago

I can launch cmd, activate conda, load an lf environment, then launch shell. This is the $PATH:

C:\Users\ondrejcertik\AppData\Local\miniforge3\envs\lf;
C:\Users\ondrejcertik\AppData\Local\miniforge3\envs\lf\Library\mingw-w64\bin;
C:\Users\ondrejcertik\AppData\Local\miniforge3\envs\lf\Library\usr\bin;
C:\Users\ondrejcertik\AppData\Local\miniforge3\envs\lf\Library\bin;
C:\Users\ondrejcertik\AppData\Local\miniforge3\envs\lf\Scripts;
C:\Users\ondrejcertik\AppData\Local\miniforge3\envs\lf\bin;
C:\Users\ondrejcertik\AppData\Local\miniforge3\condabin;
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

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:

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

This can then be enabled via https://github.com/prefix-dev/shell/issues/90#issuecomment-2338891209 and https://github.com/prefix-dev/shell/issues/94#issue-2514710177.

certik commented 1 week ago

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.

certik commented 5 days ago

Specifically:

~$ cmd
Microsoft 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 $PATH
C:\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:

export PATH='C:\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\tool%;C:\Users\ondrejcertik\AppData\Local\Programs\AzureAuth\0.8.4'

And source it like:

source ~/.shell-conda

In order to make such "path" update scripts additive, we need to fix https://github.com/prefix-dev/shell/issues/130 first.