conda-forge / miniforge

A conda-forge distribution.
https://conda-forge.org/miniforge
Other
5.99k stars 317 forks source link

Conda init not working for my ZSH shell #412

Open timmermansjoy opened 1 year ago

timmermansjoy commented 1 year ago

Solution to issue cannot be found in the documentation.

Issue

I have looked everywhere but nothing is working for me, when I install Miniforge on my Mac with home-brew and do conda init zsh afterwards, it puts the piece of code in my .zshrc file, but it still gives me an error that conda init has to be run. I'm doing this on the new M2 max MacBook, but also have tried it before with 2020 intel Mac and got the same thing, making me believe there is something going on with conda or my dot files but can't seem to figure out what.

Screenshot 2023-01-27 at 09 12 22 Screenshot 2023-01-27 at 09 13 26

Installed packages

brotlipy                  0.7.0           py310h8e9501a_1005    conda-forge
bzip2                     1.0.8                h3422bc3_4    conda-forge
ca-certificates           2022.12.7            h4653dfc_0    conda-forge
certifi                   2022.12.7          pyhd8ed1ab_0    conda-forge
cffi                      1.15.1          py310h2399d43_3    conda-forge
charset-normalizer        2.1.1              pyhd8ed1ab_0    conda-forge
conda                     22.9.0          py310hbe9552e_2    conda-forge
conda-package-handling    2.0.2              pyh38be061_0    conda-forge
conda-package-streaming   0.7.0              pyhd8ed1ab_1    conda-forge
cryptography              38.0.4          py310hfc83b78_0    conda-forge
idna                      3.4                pyhd8ed1ab_0    conda-forge
libcxx                    14.0.6               h2692d47_0    conda-forge
libffi                    3.4.2                h3422bc3_5    conda-forge
libsqlite                 3.40.0               h76d750c_0    conda-forge
libzlib                   1.2.13               h03a7124_4    conda-forge
ncurses                   6.3                  h07bb92c_1    conda-forge
openssl                   3.0.7                h03a7124_1    conda-forge
pip                       22.3.1             pyhd8ed1ab_0    conda-forge
pycosat                   0.6.4           py310h8e9501a_1    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pyopenssl                 22.1.0             pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
python                    3.10.8          h3ba56d0_0_cpython    conda-forge
python_abi                3.10                    3_cp310    conda-forge
readline                  8.1.2                h46ed386_0    conda-forge
requests                  2.28.1             pyhd8ed1ab_1    conda-forge
ruamel_yaml               0.15.80         py310h8e9501a_1008    conda-forge
setuptools                65.6.3             pyhd8ed1ab_0    conda-forge
tk                        8.6.12               he1e0b03_0    conda-forge
toolz                     0.12.0             pyhd8ed1ab_0    conda-forge
tzdata                    2022g                h191b570_0    conda-forge
urllib3                   1.26.13            pyhd8ed1ab_0    conda-forge
wheel                     0.38.4             pyhd8ed1ab_0    conda-forge
xz                        5.2.6                h57fd34a_0    conda-forge
yaml                      0.2.5                h3422bc3_2    conda-forge
zstandard                 0.19.0          py310had9512b_1    conda-forge
zstd                      1.5.2                h8128057_4    conda-forge

Environment info

active environment : None
            shell level : 0
       user config file : /Users/joy/.condarc
 populated config files : /opt/homebrew/Caskroom/miniforge/base/.condarc
          conda version : 22.9.0
    conda-build version : not installed
         python version : 3.10.8.final.0
       virtual packages : __osx=13.2=0
                          __unix=0=0
                          __archspec=1=arm64
       base environment : /opt/homebrew/Caskroom/miniforge/base  (writable)
      conda av data dir : /opt/homebrew/Caskroom/miniforge/base/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/osx-arm64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /opt/homebrew/Caskroom/miniforge/base/pkgs
                          /Users/joy/.conda/pkgs
       envs directories : /opt/homebrew/Caskroom/miniforge/base/envs
                          /Users/joy/.conda/envs
               platform : osx-arm64
             user-agent : conda/22.9.0 requests/2.28.1 CPython/3.10.8 Darwin/22.3.0 OSX/13.2
                UID:GID : 501:20
             netrc file : None
           offline mode : False
