kanja klub
kanja klub

Reputation: 131

Which python am I using?

Having trouble making sure I'm actually using the latest versions of Python even though they are already installed via homebrew.

$ brew upgrade python3
Error: python3 3.6.2 already installed

but:

$ python3 --version
Python 3.6.0

same goes for python2:

$ brew upgrade python
Error: python2 2.7.13_1 already installed

$ python --version
Python 2.7.10`

Upvotes: 3

Views: 52524

Answers (3)

kanja klub
kanja klub

Reputation: 131

First I modified my $PATH: sudo nano /etc/paths so that /Library/Frameworks/Python.framework/Versions/3.6/bin was not being invoked. I made sure my paths were in the right order so that python looked for /usr/local/bin/python3 and /usr/local/bin/python2 first to force the issue.

However, $ python3 --version still returned Python 3.6.0, though brew says python3 3.6.2 already installed.

brew doctor to the rescue: homebrew recommended a couple things. python was incorrectly symlinked so I ran brew --overwrite python3. Finally, it diagnosed python coming from /Library/Frameworks/Python.framework/Versions/3.6/bin, so I sudo rm -rf /Library/Frameworks/Python.framework. Now python versions are correct.

Homebrew brew doctor warning about /Library/Frameworks/Python.framework, even with brew's Python installed

Thank you everyone for your help.

Upvotes: 1

Violet Red
Violet Red

Reputation: 221

❯ echo `which python`

If this doesn't print '/usr/local/bin/python' (where brew actually installs binaries), then there's something wrong with your $PATH (probably '/usr/local/bin' is not there or it's inserted after '/usr/bin', so the system default python is being run instead).

++ it seems that brew names its python2.7 as python2 by default, and not as python, so you may also need to create a python2->python link in /usr/local/bin directory.

Upvotes: 3

PhilS
PhilS

Reputation: 245

Do you have separate environment variables set up for each?

I have found in the past that having multiple versions of python 2 for example, without all the environment variables, can get quite confusing!

You may find when typing python3, windows is only looking at python 3.0, unless you are in the python 3.6.2 directory.

Upvotes: 2

Related Questions