loading Python20.dll during run-time under Windows

Robin Becker robin at jessikat.fsnet.co.uk
Sun Mar 11 11:24:06 CET 2001

In article <slrn9alouc.sor.zeitlin at seth.lpthe.jussieu.fr>, Vadim Zeitlin
<zeitlin at seth.lpthe.jussieu.fr> writes
> Hello,
> I have an application which can use Python for scripting but it is not
>essential to its work, i.e. it works mostly fine without Python. So I'd
>like to be able to install it even on systems lacking Python installation
>but for this I need to [try to] load Python.dll during run-time instead
>of linking to it directly.
> Has anyone done this before and is there any (C) code I could reuse?
>Normally, there is no problem with doing what I want (especially
>after realizing that I need to have USE_DL_EXPORT defined...) but
>the perspective of having to manually write all the code needed to load
>the functions from the DLL is not very, hmm, encouraging just because there
>are quite a few of functions and so I'm looking for a slightly less painful
>way to do it.
> Thanks in advance for any help!
Gordon McMillan's Installer software has cpp code that sets up and
launches python.

In essence the code does

1) set up a PYTHONPATH environment variable and the dllpath (where the
python dll is).
2) dll = LoadLibraryEx(dllpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );
3) get the addresses of various key python variables and procedures from
the dll
4) Initialise many of the key variables and the python interpreter.
5) Run a predefined script.

If that sounds the right sort of thing then get the code from Installer-
3j/source at http://www.mcmillan-inc.com/builder.html

Robin Becker

More information about the Python-list mailing list