can't find win32api from embedded pyrun call

Jim jim at trainplayer.com
Tue Jun 20 21:09:54 CEST 2006


Miki wrote:

> IIRC you need to set the path explicitly in an embedded interpreter.
> See the code in "site.py" (which again IMO is *not* imported when the
> interpreter starts).

Thanks Miki.  Actually that doesn't turn out to be the problem.  If I
display sys.path within the embedded script, it shows the complete list
of paths, there is no need to pre-load.

The problem turned out to be a mismatch of parts.  For one thing,
building the debug lib from Python sources using VS2005 leads to the
crash in PyInitialize (I don't know why others haven't run into this);
building with VS2003 did away with that.  But that then led to the
well-known problem with a FILE* where the app is using one msvcrt and
the lib another.  At some point in fixing these issues, the "cannot
find win32api" went away.

I now use this trick from a colleague which allows me to build a debug
version of my app but load the release version of the lib: bracket the
"#include python.h" statement with undef/redef of _DEBUG.

And this trick to get around the FILE* problem (since my app is VS2005
and the lib is 2003): instead of PyRun_SimpleFile, use
PyRun_SimpleString ("execfile(fname)").  I got this from the win32 FAQ.

I hope someone benefits from this, it cost me plenty to figure out.

  -- Jim




More information about the Python-list mailing list