conda / conda

A system-level, binary package and environment manager running on all major operating systems and platforms.
https://docs.conda.io/projects/conda/
Other
6.32k stars 1.63k forks source link

Conda in Windows under MSYS2 and Zsh line ending problems #9922

Open joaommartins opened 4 years ago

joaommartins commented 4 years ago

Current Behavior

Conda in msys2 and Zsh overwrites system variables with CRLF line endings after first use, making it impossible to use conda after using it once. Conda in msys2 and bash works as expected.

Steps to Reproduce

Installed miniconda in Windows and tried using it under zsh installed through Msys2. conda init zsh writes the follwowing to .zshrc:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval "$('/c/Users/joaom/Miniconda3/Scripts/conda.exe' 'shell.zsh' 'hook')"
# <<< conda initialize <<<

New shell sessions complain with (eval):35: parse error near `elif' if this initialization is in the .zshrc. conda init zsh also leaves the .zshrc with CRLF line endings, which is fine since msys2 ignores line endings by default. conda activate <envname> does not work after this, with the usual error:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.

To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - cmd.exe
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

Alternatively, loading conda.sh directly almost works. I added the following to my .zshrc instead of the conda init generated eval command:

. /c/Users/joaom/Miniconda3/etc/profile.d/conda.sh

This almost works in the sense that I can use conda activate <envname> once without errors. After the first usage, any conda usage lead to this error:

~
❯ conda activate base

~ [base]
❯ conda deactivate

__conda_activate:13: no such file or directory: /c/Users/joaom/Miniconda3/Scripts/conda.exe^M

(127) ~ [base]
❯

zsh complains about not finding conda.exe due to the CRLF line ending, meaning that it has to have changed between activating the environment and trying to deactivate it. I looked in my env before and after activating an environment, and I can see that the line endings change, as you can see in the output of env | cat -A:

Before activating, relevant env lines:

CONDA_EXE=/c/Users/joaom/Miniconda3/Scripts/conda.exe$
_CE_M=$
_CE_CONDA=$
CONDA_PYTHON_EXE=C:\Users\joaom\Miniconda3\python.exe$
CONDA_SHLVL=0$
AGKOZAK_GIT_VERSION=2.26.2.windows.1$
_=/usr/bin/env$

After activating, relevant env lines:

CONDA_EXE=/c/Users/joaom/Miniconda3/Scripts/conda.exe^M$
_CE_M=^M$
_CE_CONDA=^M$
CONDA_PYTHON_EXE=/c/Users/joaom/Miniconda3/python.exe^M$
CONDA_SHLVL=1^M$
AGKOZAK_GIT_VERSION=2.26.2.windows.1$
CONDA_PREFIX=C:\Users\joaom\Miniconda3^M$
CONDA_DEFAULT_ENV=base^M$
CONDA_PROMPT_MODIFIER=(base) ^M$
_=/usr/bin/env$

As some further information, the environment uses its correct python executable:

~
❯ which python
/c/Python38/python

~
❯ python --version
Python 3.8.2

~
❯ conda activate base

~ [base]
❯ which python
/c/Users/joaom/Miniconda3/python

~ [base]
❯ python --version
Python 3.7.4

However, this python executable complains about the environment not being activated:

~ [base]
❯ python
Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>>

Expected Behavior

After running the first conda activate base conda commands should still work, allowing to deactivate the base environment or activating other environments. The python executable should correctly see the right environment activated.

Environment Information

conda info

``` ~ ❯ conda info active environment : None shell level : 0 user config file : C:\Users\joaom\.condarc populated config files : conda version : 4.8.3 conda-build version : 3.18.11 python version : 3.7.4.final.0 virtual packages : base environment : C:\Users\joaom\Miniconda3 (writable) channel URLs : https://repo.anaconda.com/pkgs/main/win-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/win-64 https://repo.anaconda.com/pkgs/r/noarch https://repo.anaconda.com/pkgs/msys2/win-64 https://repo.anaconda.com/pkgs/msys2/noarch package cache : C:\Users\joaom\Miniconda3\pkgs C:\Users\joaom\.conda\pkgs C:\Users\joaom\AppData\Local\conda\conda\pkgs envs directories : C:\Users\joaom\Miniconda3\envs C:\Users\joaom\.conda\envs C:\Users\joaom\AppData\Local\conda\conda\envs platform : win-64 user-agent : conda/4.8.3 requests/2.23.0 CPython/3.7.4 Windows/10 Windows/10.0.19041 administrator : False netrc file : None offline mode : False ```

env | sort | cat -A, before activating environment

