[GRASS-dev] Python handling in winGRASS7 [was: Re: GRASS GIS 7 tech-preview release preparations]
Moritz Lennert
mlennert at club.worldonline.be
Mon Jul 29 07:13:45 PDT 2013
On 26/07/13 20:18, Glynn Clements wrote:
>
> Moritz Lennert wrote:
>
>> Would it be a possible option to implement only a) and document the fact
>> that the user has to take care of creating a working Python installation
>> herself if they want b) ?
>
> In order to be able to "execute" scripts via the command prompt,
> batch files, system(), subprocess.Popen() or similar, the extension
> must be associated with an interpreter in the registry. This cannot be
> overridden via environment variables.
>
> Note that Python 3 includes a launcher utility for Windows:
>
> http://docs.python.org/3/using/windows.html#launcher
>
> The idea is that the .py extension can be associated with the
> launcher, which can be configured to use a specific version of Python
> in a specific context.
>
> I don't know whether it's possible to make use of this without
> installing the rest of Python 3, though.
I just tested the following on a WinXP machine without Python installed
(except for the Python in the GRASS installation):
- Go to https://bitbucket.org/vinay.sajip/pylauncher
- Download launchwin.msi
(https://bitbucket.org/vinay.sajip/pylauncher/downloads/launchwin.msi)
- Install by double-clicking or with msiexec /i launcher.msi
Result:
- I can call python modules from the command line (v.db.update,
v.db.renamecolumn)
- Calling a script from a script works (v.db.renamecolumn)
This is without any py.ini, so IIUC just relying on the /usr/bin/env
python shebangs in the scripts !
When I installed a 2.7.5 Python from python.org, everything still works
the same way, but launching python at the prompt gives me 2.7.5 (i.e.
the python.org version, not the GRASS installed version which is 2.7.4),
so I suppose that the system-wide installed python is launched, even
though its path is at the very end of %PATH%, after grass\extrabin.
When I installed a 3.3 version from python.org, running python from the
GRASS command line gives me 2.7.4, but running GRASS GUI gives me error
messages as does trying to launch v.db.update or other scripts at the
command line. The error message contains a reference to python33.dll.
Running py -2 gives an error that version 2 is not found. So it seems
that the python launcher does not take into account the PATH,
PYTHONHOME, and PYTHONPATH settings which all point correctly to the
GRASS version of Python, but rather still calls the installed 3.3
version (even it the path to that version is not in PATH). I guess the
launcher takes its information from the registry.
However, I still think this looks promising as the whole idea of the
launcher is to allow multiple instances of Python to run on the same
machine. So, maybe it would be enough to figure out how to register the
GRASS installation of Python in the registry and then install an .ini in
the GRASS7 Application Data directory to direct the python launcher to
that version?
Moritz
More information about the grass-dev
mailing list