OPNsense Forum

English Forums => General Discussion => Topic started by: datenimperator on August 26, 2026, 07:42:35 AM

Title: Recommendation on installing custom Python packages
Post by: datenimperator on August 26, 2026, 07:42:35 AM
I broke my 26.7 system by tinkering with packages, resulting in an incompatible kernel which would not boot. So I started new, restored my backup and ditched ISC on my way. Fresh 26.7 with no custom packages again.

The question remains: I'd like to install a daemon written in Python, which would require a number of Python extensions. In particular

- psutil
- paho-mqtt
- pyyaml

The packages names relate to the base python version, eg py312-psutil. How would I install that, without putting my system at risk? Regards

Christian
Title: Re: Recommendation on installing custom Python packages
Post by: franco on August 26, 2026, 08:42:10 AM
Hi Christian,

Long time no see. Hope you are doing good!

So you wouldn't break the kernel with ports but a major upgrade could fail although in reality your custom packages will just stop working.

Current Python is 3.13 and most Python ports are flavoured now so I'm not entirely sure how to build them from the command line.  But anyway load the ports tree:

# opnsense-code ports

(the utility will provide the ports and tools repositories and set up /etc/make.conf for you)

Go to the respective directories and build the matching version. You probably had a similar workflow before.


Cheers,
Franco
Title: Re: Recommendation on installing custom Python packages
Post by: Patrick M. Hausen on August 26, 2026, 09:08:52 AM
Alternatively create a dedicated user from the UI and in their home directory create a virtual environment.

https://docs.python.org/3/library/venv.html
Title: Re: Recommendation on installing custom Python packages
Post by: datenimperator on August 26, 2026, 04:49:49 PM
I feel honored seeing you remember me. :-) Yes, it has been a while, though I sticked with OpnSense ever since my m0n0wall days.

Quote from: franco on August 26, 2026, 08:42:10 AMSo you wouldn't break the kernel with ports but a major upgrade could fail although in reality your custom packages will just stop working.

Current Python is 3.13 and most Python ports are flavoured now so I'm not entirely sure how to build them from the command line.  But anyway load the ports tree:

# opnsense-code ports

The ports unfortunately don't include all three packages, just pyyaml. So that won't work.

Can I safely delete /usr/ports after I learned that?
Title: Re: Recommendation on installing custom Python packages
Post by: datenimperator on August 26, 2026, 04:52:27 PM
Quote from: Patrick M. Hausen on August 26, 2026, 09:08:52 AMAlternatively create a dedicated user from the UI and in their home directory create a virtual environment.

https://docs.python.org/3/library/venv.html

I like the idea of having a non-admin user building and running that daemon. However, creating a non-root user won't let me give him a login shell: "The login shell for this non-admin user is not active for security reasons."

Is this a setting?
Title: Re: Recommendation on installing custom Python packages
Post by: franco on August 26, 2026, 05:15:28 PM
Quote from: datenimperator on August 26, 2026, 04:49:49 PMCan I safely delete /usr/ports after I learned that?

Sure.

venv/pip would be rather safe as Patrick suggests. This shouldn't clash with any system files.

Quote from: datenimperator on August 26, 2026, 04:52:27 PMI like the idea of having a non-admin user building and running that daemon. However, creating a non-root user won't let me give him a login shell: "The login shell for this non-admin user is not active for security reasons."

Is this a setting?

Add the "page-all" privilege to the user.


Cheers,
Franco