0

I am running macOS Big Sur 11.1 on MacBook Air M1. It comes bundled with Python 3.9.1 for regular usage and running python command through terminal says that I have Python 2.7.16 for compatibility with legacy software.

I want to install TensorFlow which specifically requires Python 3.8. So, if I upgrade Python 2.7.16 to Python 3.8 will it cause trouble with legacy software? If no, then is it a good idea to do this upgrade? If yes, can you please tell me the procedure? I don't find a pip installed on my machine but there is a pip3 to work with Python3.

Also, is there a way to find the list of software/packages installed on my machine that require Python 2.7.x to work?

2
  • python3 gives me 3.6.6 – Thorbjørn Ravn Andersen Dec 22 '20 at 18:14
  • On Big Sur 11.1 python3 is not installed by default to get it you need Xcode command line tools (macOS will tell you that if you try to run it). Xcode gives my python 3.8 – mmmmmm Jan 20 at 11:52
1

A bit of background

Python2 and 3 are in many ways separate languages. For configuration and use definitely consider them as separate. The code you read and write is very similar though.

Python 2 is not supported (by python.org) from 1/1/20. That is no bug fixes etc. So you should not be using it.

Due to the difference you need separate pip versions. The standard macOS way is pip and python are links to the Python 2 versions. python3 and pip3 are the links to the Python 3 versions.

As usual with software supplied with macOS you do not upgrade Apple versions of software. However you can install other versions as well as the Apple versions. In fact the normal advice from python users is not to use Apple's versions but use another one.

Installation

The alternatives are install via a general package manager e.g. MacPorts, HomeBrew, Fink or from python bases managers python.org or I use Conda especially if you use numpy etc. (it does have a version of tensorflow). python now comes with pyvenv and other tools to allow you to chose which version to use for a particular project, conda has a similar way of doing this, macports has a simple link allowing choice of one version or another globally and not by project.

Existing scripts

There is no absolute way of seeing what uses python 2. However a reasonable guess is to look at the first line of each python file for the hash bang invocation. This tends to be #!/usr/bin/python or #!/usr/bin/env python for scripts that use python 2 - scripts using python3 will have 3 in the line.

Apps

Again no consistent way.

However the Apple recommendation is for apps that use an interpreter or runtime is to embed the interpreter into the app bundle - thus it is up to the application supplier to deal with python versions etc and the user does not need to and probably should not alter how the app is run.

1

You can install Python 3.8 using homebrew. The instructions to install homebrew are on homebrew's home page. Currently the instructions are entering into a terminal window: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

The instructions to install Python 3.8 are on the homebrew page for Python 3.8. Once you've installed homebrew, enter into a terminal window brew install python@3.8

This won't replace your stock Python installations, it will be installed into a separate location to avoid causing problems with stock legacy software. User legacy software may require you to explicitly specify the full path for the version of python it requires.

I'm not aware of a method to find all software that uses the stock versions of Python.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .