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.
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.
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.
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 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.
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.
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).
Select Python Interpreter settings. Then either choose an existing interpreter from the Python interpreter list of click.
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.
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.
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.
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).
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.
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!
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”
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.
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.
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.
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.
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.
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.
We notice you're using an ad blocker
Without advertising income, we can't keep making this site awesome for you.