I am running Mac 10.9 Mavericks and have installed Anaconda. However, despite that, when I access python via terminal, I still get the default Apple version:
Python 2.7.5 (default, Sep 2 2013, 05:24:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
My .bash_profile is this:
export PATH="$HOME/anaconda/bin:$PATH"
MONGO_PATH=/usr/local/mongodb/bin
SQL_PATH=/usr/local/mysql
export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
Is there anything I can do to use the Anaconda version of Python? At a loss at the moment.
Thank you
The first matching executable is the one that is run. From what I can gather you are concatenating your PATH variable in such a way that:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
comes before:
$HOME/anaconda/bin
So make sure that the anaconda directory is the first one, meaning that it will have precedence:
export PATH="$HOME/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
If you are using fish, you can find Anaconda backup your old .bash_profile as .bash_profile-anaconda.bak, and it added 2 lines at the bottom of .bash_profile which looks like this:
# added by Anaconda2 4.1.1 installer
export PATH="/Users/username/anaconda/bin:$PATH"
However fish does not read it, so you have to add it in fish config file manually, which is in ~/.config/fish/config.fish:
set -x PATH /Users/username/anaconda/bin $PATH
if you are using zsh you can edit in your zshrc file in your root folder to include
export PATH="$HOME/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
If you use LiClipse or Eclipse as your IDE, the Preferences menu will allow this management process to go much easier. But I understand the joy of the command line.
It is super easy to make Anaconda, or rather Anaconda's Python version the default interpreter in LiClipse, as well as call the site-packages from Anaconda. I just set it up today.
Regards,
JF
Update for all people seeing this with Python 3: above solutions will not work with Python 3.
Anaconda's Python 3 is now at ~/anaconda3/bin
. So instead do:
export PATH="$HOME/anaconda3/bin:$PATH"
or
export PATH="$HOME/anaconda3/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
Make sure you are using the full path: - don't use "~" instead of the root:
(wrong)
export PATH="~/anaconda/bin:$PATH"
(Correct)
export PATH="$HOME/anaconda/bin:$PATH"
This change worked for me!
来源:https://stackoverflow.com/questions/22773432/mac-using-default-python-despite-anaconda-install