[GRASS-user] WinGRASS Python 2.7

Hello,

because I want to use some pythonscripts that only work (or can be installed) with Python 2.7, I'd like to couple my WinGRASS 6.4.1 with my
Python2.7 installation instead of the GRASS-Python.

So my Setup:
* Windows 7
* WinGRASS 6.4.1 (most recent)
* Python 2.7

Following Environemtal Variables are set:
* PATH includes C:\Python27
* GRASS_PYTHON includes C:\Python27\python.exe
* PYTHONPATH includes %GISBASE%\etc\python

So my questions:
1) How can I check which Pyhton is in use by WinGrass?
2) Is there anything else I've to set?

Thank you very much!
best regards
Johannes
--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone

Johannes Radinger wrote:

because I want to use some pythonscripts that only work (or can be
installed) with Python 2.7, I'd like to couple my WinGRASS 6.4.1
with my Python2.7 installation instead of the GRASS-Python.

So my Setup:
* Windows 7
* WinGRASS 6.4.1 (most recent)
* Python 2.7

Following Environemtal Variables are set:
* PATH includes C:\Python27
* GRASS_PYTHON includes C:\Python27\python.exe
* PYTHONPATH includes %GISBASE%\etc\python

So my questions:
1) How can I check which Pyhton is in use by WinGrass?

The wx GUI uses GRASS_PYTHON. To check which version is being used:

1. Start the wx GUI
2. Bring up Windows' Task Manager
3. Switch to the Processes tab
4. Find the python.exe (or pythonw.exe) process in the list
5. Right click on the entry for the process
6. Choose "Open File Location" from the menu

Python scripts which are "executed" from a command prompt will use
whichever Python version is associated with the .py file extension.

Scripts which are executed from bash will use the script's "#!" line.
If you use "#!/usr/bin/env python", it will use the first python.exe
in the path. You can check which version of Python is used by adding
e.g. "print sys.version" to the script.

2) Is there anything else I've to set?

Ensure that PYTHONHOME is /not/ set.

--
Glynn Clements <glynn@gclements.plus.com>

Hi,

2011/8/30 Glynn Clements <glynn@gclements.plus.com>:

So my questions:
1) How can I check which Pyhton is in use by WinGrass?

starting with 6.4.2 wxGUI has also python shell ('Python shell' tab in
Layer Manager) [1]. Here you can also see which version of Python is
used.

Martin

[1] http://grass.osgeo.org/wiki/File:Wxgui-pyshell.png

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

Hi,

-------- Original-Nachricht --------

Datum: Tue, 30 Aug 2011 20:35:30 +0100
Von: Glynn Clements <glynn@gclements.plus.com>
An: "Johannes Radinger" <JRadinger@gmx.at>
CC: grass-windows@lists.osgeo.org, grass-user@lists.osgeo.org
Betreff: Re: [GRASS-windows] WinGRASS Python 2.7

Johannes Radinger wrote:

> because I want to use some pythonscripts that only work (or can be
> installed) with Python 2.7, I'd like to couple my WinGRASS 6.4.1
> with my Python2.7 installation instead of the GRASS-Python.
>
> So my Setup:
> * Windows 7
> * WinGRASS 6.4.1 (most recent)
> * Python 2.7
>
> Following Environemtal Variables are set:
> * PATH includes C:\Python27
> * GRASS_PYTHON includes C:\Python27\python.exe
> * PYTHONPATH includes %GISBASE%\etc\python
>
>
> So my questions:
> 1) How can I check which Pyhton is in use by WinGrass?

The wx GUI uses GRASS_PYTHON. To check which version is being used:

1. Start the wx GUI
2. Bring up Windows' Task Manager
3. Switch to the Processes tab
4. Find the python.exe (or pythonw.exe) process in the list
5. Right click on the entry for the process
6. Choose "Open File Location" from the menu

So I checked the python.exe*32 (the only python that is running) in the taskmanager (after booting and starting the wxGUI). And although
GRASS_PYTHON is set in the environmental variables to C:\Python27\python.exe, the python which is used is still the GRASS-Python in
the path C:\Programm Files(x64)\GRASS 6.4.1\extrabin\python.exe

So what causes this? How can I proceed? What should I check?

PYTHONHOME is NOT set!

Any suggestion what causes the problem?

/Johannes

Python scripts which are "executed" from a command prompt will use
whichever Python version is associated with the .py file extension.

