Python

How to get the latest version of Python on your Mac - The right way! by Andrew B. Powers

pythonlogo.jpg

How to install the latest version of Python on Mac OS (Big Sur)? A walk through for you!

If you run into this error…

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue. To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.

…you have a problem with your Python installation!

Why you get this error message?

Python on a Macintosh running Mac OS is in principle very similar to Python on any other Unix platform. By default Mac OS comes with a Python 2.7 pre-installed by Apple, because several parts of the Mac OS rely on Python 2.x scripts, that Apple haven't updated yet. So the “for legacy purposes” is as much for Apple as any third-party scripts. Unfortunately it's either somewhat or very out of date, especially if you need Python 3.x.

How to fix it and overriding the old default pre-installed version?

I used Homebrew to (re)install Python and it’s really easy. Here is how to do this…

Open the terminal and enter this line to update Homebrew:

> brew update

To (re)install Python, run this command:

> brew install python

To see which version of Python your Mac is recognizing, enter this:

> python --version

It is still recognized only Python 2.7.17, you have to run the following command:

> brew info python

It told you the path to the newly installed Python 3.x.x. and this is what the command returned to you in terminal:

pyhtonhomebrewversion.png

Now you have to change the path to Python in order for your Mac to recognize the just installed current version. So you have to add the following line at the bottom of the .zshrc file, to update the path to the new (re)installed version of Python 3.x.x via Homebrew:

> export PATH=/usr/local/opt/python/libexec/bin:$PATH

Then you make sure to quit the terminal window and go back in, so that the path would actually be updated in a new terminal window instance. Now check what version of Python was recognized, with:

> python --version

And this is what executed command returned:

Python 3.x.x

Yeah, success! That was quit simple, right!?
Happy coding!

 

Do you have any recommendations or personal guidelines that you find helpful?

Please feel free to comment and share your thoughts on “How to get the latest version of Python on your Mac - The right way!”.


If you like my work or the free stuff and want to say thank you, please use this opportunity now and

 
Buy Me a Coffee at ko-fi.com
 

THANK YOU, very much! 🙏🏻