[HELP] Creating CPP Python Module.

Jan 22 at 8:16 AM
How can i compile cpp python module and mix debug with python tools?
I have visual studio 2013 Ultimate, Python Tools 2.
I added PYTHON_INCLUDE to vc++ directories,
This is the error i get: error LNK1104: cannot open file 'python27_d.lib'

And i don't know how to attach my module to the python project,
There are any example project like the one in the YouTube video.

Thanks.
Coordinator
Jan 23 at 4:24 PM
To fix that error, you have three choices:
  1. Build your project in Release mode
  2. Add #undef _DEBUG before #include <python.h>
  3. Build CPython in Debug mode
Unfortunately we don't have any nice straightforward guides for developing native Python modules, and as far as I know python.org doesn't have any either. It's really an art right now that requires a solid understanding of how Python's import system works and a lot of persistence to keep trying until it works.

You will also need to get Visual Studio 2008 (or Visual C++ 2008 Express if you can find it) to compile for Python 2.7. Alternatively, if you install the Windows SDK for .NET 3.5 and also the Windows SDK for .NET 4.0 then you will be able to select the v90 platform toolset in the project properties for your native module. (Another alternative is to be really really careful that you don't use native Python APIs with file descriptors or FILE* pointers. If you plan to redistribute your module as source code on PyPI/pip, end-users will only be able to compile it automatically with VS 2008.)

Did I mention this is complicated? :( Most people who have made it work are highly skilled C/C++ developers. If you are not, you may want to consider Cython, which will produce native modules from a Python-like syntax. I believe you will still need VS 2008 for this, though you may be able to configure Cython to use a later version.

One thing we do want to do in the future is produce a guide and template for developing native Python modules using Visual Studio. Right now however, there are a few issues that complicate it too much that we are trying to simplify (access to the necessary compilers is one of them), as well as the fact that we are currently focused on other feature areas. I personally am keen to improve this area though, so I'm sure it'll happen eventually.