``` ~ ❯ env | sort | cat -A !::=::\$ _=/usr/bin/env$ _CE_CONDA=$ _CE_M=$ ACLOCAL_PATH=/mingw64/share/aclocal:/usr/share/aclocal$ AGKOZAK_GIT_VERSION=2.26.2.windows.1$ ALLUSERSPROFILE=C:\ProgramData$ AMDPROFILERPATH=C:\Program Files\AMD\AMDuProf\bin$ ANSICON_DEF=7$ ANSICON=238x1000 (238x61)$ APPDATA=C:\Users\joaom\AppData\Roaming$ ChocolateyInstall=C:\ProgramData\chocolatey$ ChocolateyLastPathUpdate=132308462173094812$ CMDER_ROOT=C:\Users\joaom\Software\cmder$ COLORTERM=yes$ CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files$ COMMONPROGRAMFILES=C:\Program Files\Common Files$ CommonProgramW6432=C:\Program Files\Common Files$ COMPUTERNAME=LENOVO-LAPTOP$ COMSPEC=C:\WINDOWS\system32\cmd.exe$ CONDA_EXE=/c/Users/joaom/Miniconda3/Scripts/conda.exe$ CONDA_PYTHON_EXE=C:\Users\joaom\Miniconda3\python.exe$ CONDA_SHLVL=0$ ConEmuANSI=ON$ ConEmuAnsiLog=$ ConEmuArgs=$ ConEmuArgs2=$ ConEmuBackHWND=0x000C0486$ ConEmuBaseDir=C:\Users\joaom\Software\cmder\vendor\conemu-maximus5\ConEmu$ ConEmuBaseDirShort=C:\Users\joaom\Software\cmder\vendor\conemu-maximus5\ConEmu$ ConEmuBuild=191012$ ConEmuCfgDir=C:\Users\joaom\Software\cmder\vendor\conemu-maximus5$ ConEmuConfig=$ ConEmuDir=C:\Users\joaom\Software\cmder\vendor\conemu-maximus5$ ConEmuDrawHWND=0x000B0894$ ConEmuDrive=C:$ ConEmuHooks=Enabled$ ConEmuHWND=0x0019036C$ ConEmuPalette=Monokai$ ConEmuPID=10340$ ConEmuServerPID=9792$ ConEmuTask={Zsh::MSYS2}$ ConEmuWorkDir=C:\Users\joaom$ ConEmuWorkDrive=C:$ CONFIG_SITE=/mingw64/etc/config.site$ DriverData=C:\Windows\System32\Drivers\DriverData$ EDITOR=vim$ GOPATH=C:\Users\joaom\go$ HOME=/c/Users/joaom$ HOMEDRIVE=C:$ HOMEPATH=\Users\joaom$ HOSTNAME=LENOVO-LAPTOP$ INFOPATH=/usr/local/info:/usr/share/info:/usr/info:/share/info$ LANG=en_US.UTF-8$ LESS_TERMCAP_mb=^[[01;31m$ LESS_TERMCAP_md=^[[01;31m$ LESS_TERMCAP_me=^[[0m$ LESS_TERMCAP_se=^[[0m$ LESS_TERMCAP_so=^[[01;44;33m$ LESS_TERMCAP_ue=^[[0m$ LESS_TERMCAP_us=^[[01;32m$ LESS=-R$ LOCALAPPDATA=C:\Users\joaom\AppData\Local$ LOGNAME=joaom$ LOGONSERVER=\\LENOVO-LAPTOP$ LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:$ LSCOLORS=Gxfxcxdxbxegedabagacad$ MAIL=/var/mail/joaom$ MANPATH=/mingw64/local/man:/mingw64/share/man:/usr/local/man:/usr/share/man:/usr/man:/share/man$ MINGW_CHOST=x86_64-w64-mingw32$ MINGW_PACKAGE_PREFIX=mingw-w64-x86_64$ MINGW_PREFIX=/mingw64$ MSYS2_PATH_TYPE=inherit$ MSYSTEM_CARCH=x86_64$ MSYSTEM_CHOST=x86_64-w64-mingw32$ MSYSTEM_PREFIX=/mingw64$ MSYSTEM=MINGW64$ NUMBER_OF_PROCESSORS=8$ OLDPWD=/c/Users/joaom$ OneDrive=C:\Users\joaom\OneDrive$ OneDriveConsumer=C:\Users\joaom\OneDrive$ ORIGINAL_PATH=/usr/bin:/mingw64/bin:/c/Users/joaom/Software/cmder/vendor/conemu-maximus5/ConEmu/Scripts:/c/Users/joaom/Software/cmder/vendor/conemu-maximus5:/c/Users/joaom/Software/cmder/vendor/conemu-maximus5/ConEmu:/c/Python38/Scripts:/c/Python38:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program Files (x86)/Calibre2:/c/Program Files (x86)/QuickTime/QTSystem:/c/Go/bin:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/Mullvad VPN/resources:/c/Program Files/Amazon/AWSCLIV2:/mingw64/bin:/usr/bin:/c/Program Files/nodejs:/c/ProgramData/chocolatey/bin:/c/Users/joaom/Software/ffmpeg-20200403-52523b6-win64-static/bin:/c/Program Files/AMD/AMDuProf/bin:/c/Users/joaom/Miniconda3:/c/Users/joaom/Miniconda3/Library/mingw-w64/bin:/c/Users/joaom/Miniconda3/Library/usr/bin:/c/Users/joaom/Miniconda3/Library/bin:/c/Users/joaom/Miniconda3/Scripts:/c/Users/joaom/AppData/Local/Microsoft/WindowsApps:/c/Users/joaom/AppData/Local/Programs/Microsoft VS Code/bin:/c/Users/joaom/Software/cmder:/c/Users/joaom/Software/chromedriver:/c/Program Files (x86)/Minimal ADB and Fastboot:/c/Users/joaom/go/bin:/c/Users/joaom/AppData/Roaming/npm$ ORIGINAL_TEMP=/c/Users/joaom/AppData/Local/Temp$ ORIGINAL_TMP=/c/Users/joaom/AppData/Local/Temp$ OS=Windows_NT$ PAGER=less$ PATH=/c/Users/joaom/Miniconda3/Scripts/condabin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Users/joaom/Software/cmder/vendor/conemu-maximus5/ConEmu/Scripts:/c/Users/joaom/Software/cmder/vendor/conemu-maximus5:/c/Users/joaom/Software/cmder/vendor/conemu-maximus5/ConEmu:/c/Python38/Scripts:/c/Python38:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program Files (x86)/Calibre2:/c/Program Files (x86)/QuickTime/QTSystem:/c/Go/bin:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/Mullvad VPN/resources:/c/Program Files/Amazon/AWSCLIV2:/c/Program Files/nodejs:/c/ProgramData/chocolatey/bin:/c/Users/joaom/Software/ffmpeg-20200403-52523b6-win64-static/bin:/c/Program Files/AMD/AMDuProf/bin:/c/Users/joaom/Miniconda3:/c/Users/joaom/Miniconda3/Library/mingw-w64/bin:/c/Users/joaom/Miniconda3/Library/usr/bin:/c/Users/joaom/Miniconda3/Library/bin:/c/Users/joaom/Miniconda3/Scripts:/c/Users/joaom/AppData/Local/Microsoft/WindowsApps:/c/Users/joaom/AppData/Local/Programs/Microsoft VS Code/bin:/c/Users/joaom/Software/cmder:/c/Users/joaom/Software/chromedriver:/c/Program Files (x86)/Minimal ADB and Fastboot:/c/Users/joaom/go/bin:/c/Users/joaom/AppData/Roaming/npm:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Users/joaom/.antigen/bundles/robbyrussell/oh-my-zsh/lib:/c/Users/joaom/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/command-not-found:/c/Users/joaom/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/docker:/c/Users/joaom/.antigen/bundles/zsh-users/zsh-completions:/c/Users/joaom/.antigen/bundles/zsh-users/zsh-autosuggestions:/c/Users/joaom/.antigen/bundles/zsh-users/zsh-syntax-highlighting:/c/Users/joaom/.antigen/bundles/agkozak/agkozak-zsh-prompt$ PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW$ PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig$ PRINTER=Microsoft Print to PDF$ PROCESSOR_ARCHITECTURE=AMD64$ PROCESSOR_IDENTIFIER=AMD64 Family 23 Model 24 Stepping 1, AuthenticAMD$ PROCESSOR_LEVEL=23$ PROCESSOR_REVISION=1801$ ProgramData=C:\ProgramData$ ProgramFiles(x86)=C:\Program Files (x86)$ PROGRAMFILES=C:\Program Files$ ProgramW6432=C:\Program Files$ PS1=%B%F{red}%(?..%? )%f%b%B%F{blue}%n%f%b@%m %B%40<..<%~%<< %b%# $ PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules;C:\Program Files (x86)\AWS Tools\PowerShell\$ PUBLIC=C:\Users\Public$ PWD=/c/Users/joaom$ SESSIONNAME=Console$ SHELL=/usr/bin/zsh$ SHLVL=1$ SYSTEMDRIVE=C:$ SYSTEMROOT=C:\WINDOWS$ TEMP=/tmp$ temp=C:\Users\joaom\AppData\Local\Temp$ TERM=xterm-256color$ TMP=/tmp$ TZ=Europe/Paris$ USER=joaom$ USERDOMAIN_ROAMINGPROFILE=LENOVO-LAPTOP$ USERDOMAIN=LENOVO-LAPTOP$ USERNAME=joaom$ USERPROFILE=C:\Users\joaom$ WINDIR=C:\WINDOWS$ ```

