[GRASS-windows] Python collections module
Frank Broniewski
brfr at metrico.lu
Wed Feb 10 01:45:26 EST 2010
Hello Luigi,
It seems that your python path is not set. You get yet a different error
because of this. In your case your test.py should set it accordingly like
so:
import sys
import os
#Try to import GRASS GIS Python module
if "GISBASE" in os.environ:
osgeo4w_root = os.path.normpath(os.environ["OSGEO4W_ROOT"])
gis_base = os.path.normpath(os.environ["GISBASE"])
grass_python_path = os.path.join(gis_base, "etc", "python")
std_python_path = os.path.join(osgeo4w_root, "apps", "Python25", "Lib")
sys.path.append(grass_python_path)
sys.path.append(std_python_path)
if "PYTHONPATH" not in os.environ:
os.environ["PYTHONPATH"] = grass_python_path + os.pathsep +
std_python_path
try:
import grass.script as grass
except ImportError:
print os.environ["PYTHONPATH"]
This code sets the PYTHONPATH environment variable to your grass gis
installation directory. If you could execute that code again. If you get my
mentioned error or nothing at all the code works. I hope this isn't too much
trouble
Many thanks
Frank
--------------------------------------------------
From: "Luigi Ponti" <lponti at infinito.it>
Sent: Tuesday, February 09, 2010 11:23 AM
To: "Frank Broniewski" <brfr at metrico.lu>
Cc: "Glynn Clements" <glynn at gclements.plus.com>; "grass-windows"
<grass-windows at lists.osgeo.org>
Subject: Re: [GRASS-windows] Python collections module
> On 09/02/2010 08:03, Frank Broniewski wrote:
>> Hello,
>>
>> Thanks for your answer, Glynn. I don't find a python25.dll in my stock
>> installation, but it works too. I am just a little bit worried that the
>> shipped version from the osgeo4w installer doesn't work as expected. When
>> I replace the osgeo4w version with the stock version everything works.
>>
>> Can someone confirm this? Sample code to reproduce my error:
>> test.py
>> --------------
>> import sys
>> import os
>> import grass.script as grass
>>
>> gives me the below mentioned error. It's because
>> Python25/Lib/threading.py does:
>> from collections import deque.
> Hi,
>
> This is what I get on my osgeo4w grass:
>
> GRASS 6.4.0svn (AEA_US)> python --version
> Python 2.5.2
>
> GRASS 6.4.0svn (AEA_US)> python test.py
> Traceback (most recent call last):
> File "test.py", line 3, in <module>
> import grass.script as grass
> ImportError: No module named grass.script
>
> Regards,
> Luigi
>
>>
>> Now I wonder if I should report this as a bug, because reinstalling
>> osgeo4w doesn't solve the problem. If someone can confirm this I would
>> report it, but I hesitate. I will test this behavior on another
>> installation today and I will see if I encounter this error message
>> again.
>>
>> Many thanks
>>
>> Frank
>>
>> --------------------------------------------------
>> From: "Glynn Clements" <glynn at gclements.plus.com>
>> Sent: Monday, February 08, 2010 9:11 PM
>> To: "Frank Broniewski" <brfr at metrico.lu>
>> Cc: "grass-windows" <grass-windows at lists.osgeo.org>
>> Subject: Re: [GRASS-windows] Python collections module
>>
>>>
>>> Frank Broniewski wrote:
>>>
>>>> I am using the osgeo4w installation and I want to use the python
>>>> scripting
>>>> possibilities.
>>>> When I try to import the grass module I get an ImportError "No module
>>>> named
>>>> collections" from "C:\OSGeo4W\apps\Python25\lib\threading.py".
>>>> And indeed there is no collections.py. When I look into my Python26
>>>> installation dir, there is a collections.py in Python26\Lib. Is the
>>>> osgeo4w
>>>> python package broken? Reinstalling does not fix the missing
>>>> collections
>>>> module.
>>>> I appreciate any help with this problem
>>>
>>> The Python documentation says that the collections module was added in
>>> 2.4.
>>>
>>> I have both Python 2.5 and Python 2.6 installed on Windows (both are
>>> the stock python.org versions). 2.5 doesn't have a collections.py, but
>>> "import collections" works from the IDE. AFAICT, the collections
>>> module is built into python25.dll.
>>>
>>> --
>>> Glynn Clements <glynn at gclements.plus.com>
>>
>> _______________________________________________
>> grass-windows mailing list
>> grass-windows at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/grass-windows
>>
>
More information about the grass-windows
mailing list