Opened 15 years ago

Last modified 12 years ago

#114 assigned enhancement

optional package to register python in Windows registry

Reported by: maphew Owned by: maphew
Priority: major Component: Installer
Version: Keywords: python
Cc:

Description (last modified by maphew)

It can be helpful sometimes to register the gdal version of python with Windows. This way a) .py files can be run from outside the o4w shell, and b) 3rd party python programs which aren't part of the o4w package system can be installed using traditional python installers and eggs.

working prototype: http://code.google.com/p/maphew/source/browse/register-python/register-python.py

Adapted from how to for (de)registering a given python install: http://effbot.org/zone/python-register.htm

There can only be a single major version registered at a time, e.g. only one python 2.5

Change History (15)

comment:1 by warmerdam, 15 years ago

I would encourage some caution in registering OSGeo4W's Python as the system python. As noted, we should not replace the system python if there is one registered. We might also consider making registering as the system python something that is trigger by an extra by-request package rather than part of the normal python install.

That said, if we can do this well it could be quite valuable.

Were you interested in taking the lead on this Matt?

comment:2 by maphew, 15 years ago

Owner: changed from osgeo4w-dev@… to maphew
Status: newassigned

Sure, I'll give it a try. It looks tight enough in scope that I won't have to stretch too far to learn how. :)

comment:3 by maphew, 15 years ago

I have a version ready for testing: http://code.google.com/p/maphew/source/browse/trunk/gis/o4w_extras/register-python.py.

Successfully doesn't register o4w python on WinXP Home with Py2.5 pre-installed outside of o4w. Don't know if it will work on x64.

comment:4 by maphew, 14 years ago

It, currently, doesn't detect existing installs on x64 due to something called "registry reflection" and "registry redirection" - http://www.mail-archive.com/python-list@python.org/msg266397.html

However on x64 it can't register itself either, so this is an annoyance and a failure, but not damaging.

comment:5 by maphew, 13 years ago

Python 2.7+ has a _winreg module which reads like it would fix the 64bit issue. Patch files here, found by way of Stack Overflow.

comment:6 by maphew, 13 years ago

Keywords: python added

comment:8 by maphew, 13 years ago

New release of register-python.py (reg-py_0.1) is ready for testing. It's been tested on 32bit Win7. Most notable improvement is that this version removes as well as installs (but only if the InstallPath matches)

b:\>register-python.bat install

Putting python from environment into registry...

--- Python 2.7 is now registered to C:\o4w\apps\Python27!

b:>register-python.bat remove

Found in All Users:

        2.7 - C:\o4w\apps\Python27

existing python matches ours, removing...

--- Python 2.7, C:\o4w\apps\Python27 is now removed!

b:\code\maphew\gis\o4w_extras>

comment:9 by maphew, 12 years ago

Description: modified (diff)

revised url: http://code.google.com/p/maphew/source/browse/register-python/register-python.py (sorry for the jumping about! When reorganizing for my personal efficiency I forgot there are links to it.)

comment:10 by Alister, 12 years ago

Why do I get this?:

python regist*.py install


...installing

Putting python from environment into registry...

--- Python 2.7 is now registered to C:\OSGeo4W\apps\Python27!
Traceback (most recent call last):
  File "register-python.py", line 246, in <module>
    install()
  File "register-python.py", line 211, in install
    if match:
UnboundLocalError: local variable 'match' referenced before assignment

comment:11 by maphew, 12 years ago

Whups. Looks like install fails if there are no current pythons at all. Fix it by adding match = False near the beginning of def install. See http://code.google.com/p/maphew/source/browse/register-python/register-python.py line 118, as of today. Thanks for the bug report.

comment:12 by Alister, 12 years ago

OK, now I get this:

...installing

Putting python from environment into registry...

--- Python 2.7 is now registered to C:\OSGeo4W\apps\Python27!

Putting python from environment into registry...

--- Python 2.7 is now registered to C:\OSGeo4W\apps\Python27!

It seems strange that it seems to register twice, but OK.

comment:13 by maphew, 12 years ago

Glad it works now. Double registration fixed now too, along with a few other clean ups.

comment:14 by maphew, 12 years ago

just discovered: if o4w python is the All-Users system default, running the official installer and selecting "install for just me" results in 2 registrations for the same major version. Something I had thought was not possible. However since the official installer is okay with it, maybe it just means there can't be the same major version in the same container (All vs Current).

Dunno what this means for standard python search path when importing.

B:\python register-python.py list
Current python installs in registry:

Current User:
        2.7 - C:\Python27\

All Users:
        2.7 - B:\o4w\apps\Python27

comment:15 by maphew, 12 years ago

The dual registration causes problems with PyScripter. This is because PyScripter expects the All Users python27.dll to be in %windir%\system32 and refuses to look elsewhere unless told to with a commandline parameter.

Workarounds:

  • copy the python27.dll to %windir%\system32, or
  • use pyscripter --python27 --pythondllpath o:\apps\Python27

Solution:

  • change register-python so that it installs to Current User by default; that's more in keeping with Osgeo4w philosophy anyway.
  • look into filing a bug with python.org as I don't think the dual registration is an intended outcome
Note: See TracTickets for help on using tickets.