Python for Mac OS X Python comes pre-installed on Mac OS X so it is easy to start using. However, to take advantage of the latest versions of Python, you will need to download and install newer versions alongside the system ones. The easiest way to do that is to install one of the binary installers for OS X from the.
Installers are available for the latest Python 3 and Python 2 releases that will work on all Macs that run Mac OS X 10.5 and later. Python releases include IDLE, Python's built-in interactive development environment. If you download and install Python from the release page, you may also need to download and install a newer version of Tcl/Tk for OS X. See the for more information.
You can run a Python interpreter by double-clicking on Applications / Utilities / Terminal and typing python3 (if you've installed a version of Python 3) or python (to use Python 2) in the window that opens up. You can also launch IDLE for the Python version you have installed by double-clicking its icon in the appropriate Python version folder in the Applications folder or you can also just type idle3 or idle in a terminal window. There are many thousands of additional Python software packages available through, the Python Package Index. We recommend you use the tool to simplify installing and managing additional packages.
Pip is included with Python 3.4 releases; for earlier releases, follow the pip install instructions. Among the packages available through PyPI are some that are specifically for OS X environments. Among these are:. which provides a bridge between Python and Objective-C, allowing you to write full-featured native Cocoa applications in pure Python. which allows you to make standalone OS X double-clickable application bundles and plugins from Python scripts. For more information about Python on OS X, see the mailing list and archives for the.
Using Python on a Macintosh Author: Bob Savage Python on a Macintosh running Mac OS X is in principle very similar to Python on any other Unix platform, but there are a number of additional features such as the IDE and the Package Manager that are worth pointing out. The Mac-specific modules are documented in. Python on Mac OS 9 or earlier can be quite different from Python on Unix or Windows, but is beyond the scope of this manual, as that platform is no longer supported, starting with Python 2.4. See for installers for the latest 2.3 release for Mac OS 9 and related documentation. Getting and Installing MacPython Mac OS X 10.8 comes with Python 2.7 pre-installed by Apple.
If you wish, you are invited to install the most recent version of Python from the Python website. A current “universal binary” build of Python, which runs natively on the Mac’s new Intel and legacy PPC CPU’s, is available there. What you get after installing is a number of things:.
A MacPython 2.7 folder in your Applications folder. In here you find IDLE, the development environment that is a standard part of official Python distributions; PythonLauncher, which handles double-clicking Python scripts from the Finder; and the “Build Applet” tool, which allows you to package Python scripts as standalone applications on your system. A framework /Library/Frameworks/Python.framework, which includes the Python executable and libraries. The installer adds this location to your shell path. To uninstall MacPython, you can simply remove these three things. A symlink to the Python executable is placed in /usr/local/bin/. The Apple-provided build of Python is installed in /System/Library/Frameworks/Python.framework and /usr/bin/python, respectively.
You should never modify or delete these, as they are Apple-controlled and are used by Apple- or third-party software. Remember that if you choose to install a newer Python version from python.org, you will have two different but functional Python installations on your computer, so it will be important that your paths and usages are consistent with what you want to do.
IDLE includes a help menu that allows you to access Python documentation. If you are completely new to Python you should start reading the tutorial introduction in that document. If you are familiar with Python on other Unix platforms you should read the section on running Python scripts from the Unix shell. How to run a Python script Your best way to get started with Python on Mac OS X is through the IDLE integrated development environment, see section and use the Help menu when the IDE is running.
If you want to run Python scripts from the Terminal window command line or from the Finder you first need an editor to create your script. Mac OS X comes with a number of standard Unix command line editors, vim and emacs among them. If you want a more Mac-like editor, BBEdit or TextWrangler from Bare Bones Software (see ) are good choices, as is TextMate (see ). Other editors include Gvim and Aquamacs. To run your script from the Terminal window you must make sure that /usr/local/bin is in your shell search path.
To run your script from the Finder you have two options:. Drag it to PythonLauncher.
Select PythonLauncher as the default application to open your script (or any.py script) through the finder Info window and double-click it. PythonLauncher has various preferences to control how your script is launched. Option-dragging allows you to change these for one invocation, or use its Preferences menu to change things globally. GUI Programming on the Mac There are several options for building GUI applications on the Mac with Python. PyObjC is a Python binding to Apple’s Objective-C/Cocoa framework, which is the foundation of most modern Mac development. Information on PyObjC is available from.
The standard Python GUI toolkit is, based on the cross-platform Tk toolkit. An Aqua-native version of Tk is bundled with OS X by Apple, and the latest version can be downloaded and installed from; it can also be built from source.
WxPython is another popular cross-platform GUI toolkit that runs natively on Mac OS X. Packages and documentation are available from. PyQt is another popular cross-platform GUI toolkit that runs natively on Mac OS X. More information can be found at. Idvd replacement for mac.