Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to replace MacOS X default Python interpreter?

I have the default Python 2.6.1 installed as /usr/bin/python and Python 3.1.2 installed in /usr/local/bin/python3.1. Considering that I use only 3.x syntax, is it safe to replace the default interpreter (2.6) with the 3.1 one (python-config included) using symlinks (and removing old Python binary)? Or is the system relying on the 2.x version for some purpose I don't know?

like image 974
Simone Margaritelli Avatar asked Sep 16 '10 01:09

Simone Margaritelli


People also ask

How do I change the default Python interpreter Mac?

Open the terminal (bash or zsh) whatever shell you are using. Install python-3 using Homebrew (https://brew.sh). Look where it is installed. Change the default python symlink to the version you want to use from above.

Which version of Python should I use on Mac?

Future versions of macOS will not include Python 2.7. Instead, it is recommended that you transition to using 'python3' from within Terminal. Until Apple decides to set Python 3. x, as the default you're going to have to install it yourself.

Which version of Python should I use for 2022?

The latest version Python 3.11 is set to release in October this year and the alpha phase is currently ongoing and generally goes on until May 2022.

How do I change Python default interpreter?

Set Default interpreter path in settings; Select "Python: choose interpreter" in command pallete; Check choosed interpreter. It should be Default, but choosed is Recommended.


2 Answers

If you're only using Python 3, start your scripts with:

#! /usr/bin/env python3.1

And you'll be using the right version, without doinking the system about.

edit: BTW this idea is suggested by the Python docs. Each script will be running the version of Python they depend on. Since Python 3 is not backward compatible, it seems dangerous to be replacing the Python executable with one that will break scripts other utilities may rely on.

like image 198
Graham Perks Avatar answered Sep 25 '22 00:09

Graham Perks


You can not safely replace the system supplied python. I cannot find a Mac-specific reference for you... but some recent Python versions are not backwards compatible... Many scripts made dependent on an older version of Python will not run on an upgraded python. OS X Comes with Python pre-installed because it has dependencies on it.

Try using VirtualEnv instead.

Update: Just came across python-select from macports which may solve your problem.

like image 30
Eric Avatar answered Sep 24 '22 00:09

Eric