Python Scripting, module in VENV cannot be loaded

When using the PythonScripting I’m not able to use additional modules using VENV.

I did perform the installation steps and everything looks fine:

“pythonscripting info” shows:

Python Scripting Environment:
======================================
  Runtime:
    Bundle version: 5.1.0.M2
    GraalVM version: 24.2.1
    Python version: 3.11.7
    Helper lib version: 1.0.14
    VEnv state: enabled
    Type hints: available

  Directories:
    Scripts: /openhab/conf/automation/python
    Libraries: /openhab/conf/automation/python/lib
    Typing: /openhab/conf/automation/python/typings
    Temp: /openhab/userdata/tmp
    VEnv: /openhab/userdata/cache/org.openhab.automation.pythonscripting/venv

Python Scripting Add-on Configuration:
======================================
  Python-Umgebung
    scopeEnabled: true
    helperEnabled: true
    injectionEnabled: 1

  Systemverhalten
    pipModules: unificontrol,pyunifi
    nativeModules: true
    dependencyTrackingEnabled: true
    cachingEnabled: true
    jythonEmulation: false

/openhab/userdata/cache/org.openhab.automation.pythonscripting/venv/bin/pip list

Package            Version
------------------ ----------
certifi            2025.11.12
charset-normalizer 3.4.4
idna               3.11
pip                24.3.1
pyunifi            2.21
requests           2.32.5
setuptools         80.9.0
unificontrol       0.2.9
urllib3            2.6.2
wheel              0.43.0

But when I want to load the module pyunifi in script via

import pyunifi

I get the following errors in Log:

2025-12-13 00:15:08.570 [ERROR] [hab.automation.pythonscripting.unifi] - ModuleNotFoundError, No module named 'pyunifi'
Traceback (most recent call last):
File "/openhab/conf/automation/python/unifi.py", line 9, in <module>
    import pyunifi
