2

After following these steps and installing conda it seems that conda init updates my .bash_profile incorrectly for some reason. It adds it's content AFTER running .bashrc and thus when bash gets started all my conda stuff does not get initiated correctly for some reason. I ended up having to change the .bash_profile manually to look like this:

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

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

The way I installed it was using what I thought was the official installation:

sh Anaconda3-2020.02-MacOSX-x86_64.sh

but that seems to be causing issues (e.g. conda init bash not adding the stuff in the right place to .bash_profile. The graphical/dmg installer even installs things at ~/opt for some reason). I outlined the hacky solution that worked for me here but I assume that is not the right way to be doing things.

What is causing my problems and how do I fix it?

Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
  • How is this related to programming? Why would anyone here debug their broken installation script? – oguz ismail Mar 28 '20 at 18:34
  • 2
    `conda` isn't doing any sort of analysis of your `.bash_profile`; it's just appending its block to the end of the file. If your `.bashrc` contains something that requires it be sourced after the `conda` initialization, it's your responsibility to adjust `.bash_profile` as necessary. – chepner Mar 28 '20 at 19:22
  • very related: https://stackoverflow.com/questions/70307161/why-is-python-using-3-8-1-and-3-9-then-fail-to-install-packages-error-package?noredirect=1#comment124283809_70307161 – Charlie Parker Dec 10 '21 at 16:40

1 Answers1

2

As the comment by chepner says as I discovered on my own eventually is that conda init doesn't work out of the box for some reason (e.g. if it modifies .bash_profile it's obvious the user will run their .bashrc file somewhere there so it should add it's contents correctly before that, or at least in imho). Anyway this is an example of a working file:

(automl) brandBrandoParetoopareto~/automl-meta-learning $ cat ~/.bash_profile 
echo ----Running .bash_profile

conda -V
python -V
echo $PATH
echo $PATH | tr ":" "\n"

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

echo ----Completed running .bash_profile

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

after I manually changed it.

I would have not guessed I needed to modify these things myself. Perhaps I should not trust commands/installers etc and see what the output to their terminal is more often.


Also, things are worse if your using the integrated terminal in vscode like I was. For that read this to avoid errors/strange behaviours: https://code.visualstudio.com/updates/v1_36#_launch-terminals-with-clean-environments

Launch terminals with clean environments The Integrated Terminal in VS Code has always acted a little differently to normal terminals, particularly on Linux and macOS. The reason is that the environment was always inherited from VS Code's window (instance) and VS Code/Electron-related environment variables were removed, whereas a normal terminal would typically be launched from the Dock/Start menu and use the system environment. This could cause issues in certain scenarios, for example Python virtual environments were broken because of how they use the $PATH variable.

There's a new preview option, terminal.integrated.inheritEnv, that when false causes the terminal to not use VS Code's environment.

Instead, depending on the platform, it will do the following:

Linux: Fetch and use the environment of the parent process of VS Code's "main process". macOS: Pull a handful of important environment variables off the current environment and only include them. Eventually we would like macOS to behave the same as Linux but there are currently issues with fetching environments. Windows: Currently this setting does not affect Windows. The main visible result of setting inheritEnv to false is that $SHLVL (shell level) should now be 1 and $PATH should not include duplicate paths, provided your launch scripts don't intentionally include them.

The default value for terminal.integrated.inheritEnv is true, which is the previous behavior, but we will probably switch the value to false in the future.

also closing and opening vscode completely seems to be helpful.

Hopefully, this will save people's days of changing bash files around and re-installing and uninstalling a bunch of things.

Another helpful tip is to go the top left of vscode where it says code click it then go to preferences and then settings. Then you can change the terminal.integrated.inheritEnv to false by unclicking/selecting it.

Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
  • 1
    It's not at all obvious that the user will source `.bashrc` at the end of file. There is *nothing* standard that `conda` could know to look for. All it can do is *append* its block to the end of the file, and let the user put it where it belongs relative to *their* existing code. – chepner Apr 27 '20 at 19:21
  • @chepner I was under the impression it was standard to source `.bashrc` after `.bash_profile` is ran. Perhaps I was mistaken (why I thought it would be `obvious`). Perhaps it would be nice if conda asked the user before appending to it where it would go. Idk, perhaps I am the only person that thought it's standard to run `.bashrc`. – Charlie Parker Apr 27 '20 at 19:33
  • 1
    To be honest, it would be much simpler if the documentation simply stated *what* is necessary, and leave it up to the user to determine which file, and where in that file, the code needs to be placed. – chepner Apr 27 '20 at 20:19
  • 1
    @chepner it is very frustrating that conda never tells us at any point where to append that. Conda init just does it blindly and creates many issues. Wish somewhere it said where that should go in general. – Charlie Parker Dec 10 '21 at 16:58