mamba-org / mamba

The Fast Cross-Platform Package Manager
https://mamba.readthedocs.io
BSD 3-Clause "New" or "Revised" License
6.84k stars 353 forks source link

Micromamba >v1.4.5 broken with cygwin #2683

Closed 0xbe7a closed 1 year ago

0xbe7a commented 1 year ago

Troubleshooting docs

How did you install Mamba?

Micromamba

Search tried in issue tracker

yes

Latest version of Mamba

Tried in Conda?

Not applicable

Describe your issue

I'm using micromamba with cygwin. My .bash_profile looks like

# >>> mamba initialize >>>
# !! Contents within this block are managed by 'mamba init' !!
export MAMBA_EXE='/cygdrive/c/Users/USER/.bin/micromamba.exe';
export MAMBA_ROOT_PREFIX='/cygdrive/c/Users/USER/micromamba_prefix';
eval "$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX")"
# <<< mamba initialize <<<

With micromamba <=1.4.5 shell hook --shell bash checked if !hook_source_path().empty() and if true just emitted the file shell hook without substituting $MAMBA_EXE. Only if hook_source_path() was empty would get_hook_contents be used to emit the shell hook. Crucially get_hook_contents replaced $MAMBA_EXE with the path to the binary on its own. However, this produces a broken config, as the replaced path is in windows format which cant be opened by cygwins bash. PR #2631 changed the behavior of shell hook so that get_hook_contents is always used which breaks my cygwin config.

I'm not really sure how to tackle this problem, but i think a --no-replace option for shell hook would solve my issue.

mamba info / micromamba info

No response

Logs

No response

environment.yml

No response

~/.condarc

No response

jonashaag commented 1 year ago

I think we should use the equivalent of cygpath -u for get_hook_contents in bash

jonashaag commented 1 year ago

I wonder why this hasn't been found in the tests.

AntoinePrv commented 1 year ago

Thank you for reporting @0xbe7a

If I understand correctly, the issue can be solved by using /unix/like/paths? More precisely changing the format here? I think it is safe to make it always unix-like when using unix shells.

0xbe7a commented 1 year ago

Yes, i think the assumption should hold in general and would solve my issue!

AntoinePrv commented 1 year ago

@0xbe7a could you try #2685 locally?

0xbe7a commented 1 year ago

I can't build micromamba in the enterprise environment im in. I could test out the artifacts from the CI builds, however the CI Build micromamba - win-64 is failing

AntoinePrv commented 1 year ago

I could test out the artifacts from the CI builds, however the CI Build micromamba - win-64 is failing

That should be a temporary VCPKG issue :crossed_fingers:

pavelzw commented 1 year ago

That should be a temporary VCPKG issue 🤞

Let's hope https://github.com/microsoft/vcpkg/issues/32600 is fixed soon 😅

0xbe7a commented 1 year ago

The PR still replaces the $MAMBA_EXE with a path in windows format

~ $ micromamba shell hook --shell=bash micromamba_prefix/

# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause

__mamba_exe() (
    "C:\Users\USER\micromamba.exe" "${@}"
)

After discovering more issues with cygwins cygdrive i abandonned cygwin for gits bash.exe. gits bash.exe can handle paths in windows format so micromamba 1.4.9 works.

jonashaag commented 1 year ago

I'll reopen because it's not fixed.

goyalyashpal commented 1 year ago

as this is related with unix shells on windows, saying just for recrods; that micromamba 1.4.9 works fine with msys2 3.4.7.x86_64.

vickunwu commented 10 months ago

as this is related with unix shells on windows, saying just for recrods; that micromamba 1.4.9 works fine with msys2 3.4.7.x86_64.

@goyalyashpal Hello friend. I'm using msys2 with zsh as shell(not Git Bash) but I cannot get micromamba working. Could you please give me some instructions about the details of how to make it run? Appreciate it a lot.

goyalyashpal commented 10 months ago

I'm using msys2 with zsh as shell(not Git Bash) but I cannot get micromamba working

hi! i may have helped, but i don't have enough information. read here: https://tinyurl.com/stack-checklist/ and here: http://catb.org/~esr/faqs/smart-questions.html#beprecise

vickunwu commented 10 months ago

I'm using msys2 with zsh as shell(not Git Bash) but I cannot get micromamba working

hi! i may have helped, but i don't have enough information. read here: https://tinyurl.com/stack-checklist/

@goyalyashpal I've managed to get the micromamba auto completion works by modifying the following line in my rc file: eval "$("$MAMBA_EXE" shell hook --shell ${SHELL##*/} --root-prefix "$MAMBA_ROOT_PREFIX" | sed "s#$(cygpath -w $MAMBA_EXE|sed 's|\\|\\\\|g')#$MAMBA_EXE#g")"

