- LinuxCNC
- General LinuxCNC Questions
- Best practice for installing custom Python packages in LinuxCNC?
Best practice for installing custom Python packages in LinuxCNC?
- workshop54
- Offline
- New Member
-
Less
More
- Posts: 16
- Thank you received: 3
14 May 2025 13:54 - 14 May 2025 13:56 #328446
by workshop54
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:
Any advice or patterns you use would be greatly appreciated!
Cheers,
Johan
Best practice for installing custom Python packages in LinuxCNC? was created by workshop54
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.
- 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?
Any advice or patterns you use would be greatly appreciated!
Cheers,
Johan
Last edit: 14 May 2025 13:56 by workshop54.
Please Log in or Create an account to join the conversation.
- langdons
- Offline
- Platinum Member
-
Less
More
- Posts: 369
- Thank you received: 36
14 May 2025 14:16 #328452
by langdons
Replied by langdons on topic Best practice for installing custom Python packages in LinuxCNC?
Python programming is generally something of a band-aid programmed free-for-all.
Java has conventions and structure.
Python is just "whatever floats your goat".
Java has conventions and structure.
Python is just "whatever floats your goat".
Please Log in or Create an account to join the conversation.
- workshop54
- Offline
- New Member
-
Less
More
- Posts: 16
- Thank you received: 3
14 May 2025 14:34 #328459
by workshop54
Replied by workshop54 on topic Best practice for installing custom Python packages in LinuxCNC?
Fully agreed — if LinuxCNC ever gets a proper Java API, I’ll gladly throw my Python into the chip tray
Until then, I’ll just keep pretending my Python package has structure and discipline… while knowing deep down it’s all held together by logging statements and good intentions
Until then, I’ll just keep pretending my Python package has structure and discipline… while knowing deep down it’s all held together by logging statements and good intentions
Please Log in or Create an account to join the conversation.
- tommylight
-
- Away
- Moderator
-
Less
More
- Posts: 20242
- Thank you received: 6885
14 May 2025 14:47 #328463
by tommylight
Replied by tommylight on topic Best practice for installing custom Python packages in LinuxCNC?
If you want to move away from Python, try "Ruby on Rails".
Going from Python to Java is absolutely moving backwards.
Going from Python to Java is absolutely moving backwards.
Please Log in or Create an account to join the conversation.
- langdons
- Offline
- Platinum Member
-
Less
More
- Posts: 369
- Thank you received: 36
14 May 2025 14:57 #328466
by langdons
Replied by langdons on topic Best practice for installing custom Python packages in LinuxCNC?
Backwards?
In what sense?
Java is far, far more feature-rich than Python.
Python does not even have switch statements!
I think the main reason I like Java is the editor (Intellij IDEA CE) is free and good.
PyCharm just is not that great.
And I believe any life without true access modifiers is not a good life.
In what sense?
Java is far, far more feature-rich than Python.
Python does not even have switch statements!
I think the main reason I like Java is the editor (Intellij IDEA CE) is free and good.
PyCharm just is not that great.
And I believe any life without true access modifiers is not a good life.
Please Log in or Create an account to join the conversation.
- JT
-
- Away
- Administrator
-
Less
More
- Posts: 956
- Thank you received: 492
15 May 2025 11:31 #328504
by JT
Replied by JT on topic Best practice for installing custom Python packages in LinuxCNC?
Why not just build a deb and install your package?
github.com/jethornton/simple-deb
github.com/jethornton/simple-pyqt5-deb
Or if you're using Flex GUI you can just add it to your ini and it gets imported.
gnipsel.com/linuxcnc/flexgui/python.html
JT
github.com/jethornton/simple-deb
github.com/jethornton/simple-pyqt5-deb
Or if you're using Flex GUI you can just add it to your ini and it gets imported.
gnipsel.com/linuxcnc/flexgui/python.html
JT
Please Log in or Create an account to join the conversation.
- langdons
- Offline
- Platinum Member
-
Less
More
- Posts: 369
- Thank you received: 36
15 May 2025 12:29 #328508
by langdons
Replied by langdons on topic Best practice for installing custom Python packages in LinuxCNC?
Not all python executable builders actually work.
Please Log in or Create an account to join the conversation.
- LinuxCNC
- General LinuxCNC Questions
- Best practice for installing custom Python packages in LinuxCNC?
Time to create page: 0.139 seconds