June 4, 2015

P4Python goes pip

Version Control

In recent years Python has changed its package manager strategy, and the result is pip. Pip is a powerful package manager that simplifies the creation and consumption of Python packages, turning the Python Package Index into a hub of an ever-growing number of useful packages.

P4Python always had to stay away from the package index because it requires binary builds for some platforms. With the advent of the wheel format, this has changed. Wheels are Python packages that can contain binary builds on Windows and OSX, allowing package creators to precompile their packages.

P4Python 2015.1 has been uploaded to the Python Package Index. For you this means installing the latest release of P4Python becomes a simple:

    pip install p4python

Easier, isn’t it?

However, there are a few preparations you need to make before you can run this command the first time successfully:

  1. You need to have the right version of Python installed: 2.7, 3.3 or 3.4. Python 2.6 is supported but we have not uploaded binaries for it.
  2. You need to install pip. It comes with Python 3.4 and 2.7.9 automatically; everyone else will need to install it, for example from here, and make sure the pip executable is in your PATH.
  3. There is currently no binary wheel format available for Linux, so pip will download the source code of P4Python and attempt to build it. This requires ‘python-dev’ and ‘build-essential’ installed on Debian-based distributions (using apt) and the equivalent on RPM-based (using yum).

In order to build P4Python automatically from Pip, setup.py has also gained some new tricks.

First of all, it now uses setuptools and not distutils, so you need to have setuptools installed if you want to build it on, say, Python 2.6.

If you run setup.py without the –apidir option, setup will now go off and attempt to download the correct P4API binaries from the Perforce FTP site for your platform. The API will be downloaded and unpacked into the temp directory and used automatically by the build process.

You can still download the source or the packages, of course, and install P4Python the traditional way if you prefer.

I found pip amazingly simple to use, and I hope it will make your life a lot easier when installing P4Python. As usual, if you have any issues or requests, let us know in Perforce Support or ping me on my Twitter handle @p4sven.

Happy hacking.