How to upgrade from python 2.7 to python 3.1 on macOS Mojave

I have tried to install python 3 both via homebrew and the python website. Neither works. When trying through homebrew I got:
~ brew install python3
Warning: No available formula with the name “ca-certificates”.
==> Searching for similarly named formulae…
Error: No similarly named formulae found.
==> Searching for a previously deleted formula (in the last month)…
Error: No previously deleted formula found.
==> Searching taps on GitHub…
Running brew update --preinstall
Error: No formulae found in taps.

I tried also upgrading homebrew and got:
~ brew update
Warning: No available formula with the name “ca-certificates”.
==> Searching for similarly named formulae…
Error: No similarly named formulae found.
==> Searching for a previously deleted formula (in the last month)…
Error: No previously deleted formula found.
==> Searching taps on GitHub…
Error: No formulae found in taps.
fatal: Could not resolve HEAD to a revision
Already up-to-date.

I also downloaded python from the python website, and got a folder python 3.1 but when I try to type python --version in the terminal it only returns python 2.7.16.

Can someone help with this?

It looks like there is something wrong with your Homebrew installation.

You should probably ask your question on their forum as they would be better equipped to help you:

Also, if you installed Python 3 from an installer on python.org, you need to type python3 in your terminal, not python.

1 Like

As @J-M0 mentioned, it seems like something’s wrong with your Homebrew install; you’ll likely want to reinstall it. Also, just to note, the current version downloaded from the Python website should be 3.10, not 3.1; this official guide on installing and using it on macOS looks at least somewhat up to date, at least in the most important parts.

1 Like

Are you aware that MacOS ships with a Python 3, which would have been
pretty current when the OS was released? You just need to type “python3”
to invoke it instead of “python”.

Plain “python” will get you Python 2 because to do otherwise might break
a large suite of Python 2 scripts - this is a significant transition for
vendors (shippers of OSes and utilities etc, eg Apple with MacOS) both
because they have a large existing base of Python code to maintain and
also because end users will have scripts invoking “python” and those
scripts should not break with an OS update.

Usually you can invoke “python2” to get Python 2 and “python3” to get
Python 3.

Also, these commands will tell you which executables are being run when
you do that:

which python2
which python3

Because of this, you may not need to install an additional Python 3 from
homebrew or the python.org installers.

Cheers,
Cameron Simpson cs@cskk.id.au

1 Like

macOS Catalina (10.15) and newer has stubs that will install Python 2 and Python 3 if the user invokes them, via installing the macOS developer tools, and has neither version installed or “default”. However, as stated in the title, the user is running Mojave (10.14), so their options are Python.org or Homebrew.

1 Like

Hmm, I had thought otherwise. But checking some Macs here shows that you
are correct.

Apologies,
Cameron Simpson cs@cskk.id.au

2 Likes

Thank you everyone for the help I ended up reinstalling homebrew. Only to find out that I had already successfully downloaded python but I didn’t check python3 --version haha.

1 Like

The problem is that there’s many different which-es, each with different options and behaviors.

POSIX-confirming shells (incl zsh and bash) are required to have a builtin confusingly called command . This is more portable solution i.e. not depending so much on which version of which installed. If used with -V argument one can get ‘human readable’ information. Example from my machine on different python versions:

+ > command -V python
python is aliased to `python3.7'
+ > command -V python3.8
python3.8 is /usr/local/bin/python3.8
+ > command -V python3
python3 is aliased to `python3.10'