Why doesn't #include <Python.h> work?

Curious picture Curious · Apr 24, 2013 · Viewed 21.7k times · Source

I'm trying to run Python modules in C++ using "#include <Python.h>", however, after setting the "Additional Include Dependencies" of the project to "\include" I get the following error when debuging,

LINK : fatal error LNK1104: cannot open file 'python27_d.lib'

I read that I should download the development version of Python, but I didn't find a link for that, plus, don't I just need the file 'python27_d.lib' to be copied to the "libs" folder?

Please note that I'm using the Anaconda distribution of Python.

Thanks in advance!

Answer

Klamer Schutte picture Klamer Schutte · Sep 6, 2015

I normally circumvent this by using the non-debug Python lib in debug builds. Typically, this leads to code like:

#ifdef _DEBUG
  #undef _DEBUG
  #include <Python.h>
  #define _DEBUG
#else
  #include <Python.h>
#endif

where you hide the definition of _DEBUG during the inclusion of Python.h.