[GRASS-dev] [GRASS GIS] #2333: choose python interpreter during the GRASS installation on windows

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------
Using the Windows installer would be great to be able to choice which
python interpreter must be used by GRASS.

Suppose that we have already installed a python interpreter like
[https://code.google.com/p/pythonxy/ pythonxy], at the moment the GRASS
installer use is own python interpreter therefore if I want to use any
python packages from GRASS, like [http://www.scipy.org/ scipy] or
[http://pandas.pydata.org/ pandas] I have, some how, to install these
packages on the GRASS interpreter even if they are already present in
pythonxy.

Do you think that would be possible to add this point to the GRASS
installer? or It is not possible to add this option because GRASS must be
compiled using the new interpreter? where should I look to try to add this
option?

Any hints?

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2333&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by mlennert):

Replying to [ticket:2333 zarch]:
> Using the Windows installer would be great to be able to choice which
python interpreter must be used by GRASS.
>
> Suppose that we have already installed a python interpreter like
[https://code.google.com/p/pythonxy/ pythonxy], at the moment the GRASS
installer use is own python interpreter therefore if I want to use any
python packages from GRASS, like [http://www.scipy.org/ scipy] or
[http://pandas.pydata.org/ pandas] I have, some how, to install these
packages on the GRASS interpreter even if they are already present in
pythonxy.
>
> Do you think that would be possible to add this point to the GRASS
installer? or It is not possible to add this option because GRASS must be
compiled using the new interpreter? where should I look to try to add this
option?
>
> Any hints?

http://osgeo-org.1560.x6.nabble.com/Handling-of-Python-scripts-on-MS-
Windows-tt5081335.html

I would guess that this thread is probably one of the longest in grass-dev
history. Have fun ! :wink:

Moritz

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2333#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by hellik):

Replying to [ticket:2333 zarch]:
> Using the Windows installer would be great to be able to choice which
python interpreter must be used by GRASS.
>
> Suppose that we have already installed a python interpreter like
[https://code.google.com/p/pythonxy/ pythonxy], at the moment the GRASS
installer use is own python interpreter therefore if I want to use any
python packages from GRASS, like [http://www.scipy.org/ scipy] or
[http://pandas.pydata.org/ pandas] I have, some how, to install these
packages on the GRASS interpreter even if they are already present in
pythonxy.
>
> Do you think that would be possible to add this point to the GRASS
installer? or It is not possible to add this option because GRASS must be
compiled using the new interpreter? where should I look to try to add this
option?
>
> Any hints?

a first step would be to change

https://trac.osgeo.org/grass/browser/grass/trunk/mswindows/env.bat#L9

{{{
9 set GRASS_PYTHON=%GISBASE%\extrabin\python.exe
}}}

to point to your already installed other python and test if this works (no
idea if any other changes e.g. in wxgui are needed).

''env.bat'' is AFAIR in a subfolder of ''C:\Program Files (x86)\GRASS GIS
X.x''

keep in mind, these other python should have compatible GRASS dependencies
(e.g. numpy, wxpython, matplotlib,...).

if the change in env.bat works, the next step would be to add an option
which python to use to the nsis-script:

https://trac.osgeo.org/grass/browser/grass/trunk/mswindows/GRASS-
Installer.nsi.tmpl

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2333#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by hellik):

>
> a first step would be to change
>
> https://trac.osgeo.org/grass/browser/grass/trunk/mswindows/env.bat#L9
>
> {{{
> 9 set GRASS_PYTHON=%GISBASE%\extrabin\python.exe
> }}}

oh, also this line has to be adapted:

https://trac.osgeo.org/grass/browser/grass/trunk/mswindows/env.bat#L10

{{{
10 set PYTHONHOME=%GISBASE%\Python27
}}}

and should point to the pythonhome of your other python.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2333#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by zarch):

Replying to [comment:1 mlennert]:
> http://osgeo-org.1560.x6.nabble.com/Handling-of-Python-scripts-on-MS-
Windows-tt5081335.html
>
> I would guess that this thread is probably one of the longest in grass-
dev history. Have fun ! :wink:

Thanks Moritz, I saw the thread but it seems to me that it is not going
anywhere, so I'm trying to change prospective. I think that my point is
close but it is not the same. I'm not talking on how to execute
automatically the GRASS scripts on windows, I'm talking on choosing the
default interpreter that must be used by GRASS.

If I understood the long thread we were talking on how we can link the
windows default python interpreter to run our scripts, if we have to use
or not the default python interpreter. Instead here I'm talking to give to
the user the chance of choosing which python interpreter must be used by
GRASS, if not specify just use its own interpreter.

The problem if choosing a different python interpreter could be the ctypes
binding of python that must be re-compiled, isn't it?

I don't want to use the default GRASS interpreter because I need other
libraries that are not present on the GRASS python interpreter (GPyI) and
install these libraries is not easy, generally they require to compile,
and compile on windows is a pain.

The solution that I found and it is working so far, it is just to copy all
the python/site-packages from pythonxy to the site-packages of the GPyI.

But it is just a work around, IMHO the best option should be to be able to
choose during the installation process which one should be used by GRASS.

Pietro

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2333#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by hellik):

Replying to [comment:4 zarch]:
>
> The solution that I found and it is working so far, it is just to copy
all the python/site-packages from pythonxy to the site-packages of the
GPyI.
>
> But it is just a work around, IMHO the best option should be to be able
to choose during the installation process which one should be used by
GRASS.
>
> Pietro

see my two comments above and change ''env.bat'' accordingly in L9 and
L10.

if that works, the option logic has to be added in the nsis-installer
script.

Helmut

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2333#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by glynn):

Replying to [comment:4 zarch]:

> The problem if choosing a different python interpreter could be the
ctypes binding of python that must be re-compiled, isn't it?

No. The ctypes module allows you to define Python wrappers for C functions
using only Python code. Nothing in a compiled GRASS package links against
the Python DLL/DSO (there used to be a couple of binary components in
wxGUI, but those have long since been removed).

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2333#comment:6&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by zarch):

Replying to [comment:5 hellik]:
> see my two comments above and change ''env.bat'' accordingly in L9 and
L10.
>
> if that works, the option logic has to be added in the nsis-installer
script.

Thanks Helmut. Sorry for the delay, but I had to install all on my windows
environment to be free to test, before I was using the computer of one of
my colleagues... :slight_smile:

ok, so I created a new bat file called: grass70svn_xy.bat that contains:

{{{
set GISBASE=C:\Users\PZambelli\Documents\GRASS GIS 7.0.0svn

rem => add a environmental variable for pythonxy
set PY_XY=C:\Python27

rem => reading the env file for pxthonxy
call "%GISBASE%\etc\env_xy.bat"

cd "%USERPROFILE%"
"%GRASS_PYTHON%" "%GISBASE%\etc\grass70.py" %*

if %ERRORLEVEL% GEQ 1 pause
}}}

and in etc I added a new env_xy.bat file with:

{{{
set GRASS_SH=%GISBASE%\msys\bin\sh.exe

set GRASS_HTML_BROWSER=chrome

rem GRASS_PYTHON=%GISBASE%\extrabin\python.exe
set GRASS_PYTHON=%PY_XY%\python.exe

rem PYTHONHOME=%GISBASE%\Python27
set PYTHONHOME=%PY_XY%

set GRASS_PROJSHARE=%GISBASE%\share\proj

set PROJ_LIB=%GISBASE%\share\proj
set GDAL_DATA=%GISBASE%\share\gdal
set GEOTIFF_CSV=%GISBASE%\share\epsg_csv

set PATH=%GISBASE%\msys\bin;%PATH%
set PATH=%GISBASE%\extrabin;%PATH%
set PATH=%GISBASE%\bin;%PATH%
}}}

Then I open a cmd prompt, I move to the GISBASE directory and run:
grass70svn_xy.bat...

every is working without errors and the GUI is starting, from the GRASS
cmd prompt I got:

{{{
GRASS 7.0.0svn> python -c "import sys; print(sys.executable)"
c:\Users\PZambelli\Documents\GRASS GIS 7.0.0svn\extrabin\python.exe
}}}

and the same result from the GUI command console,

But from the command prompt if I check the GRASS_PYTHON environment it
seems to be set correctly:

{{{
GRASS 7.0.0svn> echo $GRASS_PYTHON$
C:\Python27\python.exe$
}}}

But I got this error If I try to use the GRASS_PYTHON interpreter:

{{{
GRASS 7.0.0svn> $GRASS_PYTHON$
sh.exe": C:\Python27\python.exe$: No such file or directory
}}}

Instead the GUI Python shell is using the pythonxy interpreter:

{{{
>>> import sys; sys.executable
C:\Python27\python.exe
}}}

So it seemes to work, I guess...

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2333#comment:7&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by zarch):

Replying to [comment:6 glynn]:
> Replying to [comment:4 zarch]:
>
> > The problem if choosing a different python interpreter could
> > be the ctypes binding of python that must be re-compiled, isn't it?
>
> No. The ctypes module allows you to define Python wrappers for
> C functions using only Python code. Nothing in a compiled GRASS
> package links against the Python DLL/DSO (there used to be a
> couple of binary components in wxGUI, but those have long since
> been removed).

Perfect! thank you for the clarification!

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2333#comment:8&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by hellik):

Replying to [comment:7 zarch]:
>
> But I got this error If I try to use the GRASS_PYTHON interpreter:
>
>
> {{{
> GRASS 7.0.0svn> $GRASS_PYTHON$
> sh.exe": C:\Python27\python.exe$: No such file or directory
> }}}

try

{{{
GRASS 7.1.svn> $GRASS_PYTHON
}}}

see no $ at the end (works here)

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2333#comment:9&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by zarch):

Replying to [comment:9 hellik]:
> Replying to [comment:7 zarch]:
> >
> > But I got this error If I try to use the GRASS_PYTHON interpreter:
> >
> >
> > {{{
> > GRASS 7.0.0svn> $GRASS_PYTHON$
> > sh.exe": C:\Python27\python.exe$: No such file or directory
> > }}}
>
> try
>
> {{{
> GRASS 7.1.svn> $GRASS_PYTHON
> }}}
>
> see no $ at the end (works here)

Right, It's working... sorry for the typo!

ok, next week I will try to look in to the nsis script to see if is it
possible to add this option during the installation process.

Helmut Thanks for the help.

Pietro

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2333#comment:10&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by hellik):

Replying to [comment:10 zarch]:
>
> ok, next week I will try to look in to the nsis script to see if is it
possible to add this option during the installation process.

some steps may be:

- add e new installer gui-section "Customize python" (or something like
that)

- add some explanations to the gui-section "Customize python": e.g.
compatible wxpython, numpy, matplotlib, etc. are needed, ...

- default option: %GRASS_PYTHON% is the packaged python

- user option: ask the user for the %PATH% to the user wanted python

technical implementation - some pointers:

- let point %GRASS_PYTHON% to the user defined python:

a few years ago I've added two string replace functions to the nsis-
script:

https://trac.osgeo.org/grass/browser/grass/trunk/mswindows/GRASS-
Installer.nsi.tmpl#L104

https://trac.osgeo.org/grass/browser/grass/trunk/mswindows/GRASS-
Installer.nsi.tmpl#L338

use some of these functions to adjust %GRASS_PYTHON% and %PYTHONHOME% in
''env.bat'' to the user defined paths by a e.g. if/else statement

techn

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2333#comment:11&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by zarch):

Replying to [comment:11 hellik]:
> Replying to [comment:10 zarch]:
> >
> > ok, next week I will try to look in to the nsis script to see if
> > it is possible to add this option during the installation process.
>
> some steps may be:
>
> - add e new installer gui-section "Customize python" (or something like
that)
>
> - add some explanations to the gui-section "Customize python": e.g.
compatible wxpython, numpy, matplotlib, etc. are needed, ...
>
> - default option: %GRASS_PYTHON% is the packaged python
>
> - user option: ask the user for the %PATH% to the user wanted python

[[BR]]

Thank you Helmut for your help.

I'm not sure If I understood how to add a new section, I wrote:

{{{
Section "Customize python" CustomizePython
         ;Declares variables for optional Python interpreter
         Var /GLOBAL PYINTERPRETER
         Var /GLOBAL PYHOME

         ;Set default values for the Python Interpreter
         ${If} $ASK_FOR_PYINTERP == "NO"
                 StrCpy $PYINTERPRETER "%GISBASE%\extrabin\python.exe"
         ${Else}
                 StrCpy $PYINTERPRETER "$INST_PYINTERP"
         ${EndIf}

         ;Set default values for the Python home folder
         ${If} $ASK_FOR_PYHOME == "NO"
                 StrCpy $PYHOME "%GISBASE%\Python27"
         ${Else}
                 StrCpy $PYHOME "$INST_PYHOME"
         ${EndIf}

         ;Create the etc\env.bat
         ClearErrors
         FileOpen $0 $INSTALL_DIR\etc\env.bat w
         IfErrors done_create_grass_environments.bat
         FileWrite $0 '@echo off$\r$\n'
         FileWrite $0 'rem
#########################################################################$\r$\n'
         FileWrite $0 'rem #$\r$\n'
         FileWrite $0 'rem # File dynamically created by NSIS installer
script;$\r$\n'
         FileWrite $0 'rem #$\r$\n'
         FileWrite $0 'rem
#########################################################################$\r$\n'
         FileWrite $0 'rem #$\r$\n'
         FileWrite $0 'rem # Environmental variables for GRASS stand-alone
installer$\r$\n'
         FileWrite $0 'rem #$\r$\n'
         FileWrite $0 'rem
#########################################################################$\r$\n'
         FileWrite $0 '$\r$\n'
         FileWrite $0 'set GRASS_SH=%GISBASE%\msys\bin\sh.exe$\r$\n'
         FileWrite $0 '$\r$\n'
         FileWrite $0 'set GRASS_HTML_BROWSER=explorer"$\r$\n'
         FileWrite $0 '$\r$\n'
         FileWrite $0 'set GRASS_PYTHON=$PYINTERPRETER$\r$\n'
         FileWrite $0 'set PYTHONHOME=$PYHOME$\r$\n'
         FileWrite $0 '$\r$\n'
         FileWrite $0 'set GRASS_PROJSHARE=%GISBASE%\share\proj$\r$\n'
         FileWrite $0 '$\r$\n'
         FileWrite $0 'set PROJ_LIB=%GISBASE%\share\proj$\r$\n'
         FileWrite $0 'set GDAL_DATA=%GISBASE%\share\gdal$\r$\n'
         FileWrite $0 'set GEOTIFF_CSV=%GISBASE%\share\epsg_csv$\r$\n'
         FileWrite $0 '$\r$\n'
         FileWrite $0 'set PATH=%GISBASE%\msys\bin;%PATH%$\r$\n'
         FileWrite $0 'set PATH=%GISBASE%\extrabin;%PATH%$\r$\n'
         FileWrite $0 'set PATH=%GISBASE%\bin;%PATH%$\r$\n'
         FileClose $0
SectionEnd
}}}

Do you see any better way to implement this, avoiding to generate the
env.bat file?

How can I define as optional to set the path to the python interpreter and
to the python home in the GUI?
Where should I add the description with the python requirements (numpy,
wxpython, etc)?

There is a way to view/test the modified NSIS file?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2333#comment:12&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by martinl):

Replying to [comment:12 zarch]:

> There is a way to view/test the modified NSIS file?

Ideal place would be trunk (+ daily builds). Unfortunately daily builds of
winGRASS 7.1 (trunk) are completely broken (1)* thanks to r60679 (so
called "magic to break the whole system"). We could probably try to fix it
first(?).

* basically every command currently fails

{{{
Traceback (most recent call last):
  File "c:/osgeo4w/usr/src/grass_trunk/dist.i686-pc-
mingw32/scripts/d.out.file.py", line 59, in <module>
    main()
  File "c:/osgeo4w/usr/src/grass_trunk/dist.i686-pc-
mingw32/scripts/d.out.file.py", line 44, in main
    options, flags = gcore.parser()
  File "c:\osgeo4w\usr\src\grass_trunk\dist.i686-pc-
mingw32\etc\python\grass\script\core.py", line 647, in parser
    p = Popen(['g.parser', '-n'] + argv, stdout=PIPE)
  File "c:\OSGeo4W\apps\Python27\lib\subprocess.py", line 711, in __init__
    errread, errwrite)
  File "c:\OSGeo4W\apps\Python27\lib\subprocess.py", line 948, in
_execute_child
    startupinfo)
WindowsError: [Error 2] Systzt uveden soubor
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2333#comment:13&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by zarch):

Hi Martin,

Replying to [comment:13 martinl]:
> Replying to [comment:12 zarch]:
>
> > There is a way to view/test the modified NSIS file?
>
> Ideal place would be trunk (+ daily builds). Unfortunately daily
> builds of winGRASS 7.1 (trunk) are completely broken (1)* thanks
> to r60679 (so called "magic to break the whole system"). We could
> probably try to fix it first(?).

If I interpreted correctly [0], the solution should be to generate the
.bat files for each GRASS module/scripts written in python, right?.

Do you think that could be possible to generate the .bat files in the NSIS
file during the installation process?

Do you think that the NSIS file is the correct place where these .bat
files should be generated or we should put this action in some other place
during the installation process?

Pietro

[0] https://www.mail-archive.com/grass-dev@lists.osgeo.org/msg35001.html

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2333#comment:14&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by martinl):

Replying to [comment:14 zarch]:

> If I interpreted correctly [0], the solution should be to generate the
.bat files for each GRASS module/scripts written in python, right?.

no, r60679 simply broke running all commands (ie. also running exe files
from python), see the traceback from the previous comment.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2333#comment:15&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by martinl):

Replying to [comment:14 zarch]:
> Do you think that could be possible to generate the .bat files in the
NSIS file during the installation process?

in GRASS 6 bat files are generated by building system
source:grass/branches/releasebranch_6_4/include/Make/Script.make#L26. I
have local patch for that on my machine, but I still hope that r60679 will
be somehow fixed firstly.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2333#comment:16&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by martinl):

Replying to [comment:15 martinl]:
> Replying to [comment:14 zarch]:
>
> > If I interpreted correctly [0], the solution should be to generate the
.bat files for each GRASS module/scripts written in python, right?.
>
> no, r60679 simply broke running all commands (ie. also running exe files
from python), see the traceback from the previous comment.

http://wingrass.fsv.cvut.cz/grass71/logs/log-r60827-992/

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2333#comment:17&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by hellik):

Replying to [comment:12 zarch]:
> Replying to [comment:11 hellik]:
> > Replying to [comment:10 zarch]:
> > >
> > > ok, next week I will try to look in to the nsis script to see if
> > > it is possible to add this option during the installation process.
> >
> > some steps may be:
> >
> > - add e new installer gui-section "Customize python" (or something
like that)
> >
> > - add some explanations to the gui-section "Customize python": e.g.
compatible wxpython, numpy, matplotlib, etc. are needed, ...
> >
> > - default option: %GRASS_PYTHON% is the packaged python
> >
> > - user option: ask the user for the %PATH% to the user wanted python
>
> [[BR]]
>
> Thank you Helmut for your help.
>
> I'm not sure If I understood how to add a new section, I wrote:
>
> {{{
> Section "Customize python" CustomizePython
> ;Declares variables for optional Python interpreter
> Var /GLOBAL PYINTERPRETER
> Var /GLOBAL PYHOME
>
> ;Set default values for the Python Interpreter
> ${If} $ASK_FOR_PYINTERP == "NO"
> StrCpy $PYINTERPRETER "%GISBASE%\extrabin\python.exe"
> ${Else}
> StrCpy $PYINTERPRETER "$INST_PYINTERP"
> ${EndIf}
>
> ;Set default values for the Python home folder
> ${If} $ASK_FOR_PYHOME == "NO"
> StrCpy $PYHOME "%GISBASE%\Python27"
> ${Else}
> StrCpy $PYHOME "$INST_PYHOME"
> ${EndIf}
>
>
> ;Create the etc\env.bat
> ClearErrors
> FileOpen $0 $INSTALL_DIR\etc\env.bat w
> IfErrors done_create_grass_environments.bat
> FileWrite $0 '@echo off$\r$\n'
> FileWrite $0 'rem
#########################################################################$\r$\n'
> FileWrite $0 'rem #$\r$\n'
> FileWrite $0 'rem # File dynamically created by NSIS installer
script;$\r$\n'
> FileWrite $0 'rem #$\r$\n'
> FileWrite $0 'rem
#########################################################################$\r$\n'
> FileWrite $0 'rem #$\r$\n'
> FileWrite $0 'rem # Environmental variables for GRASS stand-alone
installer$\r$\n'
> FileWrite $0 'rem #$\r$\n'
> FileWrite $0 'rem
#########################################################################$\r$\n'
> FileWrite $0 '$\r$\n'
> FileWrite $0 'set GRASS_SH=%GISBASE%\msys\bin\sh.exe$\r$\n'
> FileWrite $0 '$\r$\n'
> FileWrite $0 'set GRASS_HTML_BROWSER=explorer"$\r$\n'
> FileWrite $0 '$\r$\n'
> FileWrite $0 'set GRASS_PYTHON=$PYINTERPRETER$\r$\n'
> FileWrite $0 'set PYTHONHOME=$PYHOME$\r$\n'
> FileWrite $0 '$\r$\n'
> FileWrite $0 'set GRASS_PROJSHARE=%GISBASE%\share\proj$\r$\n'
> FileWrite $0 '$\r$\n'
> FileWrite $0 'set PROJ_LIB=%GISBASE%\share\proj$\r$\n'
> FileWrite $0 'set GDAL_DATA=%GISBASE%\share\gdal$\r$\n'
> FileWrite $0 'set GEOTIFF_CSV=%GISBASE%\share\epsg_csv$\r$\n'
> FileWrite $0 '$\r$\n'
> FileWrite $0 'set PATH=%GISBASE%\msys\bin;%PATH%$\r$\n'
> FileWrite $0 'set PATH=%GISBASE%\extrabin;%PATH%$\r$\n'
> FileWrite $0 'set PATH=%GISBASE%\bin;%PATH%$\r$\n'
> FileClose $0
> SectionEnd
> }}}
>
> Do you see any better way to implement this, avoiding to generate the
env.bat file?
>
> How can I define as optional to set the path to the python interpreter
and to the python home in the GUI?
> Where should I add the description with the python requirements (numpy,
wxpython, etc)?
>
> There is a way to view/test the modified NSIS file?

Hi Pietro,

I'm travelling, no chance to look at it at the moment.

there is no need to write a new env.bat file, just replace the path string
in the existing env.bat.

Helmut

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2333#comment:18&gt;
GRASS GIS <http://grass.osgeo.org>

#2333: choose python interpreter during the GRASS installation on windows
--------------------------------------------------+-------------------------
Reporter: zarch | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.1.0
Component: Python | Version: svn-trunk
Keywords: windows installer python interpreter | Platform: MSWindows 8
      Cpu: All |
--------------------------------------------------+-------------------------

Comment(by glynn):

Replying to [comment:15 martinl]:

> > If I interpreted correctly [0], the solution should be to generate the
.bat files for each GRASS module/scripts written in python, right?.
>
> no, r60679 simply broke running all commands (ie. also running exe files
from python), see the traceback from the previous comment.

Ugh. So without shell=True it requires an explicit .exe suffix if the
program has a dot in its name. And with shell=True, it interprets
characters such as "|", "<", ">" and I don't know what else.

So, do we mimic the shell (locate the program and determine its suffix),
or use it (and determine the escaping rules so that "special" character
get passed through to the underlying program correctly)?

I still don't consider the previous approach (use the shell, don't bother
escaping anything) to be a viable solution.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2333#comment:19&gt;
GRASS GIS <http://grass.osgeo.org>