env | sort | cat -A, after activating environment

``` ~ [base] ❯ env | sort | cat -A !::=::\$ _=/usr/bin/env$ _CE_CONDA=^M$ _CE_M=^M$ ACLOCAL_PATH=/mingw64/share/aclocal:/usr/share/aclocal$ AGKOZAK_GIT_VERSION=2.26.2.windows.1$ ALLUSERSPROFILE=C:\ProgramData$ AMDPROFILERPATH=C:\Program Files\AMD\AMDuProf\bin$ ANSICON_DEF=7$ ANSICON=238x1000 (238x61)$ APPDATA=C:\Users\joaom\AppData\Roaming$ ChocolateyInstall=C:\ProgramData\chocolatey$ ChocolateyLastPathUpdate=132308462173094812$ CMDER_ROOT=C:\Users\joaom\Software\cmder$ COLORTERM=yes$ CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files$ COMMONPROGRAMFILES=C:\Program Files\Common Files$ CommonProgramW6432=C:\Program Files\Common Files$ COMPUTERNAME=LENOVO-LAPTOP$ COMSPEC=C:\WINDOWS\system32\cmd.exe$ CONDA_DEFAULT_ENV=base^M$ CONDA_EXE=/c/Users/joaom/Miniconda3/Scripts/conda.exe^M$ CONDA_PREFIX=C:\Users\joaom\Miniconda3^M$ CONDA_PROMPT_MODIFIER=(base) ^M$ CONDA_PYTHON_EXE=/c/Users/joaom/Miniconda3/python.exe^M$ CONDA_SHLVL=1^M$ ConEmuANSI=ON$ ConEmuAnsiLog=$ ConEmuArgs=$ ConEmuArgs2=$ ConEmuBackHWND=0x000C0486$ ConEmuBaseDir=C:\Users\joaom\Software\cmder\vendor\conemu-maximus5\ConEmu$ ConEmuBaseDirShort=C:\Users\joaom\Software\cmder\vendor\conemu-maximus5\ConEmu$ ConEmuBuild=191012$ ConEmuCfgDir=C:\Users\joaom\Software\cmder\vendor\conemu-maximus5$ ConEmuConfig=$ ConEmuDir=C:\Users\joaom\Software\cmder\vendor\conemu-maximus5$ ConEmuDrawHWND=0x000B0894$ ConEmuDrive=C:$ ConEmuHooks=Enabled$ ConEmuHWND=0x0019036C$ ConEmuPalette=Monokai$ ConEmuPID=10340$ ConEmuServerPID=9792$ ConEmuTask={Zsh::MSYS2}$ ConEmuWorkDir=C:\Users\joaom$ ConEmuWorkDrive=C:$ CONFIG_SITE=/mingw64/etc/config.site$ DriverData=C:\Windows\System32\Drivers\DriverData$ EDITOR=vim$ GOPATH=C:\Users\joaom\go$ HOME=/c/Users/joaom$ HOMEDRIVE=C:$ HOMEPATH=\Users\joaom$ HOSTNAME=LENOVO-LAPTOP$ INFOPATH=/usr/local/info:/usr/share/info:/usr/info:/share/info$ LANG=en_US.UTF-8$ LESS_TERMCAP_mb=^[[01;31m$ LESS_TERMCAP_md=^[[01;31m$ LESS_TERMCAP_me=^[[0m$ LESS_TERMCAP_se=^[[0m$ LESS_TERMCAP_so=^[[01;44;33m$ LESS_TERMCAP_ue=^[[0m$ LESS_TERMCAP_us=^[[01;32m$ LESS=-R$ LOCALAPPDATA=C:\Users\joaom\AppData\Local$ LOGNAME=joaom$ LOGONSERVER=\\LENOVO-LAPTOP$ LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:$ LSCOLORS=Gxfxcxdxbxegedabagacad$ MAIL=/var/mail/joaom$ MANPATH=/mingw64/local/man:/mingw64/share/man:/usr/local/man:/usr/share/man:/usr/man:/share/man$ MINGW_CHOST=x86_64-w64-mingw32$ MINGW_PACKAGE_PREFIX=mingw-w64-x86_64$ MINGW_PREFIX=/mingw64$ MSYS2_PATH_TYPE=inherit$ MSYSTEM_CARCH=x86_64$ MSYSTEM_CHOST=x86_64-w64-mingw32$ MSYSTEM_PREFIX=/mingw64$ MSYSTEM=MINGW64$ NUMBER_OF_PROCESSORS=8$ OLDPWD=/c/Users/joaom$ OneDrive=C:\Users\joaom\OneDrive$ OneDriveConsumer=C:\Users\joaom\OneDrive$ ORIGINAL_PATH=/usr/bin:/mingw64/bin:/c/Users/joaom/Software/cmder/vendor/conemu-maximus5/ConEmu/Scripts:/c/Users/joaom/Software/cmder/vendor/conemu-maximus5:/c/Users/joaom/Software/cmder/vendor/conemu-maximus5/ConEmu:/c/Python38/Scripts:/c/Python38:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program Files (x86)/Calibre2:/c/Program Files (x86)/QuickTime/QTSystem:/c/Go/bin:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/Mullvad VPN/resources:/c/Program Files/Amazon/AWSCLIV2:/mingw64/bin:/usr/bin:/c/Program Files/nodejs:/c/ProgramData/chocolatey/bin:/c/Users/joaom/Software/ffmpeg-20200403-52523b6-win64-static/bin:/c/Program Files/AMD/AMDuProf/bin:/c/Users/joaom/Miniconda3:/c/Users/joaom/Miniconda3/Library/mingw-w64/bin:/c/Users/joaom/Miniconda3/Library/usr/bin:/c/Users/joaom/Miniconda3/Library/bin:/c/Users/joaom/Miniconda3/Scripts:/c/Users/joaom/AppData/Local/Microsoft/WindowsApps:/c/Users/joaom/AppData/Local/Programs/Microsoft VS Code/bin:/c/Users/joaom/Software/cmder:/c/Users/joaom/Software/chromedriver:/c/Program Files (x86)/Minimal ADB and Fastboot:/c/Users/joaom/go/bin:/c/Users/joaom/AppData/Roaming/npm$ ORIGINAL_TEMP=/c/Users/joaom/AppData/Local/Temp$ ORIGINAL_TMP=/c/Users/joaom/AppData/Local/Temp$ OS=Windows_NT$ PAGER=less$ PATH=/c/Users/joaom/Miniconda3:/c/Users/joaom/Miniconda3/Library/mingw-w64/bin:/c/Users/joaom/Miniconda3/Library/usr/bin:/c/Users/joaom/Miniconda3/Library/bin:/c/Users/joaom/Miniconda3/Scripts:/c/Users/joaom/Miniconda3/bin:/c/Users/joaom/Miniconda3/Scripts/condabin:/mingw64/bin:/usr/local/bin:/usr/bin:/c/Users/joaom/Software/cmder/vendor/conemu-maximus5/ConEmu/Scripts:/c/Users/joaom/Software/cmder/vendor/conemu-maximus5:/c/Users/joaom/Software/cmder/vendor/conemu-maximus5/ConEmu:/c/Python38/Scripts:/c/Python38:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Program Files (x86)/Calibre2:/c/Program Files (x86)/QuickTime/QTSystem:/c/Go/bin:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/Mullvad VPN/resources:/c/Program Files/Amazon/AWSCLIV2:/c/Program Files/nodejs:/c/ProgramData/chocolatey/bin:/c/Users/joaom/Software/ffmpeg-20200403-52523b6-win64-static/bin:/c/Program Files/AMD/AMDuProf/bin:/c/Users/joaom/AppData/Local/Microsoft/WindowsApps:/c/Users/joaom/AppData/Local/Programs/Microsoft VS Code/bin:/c/Users/joaom/Software/cmder:/c/Users/joaom/Software/chromedriver:/c/Program Files (x86)/Minimal ADB and Fastboot:/c/Users/joaom/go/bin:/c/Users/joaom/AppData/Roaming/npm:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Users/joaom/.antigen/bundles/robbyrussell/oh-my-zsh/lib:/c/Users/joaom/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/command-not-found:/c/Users/joaom/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/docker:/c/Users/joaom/.antigen/bundles/zsh-users/zsh-completions:/c/Users/joaom/.antigen/bundles/zsh-users/zsh-autosuggestions:/c/Users/joaom/.antigen/bundles/zsh-users/zsh-syntax-highlighting:/c/Users/joaom/.antigen/bundles/agkozak/agkozak-zsh-prompt^M$ PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW$ PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig$ PRINTER=Microsoft Print to PDF$ PROCESSOR_ARCHITECTURE=AMD64$ PROCESSOR_IDENTIFIER=AMD64 Family 23 Model 24 Stepping 1, AuthenticAMD$ PROCESSOR_LEVEL=23$ PROCESSOR_REVISION=1801$ ProgramData=C:\ProgramData$ ProgramFiles(x86)=C:\Program Files (x86)$ PROGRAMFILES=C:\Program Files$ ProgramW6432=C:\Program Files$ PS1=%B%F{red}%(?..%? )%f%b%B%F{blue}%n%f%b@%m %B%40<..<%~%<< %b%# $ PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules;C:\Program Files (x86)\AWS Tools\PowerShell\$ PUBLIC=C:\Users\Public$ PWD=/c/Users/joaom$ SESSIONNAME=Console$ SHELL=/usr/bin/zsh$ SHLVL=1$ SYSTEMDRIVE=C:$ SYSTEMROOT=C:\WINDOWS$ TEMP=/tmp$ temp=C:\Users\joaom\AppData\Local\Temp$ TERM=xterm-256color$ TMP=/tmp$ TZ=Europe/Paris$ USER=joaom$ USERDOMAIN_ROAMINGPROFILE=LENOVO-LAPTOP$ USERDOMAIN=LENOVO-LAPTOP$ USERNAME=joaom$ USERPROFILE=C:\Users\joaom$ WINDIR=C:\WINDOWS$ ```