Scripts which are executed from bash will use the script's "#!" line.
If you use "#!/usr/bin/env python", it will use the first python.exe
in the path. You can check which version of Python is used by adding
e.g. "print sys.version" to the script.

> 2) Is there anything else I've to set?

Ensure that PYTHONHOME is /not/ set.

--
Glynn Clements <glynn@gclements.plus.com>

--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone

Johannes Radinger wrote:

So I checked the python.exe*32 (the only python that is running) in
the taskmanager (after booting and starting the wxGUI). And although
GRASS_PYTHON is set in the environmental variables to
C:\Python27\python.exe, the python which is used is still the
GRASS-Python in the path C:\Programm Files(x64)\GRASS
6.4.1\extrabin\python.exe

So what causes this? How can I proceed? What should I check?

How did you set GRASS_PYTHON?

AFAIK, it's set in %GISBASE%\etc\env.bat; this will override any
global setting.

--
Glynn Clements <glynn@gclements.plus.com>

Hi,

-------- Original-Nachricht --------

Datum: Wed, 31 Aug 2011 20:49:30 +0100
Von: Glynn Clements <glynn@gclements.plus.com>
An: "Johannes Radinger" <JRadinger@gmx.at>
CC: grass-user@lists.osgeo.org, grass-windows@lists.osgeo.org
Betreff: Re: [GRASS-windows] WinGRASS Python 2.7

Johannes Radinger wrote:

> So I checked the python.exe*32 (the only python that is running) in
> the taskmanager (after booting and starting the wxGUI). And although
> GRASS_PYTHON is set in the environmental variables to
> C:\Python27\python.exe, the python which is used is still the
> GRASS-Python in the path C:\Programm Files(x64)\GRASS
> 6.4.1\extrabin\python.exe
>
> So what causes this? How can I proceed? What should I check?

How did you set GRASS_PYTHON?

AFAIK, it's set in %GISBASE%\etc\env.bat; this will override any
global setting.

I set the environmental variables in the environment settings in the system properties as I was told some months ago here in the mailing list.
Anyway I found the env.bat file. It contains besides others following lines:

rem Path to the python directory
set PYTHONHOME=%GISBASE%\Python25
if "x%GRASS_PYTHON%" == "x" set GRASS_PYTHON=python

What exactly should be changed there and how should i look like? As I said
before, the Python I want to be used is C:\Python27\python.exe. As it is set in the environemntal variables do I just need to delete it from the env.bat or what shoul I do exactly?

/johannes

--
Glynn Clements <glynn@gclements.plus.com>

--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone

Johannes Radinger wrote:

> How did you set GRASS_PYTHON?
>
> AFAIK, it's set in %GISBASE%\etc\env.bat; this will override any
> global setting.

I set the environmental variables in the environment settings in the
system properties as I was told some months ago here in the mailing
list.

Ah; GRASS_PYTHON is only set in env.bat if it isn't already set.
PYTHONHOME and PATH are set unconditionally.

Anyway I found the env.bat file. It contains besides others following
lines:

rem Path to the python directory
set PYTHONHOME=%GISBASE%\Python25
if "x%GRASS_PYTHON%" == "x" set GRASS_PYTHON=python

What exactly should be changed there and how should i look like? As I
said before, the Python I want to be used is C:\Python27\python.exe.
As it is set in the environemntal variables do I just need to delete
it from the env.bat or what shoul I do exactly?

The above should only set GRASS_PYTHON if it isn't already set.
However, the env.bat file also sets PATH, which may cause the bundled
version to be used in some cases.

If you want to use a system version of Python, I'd suggest disabling
the PYTHONHOME and GRASS_PYTHON settings in env.bat, and removing or
renaming any python.exe/pythonw.exe from the extrabin directory.

The original reason for bundling Python was that the GUI included a
couple of binary components (vdigit and nviz), which would only work
with the specific version of Python against which they were built.
Those components have since been removed, but currently we don't have
anyone who is able and willing to fix the Window installer.

--
Glynn Clements <glynn@gclements.plus.com>

The original reason for bundling Python was that the GUI included a
couple of binary components (vdigit and nviz), which would only work
with the specific version of Python against which they were built.
Those components have since been removed, but currently we don't have
anyone who is able and willing to fix the Window installer.

for a starting point see "WinGrass using www.python.org-installation":
http://trac.osgeo.org/grass/ticket/1282

best regards
Helmut

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/WinGRASS-Python-2-7-tp6742359p6751818.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Hello again!

