win32 extension installation problem
Mark Hammond
MarkH at ActiveState.com
Sat Jun 23 23:22:12 EDT 2001
zihonglu wrote:
> We are building a product with python and the win32 extension, in win32
> environment. I have a problem in shipping the product with win32 extension.
>
> What I really want is to have the python interpreter and the win32 extension
> installed inside our product's directory, say c:\MySoftware\Python, and in
> the registry, set python's keys under HKLM\Software\MySoftware\Python,
> instead of the typical HKLM\Software\Python, to avoid conflict with
> customer's possible existing python installation or possible future python
> installation change. I can achieve that by change python's source code to
> look for the new registry key.
The best solution is to change Python's view of the core registry key.
The default Python registry key is
HKLM\Software\Python\PythonCore\{version-id}
This {version-id} is loaded from the Python.dll string resource table.
You can open Python.dll in MSVC (ie, the pre-built version - no need to
rebuild anything) and locate the one-and-only string resource. This will
say, eg, "2.1". Hence the registry used for 2.1 is:
HKLM\Software\Python\PythonCore\2.1
You can change this to any value you like (numeric or otherwise). This
will change the registry key used by that DLL. FYI, this value is
reflected into Python as sys.winver - however, you can not simply change
it at runtime, as the value has already been used by the time you get
your first opportunity to change it.
So, although you can not simply change the "root" of the registry,
changing this version string will give you your own playground that will
not affect pre-installed versions.
> However, since I am also using the win32
> extension, it looks HKLM/Software/Python for its installation and execution,
> not my new keys. I also use PythonService.exe, which checks for its key
> under HKLM/Software/Python for registering the service, not the one I set
> under my new keys.
You probably don't want to use the win32all installer - simply install
these extensions along with your software into the appropriate directories.
At runtime, there is nothing hard-coded to use the version number.
pythonservice.exe and all other code that needs the registry at runtime
uses sys.winver to determine where to put it. Hence, pythonservice.exe
running with a patched python.dll should magically do the right thing.
This mechanism was added specifically for this situation, so you may as
well use it.
> To solve these problems, how many places I need to change the win32
> extension source code, if I can find them? Is there a better way? Where do
> I get the source code?
You get the source code via
http://starship.python.net/crew/mhammond/cvs.html
Mark.
More information about the Python-list
mailing list