mingwandroid commented 4 years ago

Thanks for the detailed report!

I have a feeling that the right fix for this is in MSYS2's zsh. A PR to not use CRLF anywhere in the shell files we emit for Windows would also be welcome though, I suspect!

Murazaki commented 4 years ago

Please get rid of those CR and fix this. conda is the only tool I have that doesn't work on zsh/mintty.

tuomastik commented 3 years ago

Any workarounds?

dhbloo commented 3 years ago

It seems this line eval "$('/c/Anaconda3/Scripts/conda.exe' 'shell.zsh' 'hook')" produces incorrect bash script. The "\r" in line 35 "\rehash" is interrupted as line break. echo "$('/c/Anaconda3/Scripts/conda.exe' 'shell.zsh' 'hook')" gives

export CONDA_EXE='/c/Anaconda3/Scripts/conda.exe'
export _CE_M=''
export _CE_CONDA=''
export CONDA_PYTHON_EXE='C:\Anaconda3\python.exe'

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

__add_sys_prefix_to_path() {
    # In dev-mode CONDA_EXE is python.exe and on Windows
    # it is in a different relative location to condabin.
    if [ -n "${_CE_CONDA}" ] && [ -n "${WINDIR+x}" ]; then
        SYSP=$(\dirname "${CONDA_EXE}")
    else
        SYSP=$(\dirname "${CONDA_EXE}")
        SYSP=$(\dirname "${SYSP}")
    fi

    if [ -n "${WINDIR+x}" ]; then
        PATH="${SYSP}/bin:${PATH}"
        PATH="${SYSP}/Scripts:${PATH}"
        PATH="${SYSP}/Library/bin:${PATH}"
        PATH="${SYSP}/Library/usr/bin:${PATH}"
        PATH="${SYSP}/Library/mingw-w64/bin:${PATH}"
        PATH="${SYSP}:${PATH}"
    else
        PATH="${SYSP}/bin:${PATH}"
    fi
    port PATH
}

