How do I embed Python on Windows NT? Docs don't help!

Mark Hammond mhammond at skippinet.com.au
Sun May 7 05:10:46 EDT 2000


> I'm an experienced C++
> developer, but am new to both Python and DLL's.

In that case it will all be fine once a few things click...

> I successfully built "pythonw_d.exe" in the PCbuild directory, but it
> doesn't do anything!  No console, no output, no error messages,
> nothing.

It is designed that way - the "w" means "windows" - when really it should
ge "g" for "gui".  Definately start with python(_d).exe.  pythonw.exe is
only used for certain types of programs, and even then only late in the
development cycle.

> I tried to write a super-simple console app that includes the Python
> interpreter, using the program in the PCbuild directory as a guide,
> but I can't even get it to link.  "WinMain" calls "Py_Main", but
> neither links it not explicitly loads a DLL, and it comes up
> undefined at link time (no surprise).  How is this symbol resolved?!?

Note that WinMain is the entry point for GUIs.  You will have the exact
same issue for python.exe, except the top-level entry point is simply
"main".

It is resolved with a #pragma in the source code.  One of the headers has
a #pragma comment(lib, "python_d.lib") (or minus the "_d" for none-debug)
line, informing the linker to attempt to locate that named lib.

> There's a mysterious file in the "pythonw" project called
> "python15" that I assume has something to do with the DLL,

That is simply an MSVC dependency - it tells MSVC that the DLL must be
built before the .exes.

> How do I embed the Python interpreter using a DLL?

Just include the .h files, and call the functions :-)

> Should I even bother with this DLL stuff, or should I just try to embed
it directly
> (compile & link all the Python files into my app)?

Definately go the DLL way.

Mark.





More information about the Python-list mailing list