The reason I did this is that msys2 do not recognize windows path (e.g. 'C:\micromamba\micromamba.exe') that called in the shell hook.

But when I tried to activate a certain env, here's the output:

(eval):.:7: no such file or directory: C:\Users\vickunwu\scoop\persist\micromamba\mamba\envs\whisperx\etc\conda\activate.d\openssl_activate.sh^M

I guess it's the same issue but this time I'm not able to do hacks anymore as it's controlled by the program.

goyalyashpal commented 10 months ago

micromamba auto completion works I tried to activate a certain env, here's the output:

$ micromamba activate 
critical libmamba Shell not initialized

'micromamba' is running as a subprocess and can't modify the parent shell. 
Thus you must initialize your shell before using activate and deactivate.  

To initialize the current bash shell, run:
    $ eval "$(micromamba shell hook --shell bash)"
and then activate or deactivate with:
    $ micromamba activate
To automatically initialize all future (bash) shells, run:
    $ micromamba shell init --shell bash --root-prefix=~/micromamba        
If your shell was already initialized, reinitialize your shell with:       
    $ micromamba shell reinit --shell bash
Otherwise, this may be an issue. In the meantime you can run commands. See:
    $ micromamba run --help

Supported shells are {bash, zsh, csh, xonsh, cmd.exe, powershell, fish}.   

$ eval "$(micromamba shell hook --shell bash)"

$ micromamba activate 
warning  libmamba 'root_prefix' set with default value: C:\Users\...\micromamba
(base) 
$

sed 's|\\|\\\\|g'

why not use forward slashes?

vickunwu commented 10 months ago

@goyalyashpal

why not use forward slashes?

I'm not clear about where should I use forward slashes. I think '\' should be processed as it's an escape character.

Here's my output of executing eval "$(micromamba shell hook -s bash)"

eval "$(micromamba shell hook -s bash)"
zsh: parse error near `^M'

I'm using msys_shell.cmd to spawn a mingw64 session in Windows terminal. Does this make a difference?

I think the output is a CRLF/LF issue. However, as the shell hook contains lines like \return, I cannot just tr -d '\r' or sed 's/\r//g'.

I've tried dos2unix but it still messes the shell hook.

goyalyashpal commented 10 months ago

msys_shell.cmd to spawn a mingw64 session in Windows terminal

that script is no longer required as there are dedicated .exe launchers now.

but i launch the bash session directly from konsole or wezterm terminal. konsole allows picking default shell in its settings - i picked bash there.

i have faint memory that there probably were some problems on invoking from cmd, but can't say for sure


also, have u tried invoking activation command from bash?

goyalyashpal commented 10 months ago
scoop\persist\micromamba\mamba\envs

i installed micromamba directly - without using scoop. just guessing here - that as scoop is windows only, and u seemed to be facing errors in that direction - so, maybe try direct install of micromamba too.

https://mamba.readthedocs.io/en/latest/installation/micromamba-installation.html#umamba-install

vickunwu commented 10 months ago

also, have u tried invoking activation command from bash?

I tried bash this time, and it works on both launcher and cmd without any problem. I guess that's a zsh issue. Thanks for your kind assistance!


I'm sad to say that I use Msys2 mainly because it's native support for zsh. Otherwise, I would rather use Git Bash as it seems to have less compatibility issues.

Maybe I should open another issue.

goyalyashpal commented 10 months ago

self hiding as offtopic


Otherwise, I would rather use Git Bash as it seems to have less compatibility issues.

i am using msys2 bash since 2 yrs now, and faced no problems that i am aware of.

so, just curious, why are u using zsh, and what compatibility issues do u think msys2 has that gwf doesn't?

vickunwu commented 10 months ago
  1. Git Bash natively use USERPROFILE as its home dir, it's more convenient to move downloaded files into my working dir.
  2. Msys2 has a git rev-parse issue and you have to do extra tweaks to mitigate it.
  3. Zsh have more plugins and there's a lot of tutorials about it.
ThomasMarwitzQC commented 10 months ago

@0xbe7a and I discovered a quick fix that you can use as long as this is not fixed and you don't want to abandon Cygwin:

# >>> mamba initialize >>>
# !! Contents within this block are managed by 'mamba init' !!
export MAMBA_EXE='/cygdrive/c/Users/thomas/.bin/micromamba';
export MAMBA_ROOT_PREFIX='/cygdrive/c/Users/thomas/micromamba_prefix';
eval "$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX")"
# <<< mamba initialize <<<

__mamba_exe() (
    "${MAMBA_EXE}" "${@}"
)

micromamba activate base