Category: General LinuxCNC Questions
Hi all,
I’ve developed a custom Python package — and not just a loose .py file, but a real multi-module package, complete with pyproject.toml, unit tests, internal structure, and even a __str__ for logging prettiness. Yes, I know, it’s total overkill for something that just drives the lubrication pump… but hey, it’s fun
The code I wrote can be found here if anyone is interested:
github.com/johanvergeer/maho-mh400e-conf...ree/main/lubrication
Now I want to use this package from a Python script that’s launched via loadusr in my machine config.
Some context:
- The script uses linuxcnc, hal, and qtvcp modules.
- LinuxCNC runs on the global system Python interpreter as far as I can see, which means my package has to be available outside of any virtual environment.
- Installing with pip install . into the global Python environment technically works, but it’s strongly discouraged on modern Debian-based systems due to PEP 668. I’ve already seen Poetry try to uninstall half of /usr/lib/python3
- Virtualenvs don’t help much either, since they can’t see LinuxCNC’s compiled modules.
- Adding my repo folder to sys.path is possible, but feels like duct tape.
So… what’s the best practice here?
- Is it acceptable to install your own packages into something like /usr/lib/python3/dist-packages/?
- Is there an officially recommended way to include custom Python packages that need to be imported across multiple files or used in different HAL components?
Or am I simply in “here be dragons” territory and should stick to a bunch of flat .py files with global state?
Any advice or patterns you use would be greatly appreciated!
Cheers,
Johan