Perforce Public Knowledge Base - Building and Debugging P4Python on Windows
Perforce Software logo
Reset Search



Building and Debugging P4Python on Windows

« Go Back



Installing P4Python on Windows may give you the error:

There was a problem tying to get the P4Python install path.
Possible reasons are:
1) Python is not installed.
2) An unsupported version or architecture of Python is installed.
3) The folder containing the Python executable is not in the system path
4) Another version or architecture of Python is in the system path
before the supported version or architecture.
5) The P4Python install paths are not writable

Building P4Python on Windows can be a challenge, debugging it in the case of a crash even more so. This article is intended as a guide to build Release and Debug versions of P4Python (32bit and 64bit) on Windows using Visual Studio 2008.


Pre-compiled versions

Before building your own P4Python, don't forget to first try pre-compiled versions of P4Python in our ftp directory. For example, P4Python 2.7 that runs on Windows XP or Windows 7 can be found in


For this build you will need:
  • Windows XP, Vista or 7 in either 32bit or 64bit mode.
  • Python 2.6 in the matching 32bit or 64bit release. With the 2010.1 release you can also use Python 3.1 (currently unsupported)
  • Visual Studio 2008. No other version is supported for Python 2.6 or 3.1.
  • The matching Perforce C++ API in static mode for Visual Studio 2008

To begin:

    Download P4Python from the / directory of the latest release on the perforce FTP site, and unpack it in a directory of your choice.


    To build the 32 bit Version of P4Python, it is sufficient to run the command
    python build --apidir [Perforce C++ API absolute path]

    Python will automatically find the Visual Studio directory and choose the correct directories for the compiler and so on.

    If you need to build the 64 bit version, you need to have the 64 bit version of Python installed. You also need to tell the python build environment which compiler you want to use. Run the following batch file:

    c:\Program Files(x86)\Microsoft Visual Studio 9.0\VC\bin\vsvars64.bat
    Now you can build P4Python in 64bit mode the same way as the 32bit version.

    If you want to install P4Python into your local Python libraries, run the following command next
    python install


    The Release build on Windows does not contain any debugging information. If there is a crash, the debugger will only show a disassembled code view, which is not helpful. To create a debug build for P4Python, you will need a debug build of Python first.

    To create a debug build, you need to run the build command with the option '-g':
    python build -g

    This command will fail in the link stage, because there is no python_d.dll available in the standard distribution. Instead, you need to download the Python source code from the Python website (Gzipped source tar ball). Unzip this into a directory, then navigate into the PCBuild directory within. Here you will find the project and solution configuration files. Open the solution file with Visual Studio.

    You only need the project called 'python', but you need to choose 'Debug' and '32' or '64' for the build first. Build the project, then find the required dll and lib file in the Debug directory underneath PCBuild. Copy the executable python_d.exe and the dll python_d.dll to the Python main directory and python_d.lib to the Python/libs directory. Use the newly created executable python_d.exe to build P4Python:

    python_d build -g
    This should now succeed. Install P4Python with 'install'; then you can run 'python_d' and import P4.

    Using the debugger

    You can either start python_d, wait for it to crash and then choose the debug option, or attach the Visual Studio debugger to the running Python process before importing P4. You should now have full access to the source code, the ability to set breakpoints and inspect variables.
    Related Links



    Was this article helpful?



    Please tell us how we can make this article more useful.

    Characters Remaining: 255