4
#include "C:\Users\user\appdata\local\programs\python\Python39\include\Python.h"

int main()
{
    PyObject* pInt;

    Py_Initialize();

    PyRun_SimpleString("print('Hello World from Embedded Python!!!')");

    Py_Finalize();
}

I've tried to fix this error, read both this and this, but I'm still getting the same error. Also when I do #include <Python.h> instead of "C:\Users\user\appdata\local\programs\python\Python39\include\Python.h" I get this error: cannot open source file "Python.h"

  • How are you compiling this code? Are you telling the compiler where to find the python headers and libraries? Please show a [mre] – Alan Birtles Feb 11 '21 at 20:52
  • @AlanBirtles This is the whole code. – JeduMiSePalacinke Feb 11 '21 at 20:54
  • 1
    As you are asking about compiler and linker problems part of a [mre] is your compiler and linker commands – Alan Birtles Feb 11 '21 at 20:57
  • The include problem looks like you need to setup your compiler's include path. And the linking problem looks like you did not add the folder containing python39_d.lib to the directories your linker is looking for libraries. – drescherjm Feb 11 '21 at 22:19

4 Answers4

4

Solutions:

  1. The easiest way that worked for me is to create a duplicate python39.lib and rename the second copy to python39_d.lib.
  2. The pragma for python39_d.lib is present in pyconfig.h which could be edited to python39.lib.
Abhishek Dutt
  • 1,308
  • 7
  • 14
  • 24
2

The python library python3x_d.lib is the debug version of the python library and it is an optional component. Unless you explicitly enabled (by tick mark the check box) "Download debug binaries" option during python install, it will not get installed. The easy option could be to reinstall python with the "Download debug binaries" option check marked. Building Python from its source with debug flag on is another option, significantly high effort with this. If you are using Anaconda I don’t know an option that you can use, I have not found such option yet (in fact I am looking for such option with anaconda).

Satyan
  • 1,346
  • 8
  • 15
1

I faced to the same error with Visual Studio Community 2019. The python39_d.lib is only for debug usage, instead of python39.lib

I simply put Visual in release mode and the error is gone.

Please note that I don't have the lib python39_d.lib in my Python local directory.

0

I think this is because when you installed the python in your system you didn't specify to install the debug libraries from the advanced options. During the python installation, there is a place where you can check it to install them, at least in python 3.8 install.

enter image description here

I was getting the same error but for python 3.8, python38_d.lib

Willy
  • 9,848
  • 22
  • 141
  • 284