Installing PyObjC

Supported versions

PyObjC is regularly tested with Python 2.7, 3.4, 3.5 and the CPython trunk. PyObjC does not support other python implementation such as PyPy and Jython.

PyObjC is regularly tested on Mac OS X 10.11 and should work on Mac OS X 10.5 or later for the i386, x86_64 and ppc architectures. PPC64 (64-bit on PowerMac G5 or iMac G5 systems) is not supported.

Requirements

PyObjC contains extensions and is distributed as source code. You therefore need a compiler to install PyObjC. The easiest way to get a compiler is do download Xcode from the Mac App Store.

Depending on the Python release you may need to install the Command Line Tools for Xcode. To install the Command Line Tools first install Xcode from the Mac App Store. The next action depends on the OSX release you are using.

If you use OSX 10.8 or earlier, open Xcode and then open the Xcode preferences. The downloads tab contains an option “components” and that list contains an option to install the “Command Line Tools”.

If you use OSX 10.9 or later, open a Terminal window and run xcode-select --install.

Note

The Command Line Tools package may not be automaticly updated when you install a new version of Xcode. Every time Xcode is updated through the Mac App Store you need to start Xcode to check if there is a new version of the Command Line Tools.

Installation

PyObjC is distributed as a collection of Python packages that use distribute and can be installed using both pip and easy_install. Manual installation is also supported, but is a lot more work and is therefore more of a power-user feature.

Installation using pip

Installing or upgrading PyObjC using pip is easy:

$ pip install -U pyobjc

Note

Make sure that you don’t have a directory named “build” in the current working directory when you run pip, that might result in unexpected behavior.

Note

As with easy_install installing PyObjC takes quite some time due to issue 21 and the same workaround applies:

$ pip install -U pyobjc-core
$ pip install -U pyobjc

Warning

Building on OSX 10.7 or 10.8 might give a compiler error when using Xcode 4 and a binary installer for Python. When installing fails because a compiler named ‘gcc-4.2’ cannot find the header ‘stdarg.h’ you have to install using a slightly different procedure:

$ env CC=clang pip install -U pyobjc-core
$ env CC=clang pip install -U pyobjc

Installation using easy_install

Installing or upgrading PyObjC using easy_install is easy:

$ easy_install -U pyobjc

Note

Due to issue 21 installing will take take quite some time because the package pyobjc-core is compiled a number of times.

The work around is to install that package before installing the rest of PyObjC:

$ easy_install -U pyobjc-core
$ easy_install -U pyobjc

Warning

Building on OSX 10.7 or 10.8 might give a compiler error when using Xcode 4 and a binary installer for Python. When installing fails because a compiler named ‘gcc-4.2’ cannot find the header ‘stdarg.h’ you have to install using a slightly different procedure:

$ env CC=clang easy_install -U pyobjc-core
$ env CC=clang easy_install -U pyobjc

Upgrades with pip or easy_install

Running easy_install -U or pip install -U to update an existing installation of PyObjC can fail with an error message about conflicting versions. This is due to issue 21 and is not something that can easily be fixed in PyObjC itself.

The easiest workaround is to first update “pyobjc-core” and only then perform the full update.

Manual installation

Manual installation is slightly involved, but still pretty easy.

  • First download the source code packages from the cheeseshop, you need at least pyobjc-core and pyobjc-framework-Cocoa. You do not need pyobjc, that’s a helper package that is only used to pull in the other packages when installing using easy_install or pip.

  • Extract the archives

  • Install every packages using the standard recipe for Python package installation:

    $ python setup.py install
    

    Due to package dependencies you need to install the packages in a particular order:

Advanced installation options

PyObjC for PowerPC systems

To build a version of PyObjC that runs on PowerPC systems you need a system running Mac OS X 10.6 (or earlier) running Xcode 3. The version of Xcode that is available in the Mac App Store can not create PowerPC binaries.

Distributing binaries to other Mac OS X releases

It is possible to create self-contained application bundles for PyObjC based application using py2app. You do need to take some care when you want to ship these applications to machines running a different version of Mac OS X than the one you used for the build

  • Later versions of Mac OS X should work fine

  • Earlier version of Mac OS X work fine, but you do need to ensure that Python itself is build with MACOSX_DEPLOYMENT_TARGET set to the earliest version of Mac OS X you want to support. PyObC, and other extension packages, should automaticly pick up the deployment target from the Python build.

    Note

    PyObjC contains code that explictly weak-links to a number of APIs that are not available on all Mac OS X releases.

    You might still end up with an application that won’t run on earlier releases when you use another extension module that (accidently) hard links to an API that is not available in the earlier release.