As recommended I did the changes.
I just tried to first disable the PYTHONHOME and
GRASS_PYTHON. The lines in the env.bat file are now:

rem Path to the python directory
rem set PYTHONHOME=%GISBASE%\Python25
rem if "x%GRASS_PYTHON%" == "x" set GRASS_PYTHON=python

is that correct?

I tried at this step to start GRASS but it doesn't work
anymore. Nothing is started!! So it seems that this isn't
working! Maybe I have to set the path to python.org in the
env.bat, but I don't know how the lines should look like.

What to do next? Is that a kind of bug in the WinGRASS version?

/johannes

-------- Original-Nachricht --------

Datum: Thu, 1 Sep 2011 20:49:21 +0100
Von: Glynn Clements <glynn@gclements.plus.com>
An: "Johannes Radinger" <JRadinger@gmx.at>
CC: grass-user@lists.osgeo.org, grass-windows@lists.osgeo.org
Betreff: Re: [GRASS-user] Re: [GRASS-windows] WinGRASS Python 2.7

Johannes Radinger wrote:

> > How did you set GRASS_PYTHON?
> >
> > AFAIK, it's set in %GISBASE%\etc\env.bat; this will override any
> > global setting.
>
>
> I set the environmental variables in the environment settings in the
> system properties as I was told some months ago here in the mailing
> list.

Ah; GRASS_PYTHON is only set in env.bat if it isn't already set.
PYTHONHOME and PATH are set unconditionally.

> Anyway I found the env.bat file. It contains besides others following
> lines:
>
> rem Path to the python directory
> set PYTHONHOME=%GISBASE%\Python25
> if "x%GRASS_PYTHON%" == "x" set GRASS_PYTHON=python
>
>
> What exactly should be changed there and how should i look like? As I
> said before, the Python I want to be used is C:\Python27\python.exe.
> As it is set in the environemntal variables do I just need to delete
> it from the env.bat or what shoul I do exactly?

The above should only set GRASS_PYTHON if it isn't already set.
However, the env.bat file also sets PATH, which may cause the bundled
version to be used in some cases.

If you want to use a system version of Python, I'd suggest disabling
the PYTHONHOME and GRASS_PYTHON settings in env.bat, and removing or
renaming any python.exe/pythonw.exe from the extrabin directory.

The original reason for bundling Python was that the GUI included a
couple of binary components (vdigit and nviz), which would only work
with the specific version of Python against which they were built.
Those components have since been removed, but currently we don't have
anyone who is able and willing to fix the Window installer.

--
Glynn Clements <glynn@gclements.plus.com>
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone

Johannes Radinger wrote:

As recommended I did the changes.
I just tried to first disable the PYTHONHOME and
GRASS_PYTHON. The lines in the env.bat file are now:

rem Path to the python directory
rem set PYTHONHOME=%GISBASE%\Python25
rem if "x%GRASS_PYTHON%" == "x" set GRASS_PYTHON=python

is that correct?

I tried at this step to start GRASS but it doesn't work
anymore. Nothing is started!! So it seems that this isn't
working! Maybe I have to set the path to python.org in the
env.bat, but I don't know how the lines should look like.

For the GUI, setting e.g.:

  set GRASS_PYTHON=c:\Program Files (x86)\Python27\pythonw.exe

should suffice.

If you want to run Python scripts from bash, you may run into problems
if there are any spaces in any of the directories. Using an 8.3
filename may work, e.g.:

  export PATH=$PATH:/c/PROGRA~2/Python27/pythonw.exe

Running Python scripts from cmd.exe should use the file association
for the .py extension.

--
Glynn Clements <glynn@gclements.plus.com>

Hi again,

sorry for posting again, but somehow I can't get it work to
run GRASS GIS using my local Python 2.7 installation.
See comments below:

-------- Original-Nachricht --------

Datum: Mon, 5 Sep 2011 01:57:38 +0100
Von: Glynn Clements <glynn@gclements.plus.com>
An: "Johannes Radinger" <JRadinger@gmx.at>
CC: grass-user@lists.osgeo.org, grass-windows@lists.osgeo.org
Betreff: Re: [GRASS-user] Re: [GRASS-windows] WinGRASS Python 2.7

Johannes Radinger wrote:

> As recommended I did the changes.
> I just tried to first disable the PYTHONHOME and
> GRASS_PYTHON. The lines in the env.bat file are now:
>
> rem Path to the python directory
> rem set PYTHONHOME=%GISBASE%\Python25
> rem if "x%GRASS_PYTHON%" == "x" set GRASS_PYTHON=python
>
> is that correct?
>
>
> I tried at this step to start GRASS but it doesn't work
> anymore. Nothing is started!! So it seems that this isn't
> working! Maybe I have to set the path to python.org in the
> env.bat, but I don't know how the lines should look like.

For the GUI, setting e.g.:

  set GRASS_PYTHON=c:\Program Files (x86)\Python27\pythonw.exe

should suffice.

So what I tried now were three different settings in the env.bat

1)
rem Path to the python directory
set PYTHONHOME=%GISBASE%\Python25
rem if "x%GRASS_PYTHON%" == "x" set GRASS_PYTHON=python
set GRASS_PYTHON=C:\Program Files (x86)\Python27\pythonw.exe

in this case: GRASS is starting using the Python25

2)
rem Path to the python directory
rem set PYTHONHOME=%GISBASE%\Python25
rem if "x%GRASS_PYTHON%" == "x" set GRASS_PYTHON=python
set GRASS_PYTHON=C:\Program Files (x86)\Python27\pythonw.exe

in this case: Nothing is started!

3)
rem Path to the python directory
rem set PYTHONHOME=%GISBASE%\Python25
rem if "x%GRASS_PYTHON%" == "x" set GRASS_PYTHON=python
set C:\Program Files (x86)\Python27
set GRASS_PYTHON=C:\Program Files (x86)\Python27\pythonw.exe

in this case: Nothing is started!

Just to inform you why I need that: I wrote a .py script (including g.parser elements) which I want to call inside GRASS with "file.py" (like any other modules e.g. r.fuzzy etc.) The script is working (tested on my Mac using GRASS in combination with Python 2.7)! The script calls scipy which can only be used in combination with Python 2.6 or newer (so far as I remember).

So hopefully this issue can be solved as soon as possible as I want to use the script also on my windows-office computer!!

Thank you
Johannes

If you want to run Python scripts from bash, you may run into problems
if there are any spaces in any of the directories. Using an 8.3
filename may work, e.g.:

  export PATH=$PATH:/c/PROGRA~2/Python27/pythonw.exe

Running Python scripts from cmd.exe should use the file association
for the .py extension.

--
Glynn Clements <glynn@gclements.plus.com>
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone

Johannes Radinger wrote:

So what I tried now were three different settings in the env.bat

Ugh. Init.bat ignores GRASS_PYTHON and just uses "python":

  python "%GISBASE%/etc/wxpython/gis_set.py"
  if %errorlevel% == 2 goto exitinit
  python "%GISBASE%/etc/wxpython/wxgui.py"

That should probably be:

  "%GRASS_PYTHON%" "%GISBASE%/etc/wxpython/gis_set.py"
  if %errorlevel% == 2 goto exitinit
  "%GRASS_PYTHON%" "%GISBASE%/etc/wxpython/wxgui.py"

GRASS_PYTHON is honoured by g.gui, the dialogs generated by the
parser, and the Unix start-up script, but not by Init.bat.

Just to inform you why I need that: I wrote a .py script (including
g.parser elements) which I want to call inside GRASS with "file.py"

Note that if you add .PY to PATHEXT, e.g.:

  set PATHEXT=%PATHEXT%;.PY

you can omit the ".py" suffix when running the script. This is the
preferred approach, for portability reasons. In 7.0 (where the shell
scripts have been replaced with Python scripts), the scripts are
installed with the .py suffix on Windows but without the suffix on
Unix. So the only portable way to run a Python script is to omit the
suffix and to rely upon PATHEXT on Windows.

(like any other modules e.g. r.fuzzy etc.) The script is working
(tested on my Mac using GRASS in combination with Python 2.7)! The
script calls scipy which can only be used in combination with Python
2.6 or newer (so far as I remember).

Note that the Python version used for scripts isn't tied to the
version used for the GUI or for the parameter dialogs (in fact, if
GRASS_GUI is set to tcltk, even Python scripts will use Tcl/Tk for the
parameter dialogs).

GRASS_PYTHON is only for the GUI and the parameter dialogs. It exists
because the GUI originally needed to use a specific version of Python
(for compatibility with binary components) which might not be the
"system" version.

On Unix (and from MSys' bash on Windows), scripts use the program
specified in the #! line (for "#!/usr/bin/env python", this will be
the first version found in the path). On Windows, they use the file
association.

--
Glynn Clements <glynn@gclements.plus.com>