Using Spyder IDE to develop python for Grass GIS, get 'ImportError: No module named g

المشرف العام

Administrator
طاقم الإدارة
I am trying to use Spyder IDE to develop a python script using python library from grass-6.4.3. I run the script below, and get 'ImportError: No module named grass.script'

I am using python 2.7, installed in Grass, Spyder, + native install (C:\python27) and my OS is 64-bit Windows 7.

This seems to be a common problem, but I have tried all the recommended fixes outlined below. I have even tried installing on a laptop running 32-bit windows 7 and get the same error.

I am racking my brain, what am I missing??

Read the Grass wiki: page:https://grasswiki.osgeo.org/wiki/GRASS_and_Python#External_Python_editors_.28IDE.29

Then I have tried to follow this thread to the letter:Problem with python script to control GRASS GIS from outside - How to import grass.script under Win 8.1?

My python script:

import sysimport osgisbase = os.environ['GISBASE'] = 'C:\OSGeo4W64\apps\grass\grass-6.4.3' gisdbase = os.path.normpath('C:/Users/Ryan/grassdata')location = 'newLocation'mapset = 'Ryan'GISRC = os.path.normpath('C:/Users/Ryan/AppData/Roaming/GRASS6/grassrc6')LD_LIBRARY_PATH = 'C:\OSGeo4W64\apps\grass\grass-6.4.3\lib'PATH = 'C:\Python27';'C:\Users\Ryan\grassdata';'C:\Users\Ryan\AppData\Roaming\GRASS6\grassrc6';'C:\OSGeo4W64\bin';'C:\OSGeo4W64\apps\grass\grass-6.4.3';'C:\OSGeo4W64\apps\grass\grass-6.4.3\lib';'C:\OSGeo4W64\apps\grass\grass-6.4.3\etc\python';'C:\OSGeo4W64\apps\grass\grass-6.4.3\etc';'C:\OSGeo4W64\apps\grass\grass-6.4.3\bin';'C:\OSGeo4W64\apps\Python27';'C:\OSGeo4W64\apps\Python27\Lib\site-packages';'C:\OSGeo4W64\apps\msys';'C:\OSGeo4W64\apps\grass\grass-6.4.3\scripts'PYTHONLIB = 'C:\Python27'PYTHONPATH = 'C:\OSGeo4W64\apps\grass\grass-6.4.3\etc\python'GRASS_SH = 'C:\OSGeo4W64\apps\msys\bin\sh.exe'sys.path.append(os.path.join(os.environ['GISBASE'], 'etc', 'python'))sys.path.append('C:\OSGeo4W\bin')sys.path.append('C:\OSGeo4W64\apps\grass\grass-6.4.3\etc') sys.path.append('C:\OSGeo4W64\apps\grass\grass-6.4.3\etc\python') sys.path.append('C:\OSGeo4W64\apps\grass\grass-6.4.3\lib') sys.path.append('C:\OSGeo4W64\apps\grass\grass-6.4.3\bin') import grass.script as grassimport grass.script.setup as gsetupgsetup.init(gisbase, gisdb, location, mapset)I have added my environment variables manually into system settings (copied here):

GISBASE = C:\OSGeo4W64\apps\grass\grass-6.4.3GISDBASE = C:\Users\Ryan\grassdataGISRC = C:\Users\Ryan\AppData\Roaming\GRASS6\grassrc6GRASS_SH = C:\OSGeo4W\apps\msys\bin\sh.exeLD_LIBRARY_PATH = C:\OSGeo4W64\apps\grass\grass-6.4.3\libPATH = C:\Python27;C:\Users\Ryan\grassdata;C:\Users\Ryan\AppData\Roaming\GRASS6\grassrc6;C:\OSGeo4W64\bin;C:\OSGeo4W64\apps\grass\grass-6.4.3;C:\OSGeo4W64\apps\grass\grass-6.4.3\lib;C:\OSGeo4W64\apps\grass\grass-6.4.3\etc\python;C:\OSGeo4W64\apps\grass\grass-6.4.3\etc;C:\OSGeo4W64\apps\grass\grass-6.4.3\bin;C:\OSGeo4W64\apps\Python27;C:\OSGeo4W64\apps\Python27\Lib\site-packages;C:\OSGeo4W64\apps\msys;C:\OSGeo4W64\apps\grass\grass-6.4.3\scriptsPYTHONLIB = C:\Python27PYTHONPATH = C:\OSGeo4W\apps\grass\grass-6.4.3\etc\python'I have added a file called 'grass.pth' to: C:\OSGeo4W\apps\python27\lib\site-packages. The file contains:

C:\OSGeo4W\apps\grass\grass-6.4.3\etc\pythonC:\OSGeo4W\bin

I have started grass interactively to create a 'grassrc6' file, which is located here: C:\Users\Ryan\AppData\Roaming\GRASS6\grassrc6

I am not sure what else I can try, I am certain something must be wrong with the environment variables, but I wouldn't know what to look for.

Also, is it necessary to define the environment variables in both the python script, and manually in system settings?

Thanks in advance for your help



أكثر...
 
أعلى