I use NixOS. It stores Python modules under a unique path starting with /nix/store/.
When moonraker wants to load a system module, in particular for GPIO pins (AFAICT it is not used for anything else), it calls load_system_module function. This function runs a loop over SYS_MOD_PATHS declared as glob.glob("/usr/lib/python3*/dist-packages") + glob.glob("/usr/lib/python3*/site-packages") — i.e. looks for packages installed for any Python version.
I think this complex logic (instead of just import) is a workaround to look for other Python version's module variant.
But on NixOS there is no /usr/lib/python3* and even no /usr/lib directory. So SYS_MOD_PATHS == [] and the loop does not run at all.
As a result, even when libgpiod is properly installed and can be just imported, moonraker complains that it was Unable to import module gpiod and hence cannot use GPIO pins.
Client
Fluidd
Browser
Chrome
How to reproduce
Install Moonraker on a system with non-standard filesystem layout
Make sure that gpiod can be imported from plain Python shell
Enable any GPIO pin in Moonraker config
Observe Moonraker unable to import gpiod.
Additional information
Possible fixes:
Append some dummy path like /dev/null to the end of SYS_MOD_PATHS list;
First try to just import the module, and run all that machinery only if simple import fails.
What happened
I use NixOS. It stores Python modules under a unique path starting with
/nix/store/
. When moonraker wants to load a system module, in particular for GPIO pins (AFAICT it is not used for anything else), it callsload_system_module
function. This function runs a loop overSYS_MOD_PATHS
declared asglob.glob("/usr/lib/python3*/dist-packages") + glob.glob("/usr/lib/python3*/site-packages")
— i.e. looks for packages installed for any Python version. I think this complex logic (instead of justimport
) is a workaround to look for other Python version's module variant. But on NixOS there is no/usr/lib/python3*
and even no/usr/lib
directory. SoSYS_MOD_PATHS == []
and the loop does not run at all. As a result, even whenlibgpiod
is properly installed and can be justimport
ed, moonraker complains that it wasUnable to import module gpiod
and hence cannot use GPIO pins.Client
Fluidd
Browser
Chrome
How to reproduce
gpiod
can be imported from plain Python shellgpiod
.Additional information
Possible fixes:
/dev/null
to the end ofSYS_MOD_PATHS
list;import
the module, and run all that machinery only if simpleimport
fails.