Embedding Python in Windows tutorial?

Roose moof at boof.moof
Tue Oct 19 04:24:15 EDT 2004


With some googling I have found these resources:

http://docs.python.org/ext/win-dlls.html
http://www.python.org/doc/faq/windows.html

I have a large Win32/MFC/C/C++ application that has an embedded scripting
language (a very limited one).  I would like to rip it out and replace it
with Python.  I am thinking that this would be relatively simple since the
scripting language is a very small interface between the UI and the
engine -- there would only be a handful functions I would need to wrap.

However in googling I haven't been able to come up with a completely
straightforward way to do it.  I see all these caveats mentioned casually,
and not explained, which kind of scares me.

Examples:

1. I heard Python23.dll is built with MS VC++ 6.  I am using .NET 2003 (VC++
7.1).  Is this a problem?  I wouldn't think so since I am not statically
linking... but someone said the C runtime is different between the two?
When would that be a problem?

2.  Any sample VS.NET projects / boilerplate DLL code that loads
Python23.dll into the?  Sure this is probably pretty simple -- add an
include paths, add a DLL dependency... but I'm sure there is at least one
gotcha and if I can avoid repeating other's mistakes, I'd prefer that.

3.  How does C++ change the story?  I assume at the least I have to extern
"C" any functions that are called by Python, right?  What else?

4.  The program in question has no installer -- it is an internal tool, and
people simply download the binaries .exe/.dll's/etc. from a source control
system.  Does that present any problems?  Is all they need is Python23.dll
in their system dir, which is installed if you install Python?  But I am
going to need to write some Python wrappers for functions... does this mean
I need to use distutils and all that?  One thing I didn't find clear is that
distutils will "install" a module on your own machine -- but what do you
need to do to get it onto other's machines? (e.g. non-engineers who do not
have compilers)

It seems like what I am doing is pretty much the "canonical" embedding
task -- scripting an engine of C/C++ code and also needing to access this
scripting through the GUI (i.e. so it is BOTH extending and embedding), so I
would like to know if there are some more complete Windows-specific
resources out there.

Also, any general advice on the process would be interesting.  Out of all
the people who have done some embedding -- was it worth it?  Were there a
lot of headaches?  One of my concerns now is that it will decrease the
debuggability of the application.  In a pure C/C++ app in VS.NET, it is
pretty simple to debug.  But now I will have a layer of Python in between,
which could make it a big pain.  In general this is kind of an "extra"
project at work that I don't want to spend a whole lot of time on.  (It will
help "sell" python to a large group of very capable engineers, if that
motivates anyone to help me.  : ) )

Thanks in advance for any help.

Roose





More information about the Python-list mailing list