Ghostscript # make path to libgs.so.9 available

whereis gs
gs: /nix/store/kpb01793k7xas9malkqf09fkvyyqhrwh-user-environment/bin/gs

whereis libgs.so.9
libgs.so.9:


how to make the path to libgs.so.9 available (automatic [in a nix way] or with minimal effort)?

I’m not sure where your problem is.

For me gs works out of the box and ldd reports that it finds it library:

$ ldd $(which gs) | rg libgs
        libgs.so.9 => /nix/store/d9ynhabia26r24k6drpvan6kxm5k165n-ghostscript-9.55.0/lib/libgs.so.9 (0x00007fa8bbb4d000)

python
Python 3.9.12 (main, Mar 23 2022, 21:36:19)
[GCC 10.3.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import ghostscript
Traceback (most recent call last):
  File "/nix/store/390mwhnggp6fqj1q3vhkv7slffd1hx83-buildEnv__pdf2csv_gs/lib/python3.9/site-packages/ghostscript/_gsprint.py", line 524, in <module>
    libgs = cdll.LoadLibrary("libgs.so")
  File "/nix/store/nvxp3xmlrxj9sw66dk7l0grz9m4889jn-python3-3.9.12/lib/python3.9/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/nix/store/nvxp3xmlrxj9sw66dk7l0grz9m4889jn-python3-3.9.12/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libgs.so: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nix/store/390mwhnggp6fqj1q3vhkv7slffd1hx83-buildEnv__pdf2csv_gs/lib/python3.9/site-packages/ghostscript/__init__.py", line 32, in <module>
    from . import _gsprint as gs
  File "/nix/store/390mwhnggp6fqj1q3vhkv7slffd1hx83-buildEnv__pdf2csv_gs/lib/python3.9/site-packages/ghostscript/_gsprint.py", line 531, in <module>
    libgs = cdll.LoadLibrary(libgs)
  File "/nix/store/nvxp3xmlrxj9sw66dk7l0grz9m4889jn-python3-3.9.12/lib/python3.9/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/nix/store/nvxp3xmlrxj9sw66dk7l0grz9m4889jn-python3-3.9.12/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libgs.so.9: cannot open shared object file: No such file or directory

Here I’d suggest to properly make your project shell aware of GS.

Usually I’d expect the LD_LIBRARY_PATH to be set appropriately within that shell, if it isn’t you need to do the already mentionend LD_LIBRARY_PATH = lib.lib.makeLibraryPath [ ghostscript ]; within the projects shell.