[GRASS-user] Running Python scripts inside GRASS

Sonja Jankowfsky sonja.jankowfsky at cemagref.fr
Mon Mar 8 05:02:11 EST 2010


I uninstalled Python25 and 24 on my machine and reinstalled Python26 + 
the packages wxPython,

PyWin32, and NumPy. 

the ftype python.file in the command line changed to Python26 now. 
However, when I try to run the python script in GRASS I still get the following error:

 File "E:\pythoninput\test_simple.py", line 2, in <module>
     import grass.script as grass
   File "C:\GRASS-4-SVN\etc\python\grass\script\__init__.py", line 1, in 
 <module>
 
     from core   import *
  File "C:\GRASS-4-SVN\etc\python\grass\script\core.py", line 30, in 
 <module>
     import subprocess
   File "C:\GRASS-4-SVN\Python25\lib\subprocess.py", line 376, in <module>
     import threading
   File "C:\GRASS-4-SVN\Python25\lib\threading.py", line 13, in <module>
     from collections import deque
 ImportError: No module named collections

I replaced again the content of the dlls, include, Lib, libs and Scripts folder in GRASS-64-SVN/Python25 with those of my Python26 installation. 

This results again in the fact, that I can now run my Python programm in 
the GRASS command line, but I lost my wxPython interface.
I get the following error message in Msys:

C:\GRASS-4-SVN\Python25\lib\site.py:150: Warning: 'with' will become a 
reserved keyword in Python 2.6
'import site' failed; use -v for traceback
Traceback (most recent call last):
  File "c:/GRASS-4-SVN/etc/wxpython/gis_set.py", line 23, in <module>
    import os
  File "C:\GRASS-4-SVN\Python25\lib\os.py", line 758
    bs = b""
           ^
SyntaxError: invalid syntax
Error in GUI startup. If necessary, please
report this error to the GRASS developers.
Switching to text mode now.

So, the uninstalling of Python25 didn't help anything.
Does anybody has another idea?
Sonja


Glynn Clements a écrit :
> Sonja Jankowfsky wrote:
>
>   
>> So, I changed the hole content of my C:\GRASS-4-SVN\Python25 directory 
>> with the content of the C:\Python26 directory. I kept the name 
>> (Python25) of the directory and the Scripts directory and sip.exe.
>>
>> Now, I can run my Pythonprogramm under the GRASS windows command line, 
>> however I can no longer use the Pythonwx GUI. (which does not seem 
>> surprising due to the brutal changes I made ;-))
>>
>> I don't know anything about the differences between Python25 and 
>> Python26 and the dependencies for the wxpython GUI, but in my opinion it 
>> would be necessary to update the WinGRASS installation with a Python26 
>> version while keeping the compability to the wxpython GUI, in order to 
>> be able to run the python scripts inside GRASS.
>>
>>
>> Does anybody know an easier solution?
>>     
>
> Delete the copy of Python that's bundled with GRASS, and add the
> necessary packages to your system Python. IIRC, you need wxPython,
> PyWin32, and NumPy.
>
> If you have multiple versions of Python installed, the "system" Python
> is the one associated with the ".py" extension; use "ftype python.file"
> from the command prompt to find out which one this is.
>
>   


-- 
Sonja Jankowfsky
UR Hydrologie-Hydraulique
Cemagref de Lyon
3 bis quai Chauveau CP 220
69336 Lyon Cedex 09
FRANCE
Tel : (+33)4 72 20 86 11 	 
Fax : (+33)4 78 47 78 75 



More information about the grass-user mailing list