0

I have a strange problem with ipython path. When I open a terminal and type which ipython, I get "/Users/test/anaconda3/bin/ipython"

which messes up with some of my definitions. Regardless, when I run source .bash_profile it changes the path to "/usr/local/bin/ipython". Basically, everytime I open a tab, I have to run source .bash_profile for the correct path. These are the contents of my bash file and I have not seen a problem like this before.

export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.

export PATH="/usr/local/bin:$PATH"
# added by Anaconda3 2019.07 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/test/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/Users/test/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/test/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/Users/test/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<
PYTHONPATH="/Users/test/Documents/heasoft-6.25/x86_64-apple-darwin18.2.0/lib/python"
PYTHONPATH="/Users/test/anaconda3/lib/python3.7:$PYTHONPATH"

akaur
  • 389
  • 1
  • 6
  • 22
  • Adding the same lines to `~/.bashrc` probably should solve your problem. – Mihir Luthra Oct 09 '19 at 02:39
  • it is the same as .bashrc. It won't help. I tried it anyways and no luck. – akaur Oct 09 '19 at 02:52
  • 1
    Try moving `export PATH="/usr/local/bin:$PATH"` to the end of your `.bash_profile`. – Mihir Luthra Oct 09 '19 at 02:55
  • 1
    I am unsure about code by anaconda. Probably, when your bash_profile is ran the very first time i.e. anaconda puts its python path on top of your desired one. But the second time you source it, due to `if [ -f "/Users/test/anaconda3/etc/profile.d/conda.sh" ]`, it finds it is already in path and doesn't make any changes. So your path has `/usr/local/bin` on top in that case. – Mihir Luthra Oct 09 '19 at 02:58
  • 1
    yes, thank you so much. You were right. The ```if``` loop was the issue. I moved all my path definitions after the if loop. Now, it has anaconda path plus the others. – akaur Oct 09 '19 at 03:19

1 Answers1

1

This is not a bug or a problem. It's an expected behavior that /Users/test/anaconda3/bin/ipython prioritize /usr/local/bin/ipython.

This is because the "base" Python environment from Anaconda/Miniconda, /Users/test/anaconda3/bin, is prepended in the PATH.

The following content in your .bash_profile is the conda initialization script, which makes sure command conda works properly.

# added by Anaconda3 2019.07 installer
# >>> conda init >>>
...
# <<< conda init <<<

And one of the default behavior of initialization of conda is to expose its "base" Python environment.

All you need to do is disable the activation of "base" Python environment.

Solution

  1. Remove the above conda initialization script in .bash_profile. Replace it with

    # only expose the `conda` command but not the "base" environment
    export PATH="/Users/test/anaconda3/condabin:$PATH"
    
  2. Disable activation of the "base" Python env by running following command in a new interactive shell.

    # re-generate init script
    conda init
    # disable activation of "base" environment
    conda config --set auto_activate_base false
    

References

Simba
  • 23,537
  • 7
  • 64
  • 76
  • Thank you so much. @Mihir suggested along similar lines, but thanks for the descriptive answer. – akaur Oct 10 '19 at 04:20