__conda_hashr() {
    if [ -n "${ZSH_VERSION:+x}" ]; then
ehash
    elif [ -n "${POSH_VERSION:+x}" ]; then
        :  # pass
    else
        \hash -r
    fi
}

......
victor-mariano-leite commented 3 years ago

I've was having the same problem here when using WSL 2 with Ubuntu 20.04, to avoid this problem I've used dos2unix file converter in the ~/.zshrc file before executing source ~/.zshrc, because of the escape characters. Looked like it worked, although I can't get to work conda activate <ENV>, when I execute conda init zsh, by default CONDA_EXE and CONDA_PYTHON_EXE are setted in the wrong paths, since it's running from inside the WSL Ubuntu VM the correct path should be /mnt/c/.... not /C/

ICHx commented 2 years ago

https://github.com/ohmyzsh/ohmyzsh/issues/9016

iwei20 commented 2 years ago

I got it to work on my zsh installed from Cygwin, which is using oh-my-zsh and powerlevel10k theme.

I directly loaded conda.sh as indicated by @joaommartins. This initially led to some different character issues which I fixed with export PYTHONIOENCODING=UTF-8, before I encountered the same issue as in the original post with ^M being appended to the conda executable. To eliminate carriage returns I indiscriminately replaced as many string variables in conda.sh as possible with $(echo $string | tr -d '\r') in the shell script. I don't know which replacement did it, but it works now! 🤷

