Hi Markus!
We compiled GRASS 7.8 and this solved the problem of python3/python2 but we got the same error:
File “importgrass78.py”, line 79, in
main()
File “importgrass78.py”, line 68, in main
rcfile = gsetup.init(gisbase, gisdb, location, mapset)
File “/usr/local/grass78/etc/python/grass/script/setup.py”, line 175, in init
config_dir = os.path.join(os.getenv(‘HOME’), config_dirname)
File “/usr/lib/python3.6/posixpath.py”, line 80, in join
a = os.fspath(a)
This issue is due to running the GRASS script from php since the server is not able to retrieve the HOME path of the user www-data. Therefore, we modified the setup.py script specifying the home path in a new variable:
add addons to the PATH
copied and simplified from lib/init/grass.py
if mswin:
config_dirname = “GRASS7”
config_dir = os.path.join(os.getenv(‘APPDATA’), config_dirname)
else:
user_home = ‘/home/ubuntu/’
config_dirname = “.grass7”
config_dir = os.path.join(user_home, config_dirname)
After these changes, we were able to run GRASS from a php web page but we got a new error using certain modules like v.in.ogr:
Check if OGR layer <sql_statement> contains polygons…
0%^H^H^H^H^H 33%^H^H^H^H^H 66%^H^H^H^H^H 100%^H^H^H^H^H
WARNING: Vector map already exists and will be overwritten
Creating attribute table for layer <sql_statement>…
ERROR: Unable to determine user’s home directory
Traceback (most recent call last):
File “path3d.py”, line 297, in
main()
File “path3d.py”, line 267, in main
gscript.run_command(‘v.in.ogr’, input=‘{}/tmp/output.gpkg’.format(outdir0), layer='sql_statement$
File “/usr/local/grass78/etc/python/grass/script/core.py”, line 441, in run_command
return handle_errors(returncode, returncode, args, kwargs)
File “/usr/local/grass78/etc/python/grass/script/core.py”, line 343, in handle_errors
returncode=returncode)
The error is always the same, the php web page is not able to retrieve the home path. We solved this error setting the server home path as HOME environment variable. Adding the following lines to our GRASS python script, everything works fine and we are now able to run the script from our php web page!
home = ‘/home/ubuntu/’
os.environ[‘HOME’] = home
Hope this can help in case anyone has the same problem!
Regarding the problem installing GRASS GIS from ubuntugis unstable, I don’t know exactly what te problem is, but using ubuntugis unstable caused some conflicts with Postgis and QGIS server packages respectively installed using https://wiki.postgresql.org/wiki/Apt and https://qgis.org/ubuntu-ltr
Thanks again for yout help and your suggestions!
Roberta
···
Da: Markus Neteler neteler@osgeo.org
Inviato: domenica 4 ottobre 2020 11:04
A: roberta fagandini robifagandini@hotmail.it
Cc: Moritz Lennert mlennert@club.worldonline.be; grass-user@lists.osgeo.org grass-user@lists.osgeo.org
Oggetto: Re: [GRASS-user] R: exwcuting grass python script from php web page
Hi Roberta,
On Wed, Sep 30, 2020 at 5:12 PM roberta fagandini
robifagandini@hotmail.it wrote:
On 28/09/20 18:37, roberta fagandini wrote:
On 28/09/20 17:51, roberta fagandini wrote:
Sorry, maybe I didn’t explain myself well because actually, I don’t get
any error from the php web page, simply the code related to grass is not
executed.For instance gsetup.init(gisbase, gisdb, location, mapset) does
not create any file in my /tmp/ folder and the print(gscript.gisenv())
is not printed.
I checked the import of the grass libraries (print(sys.modules)) and
they seem to be correctly imported.
Have you checked your webservers error logs ?
I have already checked and this is the error in the webserver log file
I observe that:
File “importgrass.py”, line 82, in
main()
File “importgrass.py”, line 71, in main
rcfile = gsetup.init(gisbase, gisdb, location, mapset)
File “/usr/lib/grass74/etc/python/grass/script/setup.py”, line 170,
… you use GRASS GIS 7.4? Pretty old and outdated.
in init
config_dir = os.path.join(os.getenv(‘HOME’), config_dirname)
File “/usr/lib/python3.6/posixpath.py”, line 80, in join
… you try to use GRASS GIS 7.4 with Python 3. For this you need
GRASS GIS 7.8 as already suggested.
a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
…
I tried to upgrade GRASS using the repository ubuntugis unstable but it caused some problems with
the installation of postgis.
Which problems exactly?
$command = escapeshellcmd('/usr/bin/python3 importgrass.py ');
… Python 3, fine. But here:
I tried to run ‘/usr/bin/grass --version’ but I got a similar error:
File “/usr/bin/grass”, line 2005, in
main()
File “/usr/bin/grass”, line 1804, in main
grass_config_dir = get_grass_config_dir()
File “/usr/bin/grass”, line 398, in get_grass_config_dir
directory = os.path.join(os.getenv(‘HOME’), grass_config_dirname)
File “/usr/lib/python2.7/posixpath.py”, line 70, in join
… again Python 2.
This mixture will not work. Do you have by chance multiple GRASS GIS
versions installed?
I’d suggest removing all installed GRASS packages and reinstalling 7.8
cleanly again.
best
Markus