1

Typing Python on my Terminal shows

Python 3.9.5 (default, May  4 2021, 03:36:27) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

When in fact I have installed the latest version, 3.10.6, which shows when I type python3 --version. Typing just python --version returns 3.9.5 again. It seems that the default version is 3.9.5 and not updated, or am I wrong? Either way, how do I solve this? I've tried both downloading and installing it directly, as well as through brew install ..., both giving successful installs, but not updating the default version (3.9.5 -> 3.10.6)

EconNoob
  • 13
  • 4
  • Uninstall all versions and reinstall? – TheMaster Aug 15 '22 at 16:20
  • Having multiple Python versions on your computer is always a headache... Try `which python` and `which python3` to see where their executables are respectively, that might help you troubleshoot. – lancylot2004 Aug 15 '22 at 16:23
  • Notice that [`which` is hardly ever the right tool](https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then) (unless one is using tcsh). The person asking, judging by their use of Homebrew and Terminal, seems to be on a Mac, which, on modern versions of macOS, means the default shell is zsh, where `whence -v` is more appropriate. – Ture Pålsson Aug 15 '22 at 16:30
  • @lancylot2004 ```which python``` gave me ```/usr/local/opt/python@3.9/libexec/bin/python``` while ```which python3```gave ```/opt/homebrew/bin/python3``` ... I'm not good at using the terminal at all, I just code and that's it, so I'm kind of clueless as to how to solve this – EconNoob Aug 15 '22 at 16:32
  • @TurePålsson I used ```whence -v python``` and got in return the same as when using ```which python``` but with "python is" added in the beginning. Also typed ```whence -v python``` and it again returned another path – EconNoob Aug 15 '22 at 16:35
  • The first one, `.../python@3.9/libexec/...` is the system Python, and you can't really touch it (without consequences). There are a few solutions depending on what you want, like using links, removing some of the installs, or using a manager like `conda` or `pyenv`. Explaining all of them is not a good idea, so here's a starting point: [random article](https://opensource.com/article/19/5/python-3-default-mac) – lancylot2004 Aug 15 '22 at 17:04
  • You need to set your `PATH`. `brew` doesn't normally set up unversioned symlinks (e.g., `python` instead of `python3`) because it can get confusing, especially if you run both python2 and python3. It _sounds_ like you actually had an older homebrew install of Python 3.9 that was installed to `/usr/local/opt` (which is where brew puts things on x86 MacOS, but it uses `/opt/homebrew` for Apple Silicon Macs...). I think you're going to have to clean up `/usr/local/opt` or remove it from your `PATH`. – wkl Aug 15 '22 at 17:04
  • @lancylot2004 MacOS system python is not installed to `/usr/local/opt`, and the latest version they use is `3.8.9` anyway (in Monterey 12.5). – wkl Aug 15 '22 at 17:17
  • @wkl My bad, noted. – lancylot2004 Aug 15 '22 at 17:17
  • @wkl I've tried setting my ```PATH```, maybe I've done it incorrectly, but I still get Python 3.9.5 whenever I type ```which python``` or simply ```python```. I've tried restarting, but nothing works. I installed Homebrew again, just to make sure. I'll have to google how to remove and cleanup, but googling how to set path didn't help unfortunately. – EconNoob Aug 15 '22 at 18:22
  • @EconNoob in your shell, do this as a test and see if helps. `export PATH="$(brew --prefix python@3.10)/libexec/bin:$PATH"`, and then type `python -V` – wkl Aug 15 '22 at 18:58
  • @wkl It does return ```python 3.10.6```, but when I restart terminal and type ```python -V``` it again returns ```python 3.9.5``` – EconNoob Aug 15 '22 at 19:00
  • @EconNoob yes, what I just showed you is a temporary `PATH` change. In order to change it so that it survives terminal restarts/reboots, you have to modify your `~/.zshrc` file and put that line somewhere near the bottom. – wkl Aug 15 '22 at 19:01
  • @wkl Thanks! I created the ```~/.zshrc``` file and opened it using the terminal, and replaced the previous path that was there with ```export PATH="$(brew --prefix python@3.10)/libexec/bin:$PATH"``` and it works now. I don't know why, but I can't seem to accept your answer, or maybe I don't see where it's supposed to be – EconNoob Aug 15 '22 at 19:21
  • Comments aren't answers, which is why you can't accept anything. :) – wkl Aug 15 '22 at 19:22

1 Answers1

0

The solution, as provided in the comments, was to create a ~/.zshrc file (How to create a ~/.zshrc file) and then to replace the existing path with export PATH="$(brew --prefix python@3.10)/libexec/bin:$PATH"

EconNoob
  • 13
  • 4