Ticket #114 (assigned enhancement)

Opened 5 years ago

Last modified 2 years ago

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) (diff)

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

  Changed 5 years ago by warmerdam

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?

  Changed 5 years ago by maphew

  • owner changed from osgeo4w-dev@… to maphew
  • status changed from new to assigned

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. :)

follow-up: ↓ 7   Changed 5 years ago by maphew

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.

  Changed 4 years ago by maphew

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.

  Changed 4 years ago by maphew

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.

  Changed 3 years ago by maphew

  • keywords python added

  Changed 3 years ago by maphew

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>

  Changed 3 years ago by maphew

  • 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.)

  Changed 2 years ago by Alister

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

  Changed 2 years ago by maphew

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.

  Changed 2 years ago by Alister

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.

  Changed 2 years ago by maphew

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

  Changed 2 years ago by maphew

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

  Changed 2 years ago by maphew

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.