export CONDA_EXE=$(echo '/cygdrive/c/Users/karp/anaconda3/Scripts/conda.exe' | tr -d '\r')
export _CE_M=''
export _CE_CONDA=''
export CONDA_PYTHON_EXE='C:\Users\karp\anaconda3\python.exe'

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

__add_sys_prefix_to_path() {
    # In dev-mode CONDA_EXE is python.exe and on Windows
    # it is in a different relative location to condabin.
    if [ -n "${_CE_CONDA}" ] && [ -n "${WINDIR+x}" ]; then
        SYSP=$(\dirname "${CONDA_EXE}")
        SYSP=$(echo ${SYSP} | tr -d '\r')
    else
        SYSP=$(\dirname "${CONDA_EXE}")
        SYSP=$(\dirname "${SYSP}")
        SYSP=$(echo ${SYSP} | tr -d '\r')
    fi

    if [ -n "${WINDIR+x}" ]; then
        PATH="${SYSP}/bin:${PATH}"
        PATH="${SYSP}/Scripts:${PATH}"
        PATH="${SYSP}/Library/bin:${PATH}"
        PATH="${SYSP}/Library/usr/bin:${PATH}"
        PATH="${SYSP}/Library/mingw-w64/bin:${PATH}"
        PATH="${SYSP}:${PATH}"
        PATH=$(echo ${PATH} | tr -d '\r')
    else
        PATH="${SYSP}/bin:${PATH}"
        PATH=$(echo ${PATH} | tr -d '\r')
    fi
    \export PATH
}

__conda_exe() (
    __add_sys_prefix_to_path
    $(echo "$CONDA_EXE" | tr -d '\r') $_CE_M $_CE_CONDA $(echo "$@" | tr -d '\r')
)

__conda_hashr() {
    if [ -n "${ZSH_VERSION:+x}" ]; then
        \rehash
    elif [ -n "${POSH_VERSION:+x}" ]; then
        :  # pass
    else
        \hash -r
    fi
}

__conda_activate() {
    if [ -n "${CONDA_PS1_BACKUP:+x}" ]; then
        # Handle transition from shell activated with conda <= 4.3 to a subsequent activation
        # after conda updated to >= 4.4. See issue #6173.
        PS1="$CONDA_PS1_BACKUP"
        PS1=$(echo ${PS1} | tr -d '\r')
        \unset CONDA_PS1_BACKUP
    fi
    \local ask_conda
    ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix "$@")" || \return
    ask_conda=$(echo ${ask_conda} | tr -d '\r')
    \eval "$ask_conda"
    __conda_hashr
}

__conda_reactivate() {
    \local ask_conda
    ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix reactivate)" || \return
    ask_conda=$(echo ${ask_conda} | tr -d '\r')
    \eval "$ask_conda"
    __conda_hashr
}

conda() {
    \local cmd="${1-__missing__}"
    case "$cmd" in
        activate|deactivate)
            __conda_activate $(echo "$@" | tr -d '\r')
            ;;
        install|update|upgrade|remove|uninstall)
            __conda_exe $(echo "$@" | tr -d '\r') || \return
            __conda_reactivate
            ;;
        *)
            __conda_exe $(echo "$@" | tr -d '\r')
            ;;
    esac
}

if [ -z "${CONDA_SHLVL+x}" ]; then
    \export CONDA_SHLVL=0
    # In dev-mode CONDA_EXE is python.exe and on Windows
    # it is in a different relative location to condabin.
    if [ -n "${_CE_CONDA:+x}" ] && [ -n "${WINDIR+x}" ]; then
        PATH="$(\dirname "$CONDA_EXE")/condabin${PATH:+":${PATH}"}"
    else
        PATH="$(\dirname "$(\dirname "$CONDA_EXE")")/condabin${PATH:+":${PATH}"}"
    fi
    \export PATH

    # We're not allowing PS1 to be unbound. It must at least be set.
    # However, we're not exporting it, which can cause problems when starting a second shell
    # via a first shell (i.e. starting zsh from bash).
    if [ -z "${PS1+x}" ]; then
        PS1=
    fi
fi
mlaves commented 2 years ago

@iwei20 Your solution almost worked for me. However, I had to additionally escape backslashes from ask_conda in __conda_activate:

ask_conda=$(echo ${ask_conda:gs/\\/\/} | tr -d '\r')

Otherwise, my conda prefix path ended up being export CONDA_PREFIX='C:\miniforge3vs\py39' The \en was removed.

MischaPanch commented 2 years ago

Finally, the combination of sourcing conda.sh directly in .zshrc, @iwei20's fix eliminating carriage returns with @mlaves fix for escaping backslashes, conda works with oh-my-zsh under git bash. Thank you all very much!

UPDATE 25.12.22 : with the new version of conda, 22.11.1 at the time of writing, eliminating carriage returns in conda.sh was no longer necessary. Setting the pythonioencoding is still neded though, see https://github.com/conda/conda/issues/7445#issuecomment-774579800

charlesphil commented 2 years ago

Finally, the combination of sourcing conda.sh directly in .zshrc, @iwei20's fix eliminating carriage returns with @mlaves fix for escaping backlashes, conda works with oh-my-zsh under git bash. Thank you all very much!

Just wanted to add another confirmation that this combination solved the issue on a fresh installation of oh-my-zsh in git bash. Thank you all for your hard work!

