Home - Forums - Documentation - Gallery - Bugs


Compiling Python bindings with MSVC

What you need

This tutorial explains you, how you can build cspython, _cspace, and CEL blpython plugins with MSVC. First, I assume, you succeslfully compiled CS (and optionally CEL). You can find the comlete guide to do this in the manual. Get python packages from the official site, and download a Windows binary package. Install it. I tested this tutorial with Python 2.3.5 and it will not work with Python 2.5!!! Finally, download the correct cs_pyth.cpp from here. Extract the zip file, and copy int your CS/plugins/cscript/csypthon directory. Yes, rewrite the original file. Preparation finished.

Setting up MSVC IDE

1. Run MSVC IDE. 2. Go to the Tools->Options->Projects and Solutions->VC++ Directories Select Include files above. Click to New Line icon, and type or select your Python"2X/Include directory. 3. Select Library files Click to New Line icon, and type or select your Python"2X/libs directory.

From now MSVC will find Python related headers and directories.

Creating the solution

Click to the File->New->Project... and select Win32 console application template. Add a name to your solution (csypthon is ideal), select the location of your project.

Click to the ok. Now click to the Application settings. Set as DLL project and check the Empty project box. Now click to the finish button.

Now click to the Solution explorer, right click to the Headers->Add existing item.... Add the following headers to your project from your CS/plugins/cscript/cspython directory:

Noe right click to the source files, Add existing item, then add the following source files to your project from your CS/plugins/cscript/cspython directory:


Now right click to the Resource files, add existing item. Navigate to your CS/mk/msvc directroy, and add cspython.rc to your project.

Press F7 to build the solution.

Creating _cspace.pyd

When you want to write Cs applications with Python, you need to compille _cspace.pyd. This is easy. You need to compile:
in one prioject. All project settings is the same, like in the previous, but you don't need any rc file. Additional settings are here: manual.

| Article | Discussion | View source | History |