1

I installed Python 3.9.1 onto my MacBook however when I use the command python --version it says its python 2.7. Here's what going on in my terminal for reference:

$ python -V
Python 2.7.16
$ brew install pyenv
Updating Homebrew...
==> Auto-updated Homebrew!
Updated Homebrew from 565becc90 to e41981a5c.
Updated 1 tap (homebrew/core).
==> New Formulae
htmltest                   mpdecimal                  vitess
==> Updated Formulae
Updated 158 formulae.

==> Homebrew was updated to version 2.7.7
The changelog can be found at:
  https://github.com/Homebrew/brew/releases/tag/2.7.7
Warning: pyenv 1.2.22 is already installed and up-to-date.
To reinstall 1.2.22, run:
  brew reinstall pyenv
$ pyenv install 3.9.1
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.1.tar.xz...
-> https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz
Installing Python-3.9.1...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
       
Installed Python-3.9.1 to /Users/myname/.pyenv/versions/3.9.1

$ 
$ python --version
Python 2.7.16

Thanks in advance for your help!

daisy227
  • 11
  • 1
  • 2

3 Answers3

2

You have to add /usr/local/opt/python/libexec/bin to your PATH.

Checkout Make python3 as my default python on Mac

Samuel Kurian
  • 38
  • 1
  • 4
0

If you have install python they brew then edit your .zprofile

add this line export PATH=/usr/local/opt/brew/opt/python@3.9/libexec/bin:$PATH

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30847604) – Register Sole Jan 21 '22 at 03:43
  • For me personally setting it in .zprofile does not work. As .zprofile is used in login sessions as explained here: https://serverfault.com/questions/901403/zsh-not-sourcing-zprofile#:~:text=zprofile%20is%20only%20sourced%20when,zshrc%20. I ended up adding it in .zhrc but importantly place it before `export PATH="/usr/local/bin:$PATH"` so that our version takes priority. Also you should use export PATH="/usr/local/opt/python/libexec/bin:$PATH" instead of the version one above. – Hasan Wajahat Mar 16 '22 at 07:30
0

list all python under bin

ls -l /usr/local/bin/python*

something like this will be listed

lrwxr-xr-x  1 ali  admin  24 Dec 28 22:27 /usr/local/bin/python3 -> /usr/local/bin/python3.9
lrwxr-xr-x  1 ali  admin  39 Mar 31  2022 /usr/local/bin/python3 -> ../Cellar/python@3.9/3.9.12/bin/python3
lrwxr-xr-x  1 ali  admin  46 Mar 31  2022 /usr/local/bin/python3-config -> ../Cellar/python@3.9/3.9.12/bin/python3-config
lrwxr-xr-x  1 ali  admin  41 Mar 31  2022 /usr/local/bin/python3.9 -> ../Cellar/python@3.9/3.9.12/bin/python3.9
lrwxr-xr-x  1 ali  admin  48 Mar 31  2022 /usr/local/bin/python3.9-config -> ../Cellar/python@3.9/3.9.12/bin/python3.9-config

then change the symlink to the 3.9 or what's new one for you

ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python

Quit the terminal and start it again, it should work now, usually you have to change the symlink for pip too, cause it's under python3 directory.

Ali
  • 71
  • 1
  • 5