timmermansjoy commented 1 year ago

I see that the bug tag got moved to 3rdparty. So I also tried to install It from the script in Unix-like platform after this, I just get the same behaviour. also removed conda piece in the .zshrc a couple of times. but still gives issues there

Screenshot 2023-01-30 at 09 40 49

hmaarrfk commented 1 year ago

Thank you for trying to install it using our recommendations. I truly appreciate it. I don't have a mac so troubleshooting is difficult for me.

Can you try one more thing:

  1. Can you confirm that you've uninstall it from homebrew.
  2. Can you uninstall /Users/joy/mambafore/
  3. Can you confirm, that there is nothing related to conda in your /Users/joy/.zshrc
  4. Open a new shell Can you provide the output of
    echo $SHELL
    env | grep CONDA

Please check the output of env for anything sensitive you might want to remove. I'm mostly interested in any variables that are prefixed with CONDA that may exist.

Then can you try to reinstall.

After the reinstall, please show us the contents .zshrc file that you've shown before.

timmermansjoy commented 1 year ago

Screenshot 2023-02-09 at 09 47 21

first pic of everything deleted

Screenshot 2023-02-09 at 09 49 50

second pic is after installing conda with the unix like instructions and afterwards

the full file is

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

export DOTFILES=$HOME/.dotfiles
export HOMEBREW_BREWFILE=~/.dotfiles/specific/homebrew/Brewfile
SYSTEM_CONFIG=$DOTFILES/basic/system/index.zsh

export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/sbin:$PATH"

# https://unix.stackexchange.com/a/151896/148053 - I don't understand, but it is what it is
local function _source () {
  local -r FILE="$1"
  shift
  source "$FILE" "$@"
}

local function source_local () {
  if [[ -a $DOTFILES/.local ]]; then
    _source $DOTFILES/.local
  fi
}

local function source_system () {
  _source "$SYSTEM_CONFIG"
}

function source_non_system () {
  typeset -U FILES

  FILES=($DOTFILES/basic/*/index.zsh $DOTFILES/specific/*/index.zsh)

  for FILE in $FILES; do
    if [ $FILE != $SYSTEM_CONFIG ]; then
      _source $FILE
    fi
  done

  unset FILES
}

function source_extensions () {
  typeset -U FILES

  if find $DOTFILES/extensions -name 'index.zsh' -not -path '*.git*' &> /dev/null; then
    # include any extensions if present
    FILES=($FILES $DOTFILES/extensions/*/*/index.zsh)
  fi

  for FILE in $FILES; do
    if [ $FILE != $SYSTEM_CONFIG ]; then
      _source $FILE
    fi
  done

  unset FILES
}

source_local # load local-only variables (not commited)
source_system # first source the system config, which sets critical variables...
source_non_system # ...then sources other config files
source_extensions

# initialize autocomplete here, otherwise functions won't be loaded
autoload -U compinit
compinit

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

# To customize prompt, run `p10k configure` or edit ~/.dotfiles/specific/oh-my-zsh/p10k.zsh.symlink.
[[ ! -f ~/.dotfiles/specific/oh-my-zsh/p10k.zsh.symlink ]] || source ~/.dotfiles/specific/oh-my-zsh/p10k.zsh.symlink

# helps with some wierdness in pip
export LDFLAGS="-L/opt/homebrew/opt/freetds/lib -L/opt/homebrew/opt/openssl@3/lib"
export CFLAGS="-I/opt/homebrew/opt/freetds/include"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/joy/mambaforge/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/joy/mambaforge/etc/profile.d/conda.sh" ]; then
        . "/Users/joy/mambaforge/etc/profile.d/conda.sh"
    else
        export PATH="/Users/joy/mambaforge/bin:$PATH"
    fi