File "/openhab/conf/automation/python/lib/openhab/__wrapper__.py", line 93, in importWrapper
    return importOrg(name, globals, locals, fromlist, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-12-13 00:15:08.571 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script '/openhab/conf/automation/python/unifi.py': null in /openhab/conf/automation/python/unifi.py at line number 1 at column number 1
2025-12-13 00:15:08.571 [WARN ] [ort.loader.AbstractScriptFileWatcher] - Script loading error, ignoring file '/openhab/conf/automation/python/unifi.py'

Anybody an idea, what could be the reason why import and using the module with the PIP VENV does not work?

can you run “pythonscripting pip list” from inside the pythonscripting console?

Of course. Please see the output below:

openhab> pythonscripting pip list
Package            Version
------------------ ----------
certifi            2025.11.12
charset-normalizer 3.4.4
idna               3.11
pip                24.3.1
pyunifi            2.21
requests           2.32.5
setuptools         80.9.0
unificontrol       0.2.9
urllib3            2.6.2
wheel              0.43.0

That’s strange,

I found a bug right now, where the initial pip modules are not installed properly.

Means if you configure unificontrol,pyunifi as you initial pip modules, they where not installed correctly. This is fixed with the my latest pull request.

But anyway, this affects only the initial setup.

Whats confuses me, is that the pip modules are installed, what should normally not work, because of this bug.

Have you installed the pip modules somehow from outside?

I tried to reproduce the rest of you issues, but without success.

  1. I started a fresh openhab 5.1 container
  2. I installed pyunifi via pythonscripting pip install pyunifi
  3. I tested import pyunifi from pythonscripting console with success
  4. I tested import pyunifi from a python script with success
  5. After my pull request, I added unificontrol,pyunifi to my configuration and it works now too

Can you try to install the modules again via pythonscripting pip install... and verify with pythonscripting console followed by import pyunifi if it works.

I tried a lot of things yesterday. So yes, it’s possible that I installed it from somewhere else. I think I tried it from the openHAB-Pythonscripting console and directly into the docker bash using /openhab/userdata/cache/org.openhab.automation.pythonscripting/venv/bin/pip install.

openhab> pythonscripting pip install pyunifi
WARNING: Disabling truststore because platform isn't supported
Looking in indexes: https://pypi.org/simple, https://www.graalvm.org/python/wheels/
Requirement already satisfied: pyunifi in ./cache/org.openhab.automation.pythonscripting/venv/lib/python3.12/site-packages (2.21)
Requirement already satisfied: requests in ./cache/org.openhab.automation.pythonscripting/venv/lib/python3.12/site-packages (from pyunifi) (2.32.5)
Requirement already satisfied: charset_normalizer<4,>=2 in ./cache/org.openhab.automation.pythonscripting/venv/lib/python3.12/site-packages (from requests->pyunifi) (3.4.4)
Requirement already satisfied: idna<4,>=2.5 in ./cache/org.openhab.automation.pythonscripting/venv/lib/python3.12/site-packages (from requests->pyunifi) (3.11)
Requirement already satisfied: urllib3<3,>=1.21.1 in ./cache/org.openhab.automation.pythonscripting/venv/lib/python3.12/site-packages (from requests->pyunifi) (2.6.2)
Requirement already satisfied: certifi>=2017.4.17 in ./cache/org.openhab.automation.pythonscripting/venv/lib/python3.12/site-packages (from requests->pyunifi) (2025.11.12)

openhab> pythonscripting console
Python 3.11.7 (Wed Apr 02 20:07:26 CEST 2025)
[Graal, Interpreted, Java 21.0.9 (amd64)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import pyunifi
ModuleNotFoundError, No module named 'pyunifi'
Traceback (most recent call last):
File "/openhab/.cache/org.graalvm.polyglot/python/python-home/e41832d1c8ba537cb2b83ce5a12dcd2887406294/lib/python3.11/code.py", line 90, in runcode
    exec(code, self.locals)
File "<console>", line 1, in <module>
File "/openhab/conf/automation/python/lib/openhab/__wrapper__.py", line 93, in importWrapper
    return importOrg(name, globals, locals, fromlist, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Maybe I should uninstall the two modules and reinstall again? Sometimes this does some magic. :wink: If so, which way is the preferred one? Via the console? And as understood I should install first the last version of the binding?

If you want, you can test the preview version of my pull request where the initial configuration is fixed. But this needs at least openhab milstone 3. Otherwise there are conflicts regarding the correct graalvm version.

just uninstall the official binding and put the jar file into your addon folder. But for the jar file, there is no webui to configure the binding. You have to configure it manually

If so, which way is the preferred one

There is no preferred way. The initial setup or the manual setup via console makes no difference. Internally they work more or less in the same way.

For testing, you can also reset the cache folder.

Due to the several other changes in M3 I don’t want to update yet. Unfortunately a new installation of the module did not solve the problem…

Uninstalling:

openhab> pythonscripting pip uninstall pyunifi

You are uninstalling python modules.

Press Enter to confirm or Ctrl+C to cancel.

WARNING: Disabling truststore because platform isn't supported
Found existing installation: pyunifi 2.21
Uninstalling pyunifi-2.21:
  Successfully uninstalled pyunifi-2.21
openhab> pythonscripting pip list
Package            Version
------------------ ----------
certifi            2025.11.12
charset-normalizer 3.4.4
idna               3.11
pip                24.3.1
requests           2.32.5
setuptools         80.9.0
unificontrol       0.2.9
urllib3            2.6.2
wheel              0.43.0
openhab> pythonscripting console
Python 3.11.7 (Wed Apr 02 20:07:26 CEST 2025)
[Graal, Interpreted, Java 21.0.9 (amd64)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import pyunifi
ModuleNotFoundError, No module named 'pyunifi'
Traceback (most recent call last):
File "/openhab/.cache/org.graalvm.polyglot/python/python-home/e41832d1c8ba537cb2b83ce5a12dcd2887406294/lib/python3.11/code.py", line 90, in runcode
    exec(code, self.locals)
File "<console>", line 1, in <module>
File "/openhab/conf/automation/python/lib/openhab/__wrapper__.py", line 93, in importWrapper
    return importOrg(name, globals, locals, fromlist, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Re-installing:

openhab> pythonscripting pip install pyunifi
WARNING: Disabling truststore because platform isn't supported
Looking in indexes: https://pypi.org/simple, https://www.graalvm.org/python/wheels/
Loading GraalPy post-release patch repository from https://raw.githubusercontent.com/oracle/graalpython/refs/heads/github/patches/25.0.1/graalpython/lib-graalpython/patches/. This can be controlled with PIP_GRAALPY_PATCHES_URL environment variable. Set to 'disabled' to disable
Collecting pyunifi
  Downloading pyunifi-2.21-py3-none-any.whl.metadata (274 bytes)
Requirement already satisfied: requests in ./cache/org.openhab.automation.pythonscripting/venv/lib/python3.12/site-packages (from pyunifi) (2.32.5)
Requirement already satisfied: charset_normalizer<4,>=2 in ./cache/org.openhab.automation.pythonscripting/venv/lib/python3.12/site-packages (from requests->pyunifi) (3.4.4)
Requirement already satisfied: idna<4,>=2.5 in ./cache/org.openhab.automation.pythonscripting/venv/lib/python3.12/site-packages (from requests->pyunifi) (3.11)
Requirement already satisfied: urllib3<3,>=1.21.1 in ./cache/org.openhab.automation.pythonscripting/venv/lib/python3.12/site-packages (from requests->pyunifi) (2.6.2)
Requirement already satisfied: certifi>=2017.4.17 in ./cache/org.openhab.automation.pythonscripting/venv/lib/python3.12/site-packages (from requests->pyunifi) (2025.11.12)
Downloading pyunifi-2.21-py3-none-any.whl (11 kB)
Installing collected packages: pyunifi
  Looking for GraalPy patches for pyunifi
Successfully installed pyunifi-2.21
openhab> pythonscripting pip list
Package            Version
------------------ ----------
certifi            2025.11.12
charset-normalizer 3.4.4
idna               3.11
pip                24.3.1
pyunifi            2.21
requests           2.32.5
setuptools         80.9.0
unificontrol       0.2.9
urllib3            2.6.2
wheel              0.43.0
openhab> pythonscripting console
Python 3.11.7 (Wed Apr 02 20:07:26 CEST 2025)
[Graal, Interpreted, Java 21.0.9 (amd64)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import pyunifi
ModuleNotFoundError, No module named 'pyunifi'
Traceback (most recent call last):
File "/openhab/.cache/org.graalvm.polyglot/python/python-home/e41832d1c8ba537cb2b83ce5a12dcd2887406294/lib/python3.11/code.py", line 90, in runcode
    exec(code, self.locals)
File "<console>", line 1, in <module>
File "/openhab/conf/automation/python/lib/openhab/__wrapper__.py", line 93, in importWrapper
    return importOrg(name, globals, locals, fromlist, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

After deinstallation of the complete binding and reinstalling it again, the problem remains the same.

openhab> pythonscripting pip list
Package            Version
------------------ ----------
certifi            2025.11.12
charset-normalizer 3.4.4
idna               3.11
pip                24.3.1
pyunifi            2.21
requests           2.32.5
setuptools         80.9.0
unificontrol       0.2.9
urllib3            2.6.2
wheel              0.43.0
openhab> pythonscripting console
Python 3.11.7 (Wed Apr 02 20:07:26 CEST 2025)
[Graal, Interpreted, Java 21.0.9 (amd64)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import pyunifi
ModuleNotFoundError, No module named 'pyunifi'
Traceback (most recent call last):
File "/openhab/userdata/cache/org.openhab.automation.pythonscripting/python/python-home/e41832d1c8ba537cb2b83ce5a12dcd2887406294/lib/python3.11/code.py", line 90, in runcode
    exec(code, self.locals)
File "<console>", line 1, in <module>
File "/openhab/conf/automation/python/lib/openhab/__wrapper__.py", line 93, in importWrapper
    return importOrg(name, globals, locals, fromlist, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

are there any other error logs during openhab startup?

maybe you can clear the cache and initialize a new venv.

also keep in mind, if you update to M3, you have to update your graalvm to version 25.0.1

Good to know, but I think I’ll wait for the final release this time - which should include then also the upgrade of graalvm?

For the moment I’ll realize my Python scripts which needs the external module outside of openHAB. I’ll give the PythonScripting a try in future again.

But anyhow thank you for your support although it didn’t succeed (until now). Have a nice one.

the final release will be exactly the same version as the version I recommended you.

now is the only chance to fix something, you don’t want to have in the final release.

and again. I tried to reproduce with a new installation, but without success.

Understood, but unfortunately I don’t have any further idea how to understand the failure more in detail. Do you have something I could do debugging-wise? Any chance to analyze why the module is not found in console although console lists it as installed? Are there any chances to analyze something more in cosole? I’m really happy to spend some more effort but as told I have no further idea how to investigate more into deep.

And if the failure should be gone in the next milestones (and final) build I’ll be happy as soon I can do this upgrade step without causing to much interference in my setup. Just for completeness the changed layout starting from M3 causes also significant changes in some customized widget layouts in my dashboard which I have to solve first.

I did so and set up the venv newly and now it works.

And maybe I found also the root cause: On the python scripting document page, GraalVM version 24.2.1 was mentioned at one place and 25.0.1 was included in the code what to download and start. I just copied the code, so I installed a 25.0.1 venv in a 24.2.1 setup. Maybe this caused the problems.

I created a change of the documentation to avoid this mismatch.

1 Like