Python Interpreter on macOS (2024)

Python has made life extremely easy for developers and data scientists, at least most of the time. One exception that ruins their life is dealing with Python versions. There would sometimes be lots of Pythons existing on a Mac at the same time. Where are they from? Are they provided by Apple? Which one am I using? Where did the packages I installed go? This article would give some insights into those questions. This article is NOT for beginners and DO NOT teach you how to install Python. It aims to give you a better understanding of all the Python interpreters you may have on your Mac.

Sure, Python is undoubtedly a programming language, but it is not only a programming language. The name "Python" frequently used in this article would refer to the Python interpreter program most of the time. Unlike C language, which is compiled to machine code and executed by the processor directly, Python is not compiled but interpreted. It means when your Python program is running, there needs to be another program running at the same time, interpreting every line of your Python code to your processor, and the program is THE Python we are talking about in this article.

More specifically, this title means "Which python interpreter program am I using to run my Python program?". Most of the time, you use one of the interpreter programs with the command python or python3. However, it's good to know how many interpreters you have and which one you are currently using with the python command. Here are some ways that help you to find out which python you are using.

The type command

type command tells you how your shell resolves a command, in this case, the command python or python3. It gives the path to the program that is directly involved with a command. In my system, you would see the following outputs.

1
2
frost@ccsmac ~ % type python
python is /usr/bin/python

Take python as an example. It tells you /usr/bin/python is called when you use the command python. However, the path is not necessarily your interpreter's real path: it may be an alias or a trampoline. To see the actual path of the interpreter, you need other commands.

The sys.executable variable

sys.executable gives the absolute path of the executable binary for the Python interpreter you're currently using.

1
2
3
>>> import sys
>>> sys.executable
'/Library/Frameworks/Python.framework/Versions/3.7/bin/python3'

The sys.path variable

It's common for beginners to install the wrong interpreter package and ends up being unable to import the desired package. sys.path is a list of strings that specifies the search path for modules, and it tells where the packages you installed (typically with pip) go.