fi
unset __conda_setup

if [ -f "/Users/joy/mambaforge/etc/profile.d/mamba.sh" ]; then
    . "/Users/joy/mambaforge/etc/profile.d/mamba.sh"
fi
# <<< conda initialize <<<

and full installation can be found here: https://github.com/timmermansjoy/dotfiles.git

hmaarrfk commented 1 year ago

I'm really not sure. sorry. this is beyond me. :/ You seem to have done everything right according to me.

@conda-forge/help-osx-arm64 (sorry there doesn't seem to be a generic help osx group)

erykoff commented 1 year ago

I don’t know what that power 10k shell thingy is but the warning makes me wonder if it’s swallowing some functionality that the conda initializer expects? Have you tried either commenting that out or putting the conda stuff above it?

timmermansjoy commented 1 year ago

@erykoff its just a theme for the terminal https://github.com/romkatv/powerlevel10k I doubt it has influence

kevinkyyro commented 1 year ago

I'm having this issue as well. It looks like conda shell.zsh hook is generating a script that looks like

export CONDA_EXE='/usr/local/Caskroom/miniforge/base/bin/conda'
export _CE_M=''
export _CE_CONDA=''
export CONDA_PYTHON_EXE='/usr/local/Caskroom/miniforge/base/bin/python'

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

__conda_exe() (
    "$CONDA_EXE" $_CE_M $_CE_CONDA "$@"
)

__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"
        \unset CONDA_PS1_BACKUP
    fi
    \local ask_conda
    ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix "$@")" || \return
    \eval "$ask_conda"
    __conda_hashr
}

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

conda() {
    \local cmd="${1-__missing__}"
    case "$cmd" in
        activate|deactivate)
            __conda_activate "$@"
            ;;
        install|update|upgrade|remove|uninstall)
            __conda_exe "$@" || \return
            __conda_reactivate
            ;;
        *)
            __conda_exe "$@"
            ;;
    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

conda activate base

The \s didn't look right to me, so I removed them with a tweak to my .zshrc and it seemed to fix it:

-__conda_setup="$(/usr/local/Caskroom/miniforge/base/bin/conda shell.zsh hook 2> /dev/null)"
+__conda_setup="$(/usr/local/Caskroom/miniforge/base/bin/conda shell.zsh hook 2> /dev/null | sed 's/\\//g')"
aisven commented 11 months ago

Same issue under MacOS Ventura 13.3.1.

When running conda init zsh it is always:

no change /Users/******/.zshrc

arthur-c commented 11 months ago

Same issue under MacOS Ventura 13.3.1.

When running conda init zsh it is always:

no change /Users/******/.zshrc

Same issue, solved by uncommenting this block present in my zshrc:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/homebrew/Caskroom/miniconda/base/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/homebrew/Caskroom/miniconda/base/etc/profile.d/conda.sh" ]; then
        . "/opt/homebrew/Caskroom/miniconda/base/etc/profile.d/conda.sh"
    else
        export PATH="/opt/homebrew/Caskroom/miniconda/base/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

other workaround:

/opt/homebrew/Caskroom/miniconda/base/bin/conda shell.zsh hook >> ~/.zshrc
jezdez commented 11 months ago

It would be beneficial to file this upstream in the conda/conda repo

franzcrs commented 3 months ago

Hello, I knew that installing any version of conda might cause trouble in Macs with the Apple Silicon, so I looked out there for clear instructions for my case (M1), and the steps in this repository worked for me, twice (MacBookPro M1 and Macmini M1): https://github.com/mrdbourke/m1-machine-learning-test#how-to-setup-a-tensorflow-environment-on-m1-m1-pro-m1-max-using-miniforge-shorter-version

When the installation is over, remember to write 'yes' to add conda to your PATH

The version of miniforge that the repos direct to seems to be the latest release of miniforge: https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh And the installation I did in Macmini a couple of days ago worked fine.