ModuleNotFoundError: No module named 'lib'

When moving files to my docker-HABApp-config, system gives me errors and cannot localize my files under the lib-folder (or any given folder). No errors in the PyCharm-venv.

[2022-12-23 08:24:21,922] [             HABApp.Rules]    ERROR | Error "No module named 'lib'" in load:
[2022-12-23 08:24:21,922] [             HABApp.Rules]    ERROR | Could not load /habapp/config/rules/dev/ludde_rgb.py!
[2022-12-23 08:24:21,922] [             HABApp.Rules]    ERROR | File "/habapp/config/rules/dev/ludde_rgb.py", line 1 in ludde_rgb.py
[2022-12-23 08:24:21,923] [             HABApp.Rules]    ERROR | --------------------------------------------------------------------------------
[2022-12-23 08:24:21,923] [             HABApp.Rules]    ERROR | -->  1 | from lib.devices.lidl_rgb_list import LidlRgbList
[2022-12-23 08:24:21,923] [             HABApp.Rules]    ERROR |      2 | from lib.devices.ikea_remote_E2002 import IkeaRemoteE2002
[2022-12-23 08:24:21,923] [             HABApp.Rules]    ERROR | 
[2022-12-23 08:24:21,923] [             HABApp.Rules]    ERROR | --------------------------------------------------------------------------------
[2022-12-23 08:24:21,924] [             HABApp.Rules]    ERROR | Traceback (most recent call last):
[2022-12-23 08:24:21,924] [             HABApp.Rules]    ERROR |   File "/usr/local/lib/python3.10/site-packages/HABApp/rule_manager/rule_file.py", line 77, in load
[2022-12-23 08:24:21,927] [             HABApp.Rules]    ERROR |     self.create_rules(created_rules)
[2022-12-23 08:24:21,928] [             HABApp.Rules]    ERROR |   File "/usr/local/lib/python3.10/site-packages/HABApp/rule_manager/rule_file.py", line 67, in create_rules
[2022-12-23 08:24:21,928] [             HABApp.Rules]    ERROR |     runpy.run_path(str(self.path), run_name=str(self.path), init_globals=init_globals)
[2022-12-23 08:24:21,928] [             HABApp.Rules]    ERROR |   File "/usr/local/lib/python3.10/runpy.py", line 289, in run_path
[2022-12-23 08:24:21,928] [             HABApp.Rules]    ERROR |     return _run_module_code(code, init_globals, run_name,
[2022-12-23 08:24:21,929] [             HABApp.Rules]    ERROR |   File "/usr/local/lib/python3.10/runpy.py", line 96, in _run_module_code
[2022-12-23 08:24:21,929] [             HABApp.Rules]    ERROR |     _run_code(code, mod_globals, init_globals,
[2022-12-23 08:24:21,929] [             HABApp.Rules]    ERROR |   File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
[2022-12-23 08:24:21,930] [             HABApp.Rules]    ERROR |     exec(code, run_globals)
[2022-12-23 08:24:21,930] [             HABApp.Rules]    ERROR |   File "/habapp/config/rules/dev/ludde_rgb.py", line 1, in ludde_rgb.py
[2022-12-23 08:24:21,930] [             HABApp.Rules]    ERROR |     from lib.devices.lidl_rgb_list import LidlRgbList
[2022-12-23 08:24:21,931] [             HABApp.Rules]    ERROR | ModuleNotFoundError: No module named 'lib'
[2022-12-23 08:24:21,934] [             HABApp.Rules]  WARNING | Failed to load /habapp/config/rules/dev/ludde_rgb.py!

the import is without “lib.”:

from devices.lidl_rgb_list import LidlRgbList

It only works in pycharm because you probably implicitly added the “habapp” folder as a working directory.

Great, that worked!! Remains just the question of what I should do in PyCharm to avoid the syntax-highlighting and reflect the docker-installation?

I have added my docker and PyCharm-venv source-files as “Content Root”

you have to mark the “lib” folder as a source folder

1 Like

Thanks again! As reference for people as experienced as I am in using Python/PyCharm (ie… not so much but working on it). Right-click folder to get context menu, select “Mark Directory as”: “Sources Root”

image