0

I just installed Python 3.5 on my Mac OS Sierra and update my .bash_profile file:

MacBook:~ admin$ more .bash_profile

# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH

When I check if the PATH is correctly set, I have the below output:

MacBook:~ admin$ echo "$PATH"
/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet

However, when I run Python from a terminal, Python 2.7 is still executed:

MacBook:~ admin$ python --version Python 2.7.12
MacBook:~ admin$ which python /usr/local/bin/python

How can I use Python 3.5 by default?

5
  • 4
    I would advise against doing this. Make a symlink for python3, and leave the system default version alone. Commented Nov 9, 2016 at 20:19
  • 6
    It's just one more character to type python3 Commented Nov 9, 2016 at 20:20
  • 4
    Use virtualenv or something like that, so you don't mess with the default interpreter (you may even break your system if some tools depend on 2.7). Commented Nov 9, 2016 at 20:20
  • 2
    I double @PauloScardine . I'd rather install a virtualenv with Python 3.5 and make it load automatically when firing a terminal session Commented Nov 9, 2016 at 20:35
  • From experience don't do that. Did a similar thing on mac with Ruby ended up rolling back the whole machine with the time machine backup. If you do at least name it to something else then python. Commented Nov 9, 2016 at 20:36

1 Answer 1

3

I believe that your surprise comes from the shell searching /usr/bin before it tries your PATH. You really do not want to mess with that part, but you can work around it with a simple alias. Something like

alias python='/Library/Frameworks/Python.framework/Versions/3.5/bin/python'

... should do the trick. However, I recommend that you choose a name other than python, such as pyth or py3.

Sign up to request clarification or add additional context in comments.

2 Comments

... which is handled in a previous comment.
True. But I think most popular *nix environments already come with a python3, usually pointing to a python 3.4 interpreter. It's been a while since I've used Mac OS, although, I might be returning to it soon.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.