-1

My problem is that when I check the python3 version I get 3.6.0 but when I install python3 with HomeBrew it tells me that I have python 3.6.3. installed. How do I get my computer to tell me that I have python 3.6.3 when I use the python3 --version command? As you can see in the image, that is the problem that I have, how do I fix it?

python3: stable 3.6.3 (bottled), devel 3.7.0a3, HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python3/3.5.2_3 (7,720 files, 109.4MB) 
Built from source on 2016-11-14 at 18:24:57
/usr/local/Cellar/python3/3.6.3 (7,973 files, 111MB)
Built from source on 2017-12-15 at 10:26:40
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python3.rb

After I typed `brew info python3' then I got the output that you see in the above image.

wireless-10-105-105-109:~ johnhsu$ echo $PATH

/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/local/sbin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

' Also when I checked what path i have, this is what I got. Which looks very different than what it is supposed to look like, maybe?

When I enter a command which python3 it does this.

Johns-Air:~ johnhsu$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3

However, when I use 'brew info python3', it gives me this:

/usr/local/Cellar/python3/3.5.2_3 (7,720 files, 109.4MB)
  Built from source on 2016-11-14 at 18:24:57
/usr/local/Cellar/python3/3.6.3 (7,973 files, 111MB) *
  Built from source on 2017-12-15 at 10:26:40
C Hobbs
  • 59
  • 1
  • 2
  • 12

2 Answers2

0

You have installed two python versions side-by-side and OSX takes the other version as default.

brew doctor should confirmed that, as explained here.

What you'd need to do is to put edit your .bashrc to put: /usr/local/bin ahead of /usr/bin in your $PATH.

hansaplast
  • 11,007
  • 2
  • 61
  • 75
  • Johns-Air:~ johnhsu$ which python /Library/Frameworks/Python.framework/Versions/2.7/bin/python Johns-Air:~ johnhsu$ which python3 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 Johns-Air:~ johnhsu$ I get this result when I ask which python3 – C Hobbs Dec 16 '17 at 14:53
  • @CalvinVanHobbes so `brew doctor` did not fix your issue then..? – hansaplast Dec 16 '17 at 15:50
  • yeah, brew doctor didn't fix my problem because my path doesn't point to Homebrew – C Hobbs Dec 17 '17 at 00:49
  • 1
    @CalvinVanHobbes: oh, silly me. `brew doctor` just *shows* the problem, the problem is solved with adapting path. I now updated my answer – hansaplast Dec 17 '17 at 06:47
0

The problem is your PATH, but don't just go changing it at random... Actually look what you've added to it.

In order of resolution

The system Python2.7 - /Library/Frameworks/Python.framework/Versions/2.7/bin

The system Python3.6 - /Library/Frameworks/Python.framework/Versions/3.6/bin

Maybe your Homebrew installations - /usr/local/bin:/usr/local/sbin

The system Python3.5 - /Library/Frameworks/Python.framework/Versions/3.5/bin

The system Python2.7 again - /Library/Frameworks/Python.framework/Versions/2.7/bin

Maybe your Homebrew installations again - /usr/local/bin

All the other system binaries - /usr/bin:/bin:/usr/sbin:/sbin


Whenever you type python3, the first found occurrence of the System Python is run. And I don't think Macs come with Python3 within /Library/Frameworks/Python.framework, so you should at least try to uninstall that.

Even running python3.6 would do the same thing.

You must place your Homebrew bin and sbin directories first on the PATH

Personally, I stopped using Homebrew for Python and use pyenv

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245