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
Download P4Python from the /bin.tools 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 setup.py 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 setup.py 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 setup.py 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 setup.py 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.