[python-win32] Embedding/bundling Python, best practices?

Mark Hammond mhammond at skippinet.com.au
Tue Jan 29 01:28:34 CET 2008


TimR wrote:

> You need to set the Python path variable before calling the
> interpreter.  You can do that by setting the PYTHONPATH environment
> variable, but I believe you can also do that by setting variables when
> you initialize the interpreter.

Actually, if the 'lib' directory can be found relative to pythonxx.dll, it
should not be necessary to set PYTHONPATH at all.  Even then, if it *was*
necessary to set such a variable, it may be better to set PYTHONHOME instead
- that should adjust PYTHONPATH (again, the lib can be located relative to
that dir), along with ensuring sys.prefix etc are all correct, thereby
allowing things like distutils to do the right thing.

> Py2exe might prove useful for you, if only because it scans through a
> Python script and determines exactly which auxiliary DLLs and modules
> the script needs in order to operate in a standalone environment.
> 
> > Also, our application is built with VS 2005, should Python also be
> > built with the same VS version for compatibility?
> >
> 
> Yes, this is required.  The Python run-time DLL links to the Visual C++
> run-time library.  My python24.dll, for example, links to msvcr71.dll,
> which is the run-time from VS 2003.

On the other hand, it would work fine if you built Python and all modules
with the same compiler.  You can not *mix* compilers, but using a
non-default one should work fine so long as you control every binary you
load.  That is a burden though.

Cheers,

Mark




More information about the python-win32 mailing list