[Bug] g.extension fails in CMake builds for script addons that import grass.pygrass at module level ("Could not load grass_gis")
I maintainer di solito rispondono entro 1 giorno
@Shreyanshsingh23 ci sta già lavorando.
Dal 23/11/2026.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- cmake, linux, python
- Ambito
- backend, build-system
Direzione di ricerca
Start by reading build_addon.cmake and tracing the environment used by the --html-description and --md-description commands through g.extension and the build process. The report identifies the missing library search path as a likely cause but has not located where it is lost, so first confirm that path. Done means script addons that import grass.pygrass or grass.lib at module level install in the described CMake environment.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
With the conda-forge GRASS 8.5 package on Linux (a CMake build), g.extension fails for script addons that import grass.pygrass or grass.lib at module level, for example r.learn.train and r.learn.predict (r.learn.ml2).
The addon build generates the manual page by running the script with --html-description. The module-level import loads libgrass_gis through ctypes, the load fails, and the build stops:
Traceback (most recent call last):
File "/tmp/tmpnbuc2gzu/r.learn.train/grass_addons/src/raster/r.learn.ml2/r.learn.train/build/output/scripts/r.learn.train", line 347, in <module>
from grass.pygrass.raster import RasterRow
File "/usr/local/lib/grass85/etc/python/grass/pygrass/raster/__init__.py", line 10, in <module>
import grass.lib.gis as libgis
File "/usr/local/lib/grass85/etc/python/grass/lib/gis.py", line 30, in <module>
_libs["grass_gis"] = load_library("grass_gis")
File "/usr/local/lib/grass85/etc/python/grass/lib/ctypes_loader.py", line 105, in __call__
raise ImportError("Could not load %s." % libname)
ImportError: Could not load grass_gis.
gmake[2]: *** [CMakeFiles/r.learn.train-docs.dir/build.make:74: output/docs/html/r.learn.train.html] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:122: CMakeFiles/r.learn.train-docs.dir/all] Error 2
gmake: *** [Makefile:124: all] Error 2
ERROR: Compilation failed, sorry. Please check above error messages.
To reproduce
On Google Colab:
pip install condacolab, thencondacolab.install()mamba install -y grass=8.5 scikit-learn- Start a session in a notebook with
grass.jupyter.init(<mapset>) gs.run_command("g.extension", extension="r.learn.train")
Discovered when testing a my courses lab in Google Colab image_classification.ipynb
Expected behavior
The addon installs. In a session started by GRASS, building an addon should not depend on the caller's dynamic library path.
What I found
-
The shared libraries are in
$GISBASE/lib(/usr/local/lib/grass85/lib), which is not a system linker directory. -
import grass.lib.gisworks in the session environment and fails as soon asLD_LIBRARY_PATHis removed, with each Python on the machine (conda Python 3.13.13 and the Colab kernel Python):/usr/local/bin/python3 -> ImportError: Could not load grass_gis. /usr/local/bin/python -> ImportError: Could not load grass_gis. /usr/bin/python3.real -> ImportError: Could not load grass_gis. -
The generated wrapper calls
add_library_search_dirs([])with an empty list, so the ctypes loader can only findlibgrass_gisthroughLD_LIBRARY_PATHor the system linker cache. -
In
build_addon.cmake, the--html-descriptionand--md-descriptioncommands set onlyPYTHONPATH,GISBASE,GISRC,VERSION_NUMBER, andVERSION_DATE. They rely on the library path being inherited. -
Setting
LD_LIBRARY_PATHto include$GISBASE/libin the notebook before callingg.extensiondid not help: the import then worked in a subprocess of the notebook, but the docs step of the build failed with the same error. I have not yet identified where the variable is lost betweeng.extension,cmake --build,gmake, and the script.
Workaround
Registering the library directory with the system linker makes the import independent of the environment, and the addons then install:
Path("/etc/ld.so.conf.d/grass.conf").write_text(f"{os.environ['GISBASE']}/lib\n")
subprocess.run(["ldconfig"], check=True)
After this, the same test without LD_LIBRARY_PATH loads the library under all three interpreters, and r.learn.train, r.learn.predict, i.superpixels.slic, i.segment.stats, r.confusionmatrix, and i.sam2 install.
Possible fixes
- In
build_addon.cmake, set the dynamic library path explicitly ($GISBASE/lib) on the commands that run the script for--html-descriptionand--md-description. - Have the ctypes wrappers in
grass.libsearch$GISBASE/lib, sograss.libandgrass.pygrassdo not depend onLD_LIBRARY_PATH.
Additional context
The same build prints CMake policy CMP0010 warnings for unescaped regular expressions in build_addon.cmake:
build_addon.cmake:56 '</body>\|</html>\|</div>.<!--.end.container.-->' Invalid escape sequence \|
build_addon.cmake:123 .*\.py$ Invalid escape sequence \.
build_addon.cmake:249 .*\.(jpg|png)$ Invalid escape sequence \.
It also warns that the addon's CMakeLists.txt calls project() without cmake_minimum_required() (r.learn.ml2/r.learn.train/CMakeLists.txt, in grass-addons).
System description
- Operating system: Google Colab (Ubuntu, x86_64)
- GRASS: 8.5 from conda-forge, installed with condacolab into
/usr/local - Python: 3.13.13 (conda)
- Lingua principale
- C
- Stelle
- 1.2k
- Fork
- 447
- Merge medio
- 2g 10h
- PR unite (30g)
- 86
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di OSGeo/grass
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] v.db.addtable expands $MAP only when it is a directoryForse già presa @alteralto l’ha presa 35 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] grass.pygrass: Cats.delete(0) deletes all layer categories instead of category 0Forse già presa @Mohit-Ak l’ha presa 40 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] macOS: Startup crashes with StopIteration when ~/Documents is not readable (macOS privacy protection)Forse già presa @NIne-WIngEd l’ha presa 46 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
OSGeo/grass#8027 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] Specify the test project nameForse già presa @Om23131212 l’ha presa 39 giorni fa. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
OSGeo/grass#7860 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 68/100
Revivedx/SavageWindRecomp#1358 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 84/100
ossc-db/pg_hint_plan#255 ·
-
Status: Opened
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
awslabs/aws-c-common#1319 ·
-
editor/integration
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
DeusData/codebase-memory-mcp#3130 ·
I maintainer di solito rispondono entro 1 giorno