0

When I type python --version, the output is "Python 2.7.18" I tried python3 --version, and the output is Python 3.10.4, how can update python to 3.10 without creating python 3?

I was expecting python's version to be 3.10.x and I tried brew upgrade, it didn't work. I'm on mac montery btw

Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61
Jimmy Zeng
  • 37
  • 1
  • 7

3 Answers3

0

Try this

`vi ~/.bash`

Then type out

alias python=python3

Save your file by pressing Esc -> type :wq

Then to update your shell environment

source ~/.bash

Another way you could try if you know what you are doing, is to go straight to your .bash_profile or .bashrc and write direct into it:

export PATH="/usr/local/opt/python@X.Y/libexec/bin:$PATH"

change X and Y to your python version

0

Linux based system comes with Python 2 pre-installed for compatibility with legacy software. It's not recommended to make changes on it yourself. You might be breaking something.

For now, if you want to use Python 3, your option is to use the python3 command.

Alternatively, you may try the recently released (march, 14th) macOS Monterey 12.3. Acordinly to it's Release Notes, they are dropping the python 2 from the system. In this case, you should be able to safely install Python 3 and use it as just python at the command line.

Ian Andwati
  • 333
  • 2
  • 9
  • The answer declared some reason why python2 should not be changed. But the asker may want to find a way to using python command to refer the python3, and alias may be what he wanted. – Jason Pan Mar 30 '22 at 04:49
0

The python 2 version is used by the system and it's recommended that you don't mess with it becauseyoua can seriously damage your ability to use your operatingsystem.

If you feel like you need to manage multiple python versions in your system you can use pyenv

This article here also simplifies the installation

Ian Andwati
  • 333
  • 2
  • 9