1
2
3
>>> import sys
>>> sys.path
['', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/frost/Library/Python/3.7/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']

As far as I know, there is currently not an efficient way to find all Python interpreter programs that now exist on your Mac. However, I could still give the common interpreter paths you may expect on your Mac. If you come to find a way to list all interpreters or find a new Python interpreter path that is not mentioned, you are more than welcomed to share it with me.

Built-in Interpreters

Even if you don't install Python explicitly, there may be more than one Python interpreter available on your Mac already. It is not wise to remove or modify these interpreters, and you can only install packages with pip command for the user, not globally. Python you found under /usr/bin is usually system built-in interpreters, files under this path cannot be modified by users without modifying SIP, and it is strongly suggested not to do so. As far as I know, there may be 3 interpreters that are provided by the system.

  • /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7: the Python 2.7 interpreter. Almost all Macs have this interpreter, its alias is located in /usr/bin/python
  • /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7: the Python 3.7 interpreter. From macOS Catalina (reference here), the system gives this interpreter and prompts a deprecation warning when you use the system Python 2.7. It's by default /usr/bin/python3.
  • /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8: a Python interpreter installed by Xcode somehow. As far as I've observed, it overwrites /usr/bin/python3, after that, deleting the Xcode app cause /usr/bin/python3 malfunctions.

User Installed Interpreters

As the built-in interpreters may serve some system functionalities, I prefer to install another interpreter to separate my stuff from the system's interpreter. To install a Python interpreter, you can use Homebrew or install it from python.org. Here are the possible locations of the Python interpreter installed by the user.

  • /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7: the Python interpreter I installed from python.org. One of its aliases is located at /usr/local/bin/python3, and it is what my python3 command refers to.
Python Interpreter on macOS (2024)

FAQs

Is Mac good for coding Python? ›

Python on a Mac running macOS is in principle very similar to Python on any other Unix platform, but there are a number of additional features such as the integrated development environment (IDE) and the Package Manager that are worth pointing out.

Does Mac come with Python interpreter? ›

The Python programming language is widely used for everything from scraping data to building websites, and it was once pre-installed on macOS. Apple stopped including a Python install with macOS when it released Catalina and so now, if you want to use Python on your Mac, you will need to install it yourself.

How to configure Python interpreter in Mac? ›

Setting the default interpreter
  1. Go to File | New Projects Setup | Settings for New Projects (on Window and Linux) or File | New Projects Setup | Preferences for New Projects (on macOS).
  2. Select Python Interpreter settings. Then either choose an existing interpreter from the Python interpreter list of click.
Apr 8, 2024

What is the easiest IDE for Python on Mac? ›

One of the best (and only) full-featured, dedicated IDEs for Python is PyCharm. Available in both paid (Professional) and free open-source (Community) editions, PyCharm installs quickly and easily on Windows, macOS, and Linux platforms. Out of the box, PyCharm supports Python development directly.

Is Mac or Windows better for Python programming? ›

The platform doesn't matter with a language like Python. I use PCs because I use NVIDIA RTX cards in my workflow, but I know some who prefer to work on a 5k iMac because it takes up less space. Do what you like and don't let online people try to make you change your ways.

Is it better to code on Mac or Windows? ›

MacOS is a Unix-based system, similar to Linux, and this imparts certain advantages for programming over Windows. The Unix-style terminal and shell, which are more advanced and have better scripting capabilities, give a smoother experience doing version control, running scripts, and performing other programming tasks.

What interpreter does macOS use? ›

The shell is the command-line interpreter, or language, that will process the commands of the script. Historically, the default shell for macOS was bash. But with the introduction of macOS Catalina Apple changed the default from the bash shell to zsh (zshell).

How do I test Python on my Mac? ›

To check if Python is installed on your macOS machine, follow these steps: Open the Terminal app by going to the Applications folder or Spotlight search and searching for Terminal. In the command line, type python3. If Python is installed, you should see a message like “Python 3.

What is the best Python compiler for Mac? ›

Comparison Table
IDEUser RatingDeveloped in
PyCharm4.5/5JAVA, PYTHON
Spyder4/5PYTHON
PyDev4.6/5JAVA, PYTHON
Idle4.2/5PYTHON
2 more rows

What Python interpreter should I use? ›

Review Python interpreters
InterpreterNotes
AnacondaIf you're unable to decide on an interpreter, we recommend using Anaconda.
PyPyWorks with Visual Studio but with limited support for advanced debugging features.
JythonWorks with Visual Studio but with limited support for advanced debugging features.
2 more rows
Apr 18, 2024

How do I exit Python interpreter on Mac? ›

The exit() and quit() functions can exit a Python program in the terminal for both Windows and macOS. Alternatively, you can use the Ctrl + Z command to exit a Python program in the terminal in Windows and Ctrl + D in macOS. Happy coding!

Is Python installed with Xcode? ›

Python is installed following the steps below: Open Xcode -> open a new project -> choose macOS -> choose a template -> name it - save it. Open file -> go to add package -> type in the search box “http://github.com/pvieito/PythonKit.git”

Should I use PyCharm or VSCode? ›

PyCharm excels with its Python-specific features, ideal for developers immersed in Python's ecosystem. Conversely, VSCode's appeal lies in its versatility, light footprint, and extensive extensions, suitable for multi-language projects.

What is the most used IDE for Mac? ›

The most used IDE for Mac, Windows, and Linux is Visual Studio Code. It is one of the easiest ones to get into.

What is the best Python IDE for beginners? ›

Beginner — IDLE (or Online Python Editors) is the perfect choice for the first steps in python language. PyCharm is also good but takes the help of some experienced person while using this. Intermediate — PyCharm, Sublime, Atom, Vs Code. Advanced — PyCharm, Vim, Emacs, Sublime, Atom, Vs Code.

Which Mac is best for Python? ›

We think the MacBook Pro 14-inch (M3, 2023) is the best MacBook for programming overall, offering the balance between power, price and portability. One of the new MacBook Pros released in November 2023, it's the first 14-inch MacBook Pro to come with the base M chip (in this case the M3) that than a Pro or Max chip.

Is MacBook OK for coding? ›

MacBooks have long been a popular choice among programmers due to their reliability, performance, and user-friendly interface.

Can you learn to code with a Mac? ›

Swift Playgrounds is a revolutionary app for iPad and Mac that helps you learn to code and build apps using Swift, the same powerful language used to create world-class apps for the App Store.

Is Python free for Mac? ›

Python is a free, open-source interpreted language that stands out for its versatility in supporting several programming paradigms, whether utilizing object-oriented language or imperative syntax, or using its command line to work in a functional way, as with languages like Haskell.

Top Articles
Latest Posts
Article information

Author: Jerrold Considine

Last Updated:

Views: 5932

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Jerrold Considine

Birthday: 1993-11-03

Address: Suite 447 3463 Marybelle Circles, New Marlin, AL 20765

Phone: +5816749283868

Job: Sales Executive

Hobby: Air sports, Sand art, Electronics, LARPing, Baseball, Book restoration, Puzzles

Introduction: My name is Jerrold Considine, I am a combative, cheerful, encouraging, happy, enthusiastic, funny, kind person who loves writing and wants to share my knowledge and understanding with you.