SiddhantSadangi commented 2 years ago

The above solution "almost" worked for me. I am able to activate environments. But I get the below error on installing packages

DirectoryNotACondaEnvironmentError: The target directory exists, but it is not a conda environment.
Use 'conda create' to convert the directory to a conda environment.  target directory: C:

Any idea what would be wrong?

vasilevp commented 1 year ago

This did the trick for me:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval "$('/c/path/to/miniconda3/Scripts/conda.exe' 'shell.zsh' 'hook' | sed -e 's/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@"/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d \x27\\r\x27/g')"
# <<< conda initialize <<<

Basically, it replaces __conda_exe with the following:

__conda_exe() (
    __add_sys_prefix_to_path
    "$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d '\r'
)

The issue seems to be that this hook generates a call to conda.exe, then in __conda_activate it sends the output to eval and that output overwrites several environment variables.

However, since that's output from a Windows binary, it contains \r which gets appended to those environment variables, which breaks conda.

UPD: not sure why this does not happen in MSYS2 Bash, but I suspect that it does some extra trickery to clean up line endings in eval...

UPD 2024: Looks like a new version of this error has been appearing in the wild, which I happened to stumble upon randomly while playing with WSL. The solution is to add yet another tr -d '\r' to the end of the eval command, right after the last single quote.

This is what my .zshrc section looks like now:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval "$('/c/path/to/miniconda3/Scripts/conda.exe' 'shell.zsh' 'hook' | sed -e 's/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@"/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d \x27\\r\x27/g' | tr -d '\r')"
# <<< conda initialize <<<
thecrackofdawn commented 1 year ago

The above solution "almost" worked for me. I am able to activate environments. But I get the below error on installing packages

DirectoryNotACondaEnvironmentError: The target directory exists, but it is not a conda environment.
Use 'conda create' to convert the directory to a conda environment.  target directory: C:

Any idea what would be wrong?

Check your env, you will see CONDA_PREFIX=C:\Users\xx\Miniconda3. This is not a valid path in zsh. I add two line in the conda.sh to fix the path.

 __conda_activate() {
     if [ -n "${CONDA_PS1_BACKUP:+x}" ]; then
         # Handle transition from shell activated with conda <= 4.3 to a subsequent 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
     CONDA_PREFIX='/c/Users/xx/Miniconda3/'
     export CONDA_PREFIX
 }

The last two lines fix the CONDA_PREFIX when you call conda activate

HernandoR commented 1 year ago

Hi, I have a similar problem that returns (eval):11: parse error near ^M when executing eval "$('/c/path/to/miniconda3/Scripts/conda.exe' 'shell.zsh' 'hook' in my ~/.zshrc file. Therefore the conda init do not success

I'm using zsh shell in ucrt64. conda works fine with PowerShell, and I have added the script path to env that conda init is callable

KpiHang commented 1 year ago

This did the trick for me:

# >>> conda initialize >>> 
# !! Contents within this block are managed by 'conda init' !!
eval "$('/c/path/to/miniconda3/Scripts/conda.exe' 'shell.zsh' 'hook' | sed -e 's/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@"/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d \x27\\r\x27/g')"
# <<< conda initialize <<<

Basically, it replaces __conda_exe with the following:

__conda_exe() (
    __add_sys_prefix_to_path
    "$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d '\r'
)

The issue seems to be that this hook generates a call to conda.exe, then in __conda_activate it sends the output to eval and that output overwrites several environment variables.

However, since that's output from a Windows binary, it contains \r which gets appended to those environment variables, which breaks conda.

UPD: not sure why this does not happen in MSYS2 Bash, but I suspect that it does some extra trickery to clean up line endings in eval...

@vasilevp Extremelly thank you, it works very wall, Thank you very much !

KpiHang commented 1 year ago

Hi, I have a similar problem that returns (eval):11: parse error near ^M when executing eval "$('/c/path/to/miniconda3/Scripts/conda.exe' 'shell.zsh' 'hook' in my ~/.zshrc file. Therefore the conda init do not success

I'm using zsh shell in ucrt64. conda works fine with PowerShell, and I have added the script path to env that conda init is callable

I have the same error with you, thanks @vasilevp it works very well for me.

here is my process of trying: https://www.cnblogs.com/kphang/p/17264764.html

yizhilll commented 1 year ago

This did the trick for me:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval "$('/c/path/to/miniconda3/Scripts/conda.exe' 'shell.zsh' 'hook' | sed -e 's/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@"/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d \x27\\r\x27/g')"
# <<< conda initialize <<<

Basically, it replaces __conda_exe with the following:

__conda_exe() (
    __add_sys_prefix_to_path
    "$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d '\r'
)

The issue seems to be that this hook generates a call to conda.exe, then in __conda_activate it sends the output to eval and that output overwrites several environment variables.

However, since that's output from a Windows binary, it contains \r which gets appended to those environment variables, which breaks conda.

UPD: not sure why this does not happen in MSYS2 Bash, but I suspect that it does some extra trickery to clean up line endings in eval...

This solution works for me!

Bluelet commented 9 months ago

