Creating isolated userland Python virtualenvs in TrueNAS

Current Capabilities within TrueNAS

While there is a community demand for console monitoring using btop, the developers stick with htop. Even though htop has been cranked up ( NAS-129043 / HTOP Default Configuration ) there might be a desire for one or the other to use btop instead.

Feature & UI comparison

Feature / aspecthtopb(py)top
Processes & Resource overview
CPU (overall & per-process), memory & swap, process list, process tree, load averages.
Everything htop shows — plus network throughput per interface, disk I/O activity and speeds, per-core CPU usage, swap/RAM graphs, optional battery / extra stats (if supported), per-process I/O stats and more comprehensive system overview
Visual InterfaceText-based, color-coded, minimal graphs (bars)More “graphical” in terminal: real-time graphs, charts, more layout blocks (e.g. network, disk, CPU cores)
Ease-of-use for quick checksVery quick, minimal overhead, fast startup — good for SSH, low-resource serversMore data, more “eye-candy”, but maybe overkill for quick/simple checks — better when you want a full overview

To ensure immutable and predictable deployments, TrueNAS disables the installation of Debian packages. Consequently, the python3-venv package is not included by default, preventing the creation of isolated Python virtual environments, including userland virtual environments.

If you try to create a Python virtualenv in TrueNAS, you will get the following error message:

admin@truenas[/mnt/myplace]$ sudo python3 -m venv venv_btop

The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.11-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: /mnt/myplace/venv_btop/bin/python3

However as mentioned above, package installation is disabled and running the command sudo apt-get install python3-venv results in the protection error zsh: permission denied: apt-get

Solution

While the command python3 -m venv venv fails, it does manages to create the basic virtualenv folder structure and also installs a Python binary.

Bash
admin@truenas[/mnt/myplace]$ ls -l
total 42
drwxr-xr-x 4 root  4 Dec  5 16:45 ./
drwxr-xr-x 7 root  7 Oct 29 09:58 ../
drwxr-xr-x 5 root  7 Dec  5 16:45 venv_btop/
Virtualenvs can be used in two ways: persistent or one-off. The virtualenv created in TrueNAS, cannot be used in a persistent way because it is missing the activate script. However, calling the Python binary in the virtualenv is enough to execute code in an isolate manner.

The next step is to enable installation of Python packages. Since pip is not available it is necessary to bootstrap it. This can be done downloading an executable and packaged version of pip.

Bash
admin@truenas[/mnt/myspace]$ wget -c https://bootstrap.pypa.io/pip/pip.pyz
--2025-12-05 16:46:28--  https://bootstrap.pypa.io/pip/pip.pyz
Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 2a04:4e42:8e::175, 146.75.120.175
Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|2a04:4e42:8e::175|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1721080 (1.6M) [application/octet-stream]
Saving to: ‘pip.pyz’
pip.pyz                           100%[===========================================================>]   1.64M  --.-KB/s    in 0.1s
2025-12-05 16:46:28 (11.0 MB/s) - ‘pip.pyz’ saved [1721080/1721080]

Using the packaged version of pip (pip.pyz), it is possible to install the proper pip package inside the virtualenv.

Bash
admin@truenas[/mnt/myspace]$ sudo ./venv_bbytop/bin/python3 ./pip.pyz install pip
Collecting pip
  Downloading pip-25.3-py3-none-any.whl.metadata (4.7 kB)
Downloading pip-25.3-py3-none-any.whl (1.8 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 12.1 MB/s  0:00:00
Installing collected packages: pip
Successfully installed pip-25.3

With pip installed the virtualenv is for all intended purposes feature complete and complex packages can now be easily installed.

Bash
admin@truenas[/mnt/myspace]$ sudo venv_btop/bin/pip3 install bpytop
Collecting bpytop
  Downloading bpytop-1.0.68-py3-none-any.whl.metadata (19 kB)
Collecting psutil<6.0.0,>=5.7.0 (from bpytop)
  Downloading psutil-5.9.8-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (21 kB)
Downloading bpytop-1.0.68-py3-none-any.whl (83 kB)
Downloading psutil-5.9.8-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (288 kB)
Installing collected packages: psutil, bpytop
Successfully installed bpytop-1.0.68 psutil-5.9.8

Console monitoring of a TrueNAS server is now achievable without installing system-wide operating system packages or Python libraries. All Python code is contained within an isolated virtual environment.