[GRASS-user] Can't use simple GRASS modules in python when not using ".py" in module call

Dear All,

I am using grass 7.8.4. I’m trying to run some simple commands using the Grass Python Scripting Library in Python. For modules for which the source code is written in C or any other language than Python, it works without problem but for the modules written in Python it does not. Here is an example of a simple command I tried to run:

import grass.script as gscript
gscript.run_command(“v.db.dropcolumn”, flags=“help”)

It raises the error:

grass.exceptions.CalledModuleError: Module run None v.db.dropcolumn --help ended with error.
Process ended with non-zero return code 9009

I already checked and I know that return code 9009 means it does not find the python script. I solved the error by just adding “.py” in the command:

gscript.run_command(“v.db.dropcolumn.py”, flags=“help”)

I would like the command to work without the “.py” because I’m writing a python script that makes use of some addons. For the addons to work in my python script I sometimes need to modify them because there are running commands like “v.db.dropcolumn” without the “.py”, so I have to add it. But then, the addons do not work anymore when I use them directly in the grass GUI. I tried to use pygrass and it also raises an error if I’m using Module(“v.db.dropcolumn”) instead of Module(“v.db.dropcolumn.py”).

Does anybody know how to solve this?

Thank you in advance for the answer,

Best,

Camille Morlighem

Dear Camille,

I don`t get that error in GRASS 7.8.3 with your example.

Can you post the exact command (if it was different from your example), and GRASS version as well as OS?

Addons need to be on your PATH / ADDON_PATH.

Cheers

Stefan

···

Dear All,

I am using grass 7.8.4. I’m trying to run some simple commands using the Grass Python Scripting Library in Python. For modules for which the source code is written in C or any other language than Python, it works without problem but for the modules written in Python it does not. Here is an example of a simple command I tried to run:

import grass.script as gscript
gscript.run_command(“v.db.dropcolumn”, flags=“help”)

It raises the error:

grass.exceptions.CalledModuleError: Module run None v.db.dropcolumn --help ended with error.
Process ended with non-zero return code 9009

I already checked and I know that return code 9009 means it does not find the python script. I solved the error by just adding “.py” in the command:

gscript.run_command(“v.db.dropcolumn.py”, flags=“help”)

I would like the command to work without the “.py” because I’m writing a python script that makes use of some addons. For the addons to work in my python script I sometimes need to modify them because there are running commands like “v.db.dropcolumn” without the “.py”, so I have to add it. But then, the addons do not work anymore when I use them directly in the grass GUI. I tried to use pygrass and it also raises an error if I’m using Module(“v.db.dropcolumn”) instead of Module(“v.db.dropcolumn.py”).

Does anybody know how to solve this?

Thank you in advance for the answer,

Best,

Camille Morlighem

Dear Stefan,

The GRASS version is 8.4.1. and the simple commands I used are the ones in my previous email.
You helped me solve the problem; I had not added the addons and “C:\Program Files\GRASS GIS 7.8\scripts” into the PATH variable. Now I did and it solved the mistake.
Thank you very much!

Cheers,
Camille

Le ven. 15 janv. 2021 à 15:08, Stefan Blumentrath <Stefan.Blumentrath@nina.no> a écrit :

Dear Camille,

I don`t get that error in GRASS 7.8.3 with your example.

Can you post the exact command (if it was different from your example), and GRASS version as well as OS?

Addons need to be on your PATH / ADDON_PATH.

Cheers

Stefan

From: grass-user <grass-user-bounces@lists.osgeo.org> On Behalf Of Cam Morlus
Sent: fredag 15. januar 2021 11:37
To: grass-user@lists.osgeo.org
Subject: [GRASS-user] Can’t use simple GRASS modules in python when not using “.py” in module call

Dear All,

I am using grass 7.8.4. I’m trying to run some simple commands using the Grass Python Scripting Library in Python. For modules for which the source code is written in C or any other language than Python, it works without problem but for the modules written in Python it does not. Here is an example of a simple command I tried to run:

import grass.script as gscript
gscript.run_command(“v.db.dropcolumn”, flags=“help”)

It raises the error:

grass.exceptions.CalledModuleError: Module run None v.db.dropcolumn --help ended with error.
Process ended with non-zero return code 9009

I already checked and I know that return code 9009 means it does not find the python script. I solved the error by just adding “.py” in the command:

gscript.run_command(“v.db.dropcolumn.py”, flags=“help”)

I would like the command to work without the “.py” because I’m writing a python script that makes use of some addons. For the addons to work in my python script I sometimes need to modify them because there are running commands like “v.db.dropcolumn” without the “.py”, so I have to add it. But then, the addons do not work anymore when I use them directly in the grass GUI. I tried to use pygrass and it also raises an error if I’m using Module(“v.db.dropcolumn”) instead of Module(“v.db.dropcolumn.py”).

Does anybody know how to solve this?

Thank you in advance for the answer,

Best,

Camille Morlighem