I met the same line ending problems, and have spent a whole day trying to solve them, but failed. Finally, I decided using msys2 bash to manage conda package install, and maunally configured envs in zsh as my main working shell. In fact, conda init/activate only adds and changes some envs, and these envs can be easily set by yourself. This manual config has an additional benifit, no extra zsh starting time cost. ```

# >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! #if [ -f '/c/Users/peter/miniconda3/Scripts/conda.exe' ]; then # eval "$('/c/Users/peter/miniconda3/Scripts/conda.exe' 'shell.zsh' 'hook')" #fi # <<< conda initialize <<<

# maual set conda env export CONDA_DEFAULT_ENV=default export CONDA_EXE=/c/Users/peter/miniconda3/Scripts/conda.exe export CONDA_PREFIX='C:\Users\peter\miniconda3\envs\default' export CONDA_PREFIX_1='C:\Users\peter\miniconda3' export CONDA_PROMPT_MODIFIER='(default) ' export CONDA_PYTHON_EXE=/c/Users/peter/miniconda3/python.exe export CONDA_SHLVL=2 export PATH=/c/Users/peter/miniconda3/envs/default:/c/Users/peter/miniconda3/envs/default/Library/mingw-w64/bin:/c/Users/peter/miniconda3/envs/default/Library/usr/bin:/c/Users/peter/miniconda3/envs/default/Library/bin:/c/Users/peter/miniconda3/envs/default/Scripts:/c/Users/peter/miniconda3/envs/default/bin:/c/Users/peter/miniconda3/condabin:$PATH

aniude commented 8 months ago

This did the trick for me:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval "$('/c/path/to/miniconda3/Scripts/conda.exe' 'shell.zsh' 'hook' | sed -e 's/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@"/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d \x27\\r\x27/g')"
# <<< conda initialize <<<

Basically, it replaces __conda_exe with the following:

__conda_exe() (
    __add_sys_prefix_to_path
    "$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d '\r'
)

The issue seems to be that this hook generates a call to conda.exe, then in __conda_activate it sends the output to eval and that output overwrites several environment variables.

However, since that's output from a Windows binary, it contains \r which gets appended to those environment variables, which breaks conda.

UPD: not sure why this does not happen in MSYS2 Bash, but I suspect that it does some extra trickery to clean up line endings in eval...

It seems that will throw another new error as: UnicodeEncodeError: 'gbk' codec can't encode character '\u279c' in position 31: illegal multibyte sequence

It should be add the enviroment variable as: export PYTHONIOENCODING=UTF-8

uiolee commented 6 months ago

same issue

verajosemanuel commented 6 months ago

same issue here. any workaround?

lisch7 commented 5 months ago

This did the trick for me:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval "$('/c/path/to/miniconda3/Scripts/conda.exe' 'shell.zsh' 'hook' | sed -e 's/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@"/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d \x27\\r\x27/g')"
# <<< conda initialize <<<

Basically, it replaces __conda_exe with the following:

__conda_exe() (
    __add_sys_prefix_to_path
    "$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d '\r'
)

The issue seems to be that this hook generates a call to conda.exe, then in __conda_activate it sends the output to eval and that output overwrites several environment variables. However, since that's output from a Windows binary, it contains \r which gets appended to those environment variables, which breaks conda. UPD: not sure why this does not happen in MSYS2 Bash, but I suspect that it does some extra trickery to clean up line endings in eval...

It seems that will throw another new error as: UnicodeEncodeError: 'gbk' codec can't encode character '\u279c' in position 31: illegal multibyte sequence

It should be add the enviroment variable as: export PYTHONIOENCODING=UTF-8

Thanks. It works for me.

rdataforge commented 5 months ago

This makes the terminal unusable for me. It froze

Z-Fran commented 5 months ago

This did the trick for me:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval "$('/c/path/to/miniconda3/Scripts/conda.exe' 'shell.zsh' 'hook' | sed -e 's/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@"/"$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d \x27\\r\x27/g')"
# <<< conda initialize <<<

Basically, it replaces __conda_exe with the following:

__conda_exe() (
    __add_sys_prefix_to_path
    "$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d '\r'
)

The issue seems to be that this hook generates a call to conda.exe, then in __conda_activate it sends the output to eval and that output overwrites several environment variables. However, since that's output from a Windows binary, it contains \r which gets appended to those environment variables, which breaks conda. UPD: not sure why this does not happen in MSYS2 Bash, but I suspect that it does some extra trickery to clean up line endings in eval...

It seems that will throw another new error as: UnicodeEncodeError: 'gbk' codec can't encode character '\u279c' in position 31: illegal multibyte sequence

It should be add the enviroment variable as: export PYTHONIOENCODING=UTF-8

It works well.

serious-gist commented 1 month ago

I am getting the same error ''(eval):10: parse error near `^M'''

(eval):10: parse error near `^M'

> conda info

     active environment : None
       user config file : C:\Users\xyz\.condarc
 populated config files : C:\Users\xyz\miniforge3\.condarc
                          C:\Users\xyz\.condarc
          conda version : 24.5.0
    conda-build version : not installed
         python version : 3.10.14.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=skylake
                          __conda=24.5.0=0
                          __win=0=0
       base environment : C:\Users\xyz\miniforge3  (writable)
      conda av data dir : C:\Users\xyz\miniforge3\etc\conda
  conda av metadata url : None

          package cache : C:\Users\xyz\miniforge3\pkgs
                          C:\Users\xyz\.conda\pkgs
                          C:\Users\xyz\AppData\Local\conda\conda\pkgs
       envs directories : C:\Users\xyz\miniforge3\envs
                          C:\Users\xyz\.conda\envs
                          C:\Users\xyz\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/24.5.0 requests/2.31.0 CPython/3.10.14 Windows/10 Windows/10.0.22631 solver/libmamba conda-libmamba-solver/24.1.0 libmambapy/1.5.8
          administrator : False
             netrc file : None
           offline mode : False