2

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`
bfontaine
  • 18,169
  • 13
  • 73
  • 107
kanja klub
  • 121
  • 1
  • 1
  • 12
  • I wouldnt worry too much about the minor version of your python installation – Alan Kavanagh Aug 17 '17 at 20:15
  • I'm having pip installation errors on language-check, I'm looking here and some of the answers mention fixes on newer minor versions: https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error#comment72358900_42334357 – kanja klub Aug 17 '17 at 20:18
  • So I want to make sure I'm using the newer versions when I'm installing via pip – kanja klub Aug 17 '17 at 20:20
  • @kanjaklub, I don't have a Mac, but I'm betting you have a PATH problem there. Looks like you have both installed, but the one on the PATH is not what you want. Does Mac have `locate`? If so, try running `locate bin/python`, and see what it returns. – caxcaxcoatl Aug 17 '17 at 20:28
  • 1
    `brew` installs into `/usr/local/bin` by default. Your shell uses your `PATH` configuration to find binaries, it looks like you did not configure it to include `/usr/local/bin`. – Martijn Pieters Aug 17 '17 at 20:29
  • You can use the full path to the binary to force the issue: `/usr/local/bin/python3`. – Martijn Pieters Aug 17 '17 at 20:29
  • Use `which` to tell you what binary was used when you just state the `python` or `python3` commands, e.g. `which python3`. If you use the `-a` command-line switch all binaries available via your `PATH` are listed: `which -a python3`. – Martijn Pieters Aug 17 '17 at 20:31
  • `which -a python3` outputs `/Library/Frameworks/Python.framework/Versions/3.6/bin/python3 /usr/local/bin/python3` – kanja klub Aug 17 '17 at 21:05
  • Here is my `$PATH`: `-bash: /Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin: No such file or directory` – kanja klub Aug 17 '17 at 21:05
  • Here is what I get with `locate bin/python`: `WARNING: The locate database (/var/db/locate.database) does not exist. To create the database, run the following command: sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist Please be aware that the database can take some time to generate; once the database has been created, this message will no longer appear.` – kanja klub Aug 17 '17 at 21:06
  • plz update the python - plz do so – zero Mar 13 '23 at 21:49

3 Answers3

3
❯ 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.

Violet Red
  • 211
  • 1
  • 4
2

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.

PhilS
  • 245
  • 7
  • 16
1

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.

kanja klub
  • 121
  • 1
  • 1
  • 12