Pyinstaller: Exe throws ModuleNotFoundError: No module named ‘…’

im a new programmer (6 month) and use this forum for the first time. So please allow me missing information and incorrect entries.

I wrote my own logging package, and like to import it into another software from me. In vscode everything working and my package get loaded correctly and can be used. In my venv i can see the files (logging_*.json) under the configs folder, which i missing in the executable.

I like to use my modul without changing something on the pyinstaller with –add-data or adding the generatet spec file. Because i want that someone import my modul and dont need to think about something like that.

I set the repository on github on public:
[https://github.com/Zoorn/logging2](Logging Repository)

This is the folder structure of my logging project:
logging/
├── setup.py
└── bub_logger/
├── init.py
├── bub_logger.py
├── configs/
├── init.py
├── logging_console.json
└── logging_file.json

My Setup.py (dont use wheels at the moment)

from setuptools import find_packages, setup

setup(
    name="bub_logger",
    version="0.0.1",
    packages=find_packages(),
    include_package_data=True,
    long_description=open("README.md").read(),
    long_description_content_type="text/markdown",
    description="A flexible and extendable logging module",
    install_requires=[
        "PyYAML",  # Für YAML-Unterstützung
    ],
    entry_points={
        "console_scripts": [
            "bub_logger=bub_logger:main",
        ],
    },
    package_data={
        "bub_logger": ["configs/*"],
    },
    author="-",
    author_email="-",
    url="-",
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
    python_requires=">=3.7",
)

how i load the config in bub_logger.py:

import importlib.resources as pkg_resources

load_config(...):
        config_data = None
        for ext in ["json", "yaml", "yml"]:
            try:
                config_file_path = pkg_resources.files("bub_logger.configs").joinpath(
                    f"{config_file}.{ext}"
                )
                with config_file_path.open("r") as file:
                    config_data = file.read()
                    if ext == "json":
                        config = json.loads(config_data)
                    else:
                        config = yaml.safe_load(config_data)
                    break
            except FileNotFoundError:
                continue

        if config_data is None:
            raise FileNotFoundError(f"Configuration file {config_file} not found.")
 ......

How my task in vscode is defined to create the executable with pyinstaller. Its use the .venv interprete so it should load the installed packages -> bub_logger as well.

    {
      "label": "Build",
      "type": "shell",
      "command": "${workspaceFolder}\.venv\Scripts\python",
      "args": [
        "-m",
        "PyInstaller",
        "--noconfirm",
        "--log-level=INFO",
        "--onefile",
        "--windowed",
        "--workpath=.\BuildTmp",
        "--icon=..\source\images\Prog.ico",
        "..\openhmi.py"
      ],
      "options": {
        "cwd": "${workspaceFolder}/build/"
      },
      "dependsOrder": "sequence",
      "dependsOn": ["CompileImages", "mkdirBuild", "Clean"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": []
    },

so if i run the build process and start the executable after this i get the following error:

Traceback (most recent call last):
  File "openhmi.py", line 59, in <module>
  File "bub_loggerbub_logger.py", line 92, in load_config
  File "importlibresources_common.py", line 46, in wrapper
  File "importlibresources_common.py", line 56, in files
  File "functools.py", line 909, in wrapper
  File "importlibresources_common.py", line 82, in _
  File "importlib__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'bub_logger.configs

Here we see the bub_logger is importet and is used from the executable… it just dont find the configs files, which are needed.

what i am doing wrong? I asked chatgpt and other ai but every ai just return me same suggestion, which not working and the ai can’t get away from this suggestion anymore.

Thanks in advance.

i have try to get the content of the executable with:
pyi-archive_viewer .openhmi.exe > test.txt

but it not realy helped me

Contents of 'openhmi.exe' (PKG/CArchive):
 position, length, uncompressed_length, is_compressed, typecode, name
 0, 233, 289, 1, 'm', 'struct'
 233, 3825, 7438, 1, 'm', 'pyimod01_archive'
 4058, 10014, 23131, 1, 'm', 'pyimod02_importers'
 14072, 2731, 6154, 1, 'm', 'pyimod03_ctypes'
 16803, 955, 1684, 1, 'm', 'pyimod04_pywin32'
 17758, 1020, 1835, 1, 's', 'pyiboot01_bootstrap'
 18778, 886, 1530, 1, 's', 'pyi_rth_inspect'
 19664, 677, 1224, 1, 's', 'pyi_rth_pyqt5'
 20341, 1313, 2315, 1, 's', 'pyi_rth_pkgutil'
 21654, 2061, 4058, 1, 's', 'pyi_rth_multiprocessing'
 23715, 1665, 2853, 1, 's', 'openhmi'
 25380, 187392, 590112, 1, 'b', 'PyQt5\Qt5\bin\MSVCP140.dll'
 212772, 14704, 31728, 1, 'b', 'PyQt5\Qt5\bin\MSVCP140_1.dll'
 227476, 2730495, 6023664, 1, 'b', 'PyQt5\Qt5\bin\Qt5Core.dll'
 2957971, 186854, 436720, 1, 'b', 'PyQt5\Qt5\bin\Qt5DBus.dll'
 3144825, 2617501, 7008240, 1, 'b', 'PyQt5\Qt5\bin\Qt5Gui.dll'
 5762326, 568060, 1340400, 1, 'b', 'PyQt5\Qt5\bin\Qt5Network.dll'
 6330386, 1384258, 3591664, 1, 'b', 'PyQt5\Qt5\bin\Qt5Qml.dll'
 7714644, 188610, 438768, 1, 'b', 'PyQt5\Qt5\bin\Qt5QmlModels.dll'
 7903254, 1620975, 4148720, 1, 'b', 'PyQt5\Qt5\bin\Qt5Quick.dll'
 9524229, 134827, 330736, 1, 'b', 'PyQt5\Qt5\bin\Qt5Svg.dll'
 9659056, 60405, 149488, 1, 'b', 'PyQt5\Qt5\bin\Qt5WebSockets.dll'
 9719461, 2486436, 5498352, 1, 'b', 'PyQt5\Qt5\bin\Qt5Widgets.dll'
 12205897, 22414, 44528, 1, 'b', 'PyQt5\Qt5\bin\VCRUNTIME140_1.dll'
 12228311, 1750408, 4173928, 1, 'b', 'PyQt5\Qt5\bin\d3dcompiler_47.dll'
 13978719, 11075, 25072, 1, 'b', 'PyQt5\Qt5\bin\libEGL.dll'
 13989794, 1279082, 3385328, 1, 'b', 'PyQt5\Qt5\bin\libGLESv2.dll'
 15268876, 7763398, 20923392, 1, 'b', 'PyQt5\Qt5\bin\opengl32sw.dll'
 23032274, 30839, 68080, 1, 'b', 'PyQt5\Qt5\plugins\generic\qtuiotouchplugin.dll'
 23063113, 19828, 41968, 1, 'b', 'PyQt5\Qt5\plugins\iconengines\qsvgicon.dll'
 23082941, 19831, 39408, 1, 'b', 'PyQt5\Qt5\plugins\imageformats\qgif.dll'
 23102772, 21660, 45040, 1, 'b', 'PyQt5\Qt5\plugins\imageformats\qicns.dll'
 23124432, 18524, 38384, 1, 'b', 'PyQt5\Qt5\plugins\imageformats\qico.dll'
 23142956, 121065, 421360, 1, 'b', 'PyQt5\Qt5\plugins\imageformats\qjpeg.dll'
 23264021, 15397, 32240, 1, 'b', 'PyQt5\Qt5\plugins\imageformats\qsvg.dll'
 23279418, 15033, 31728, 1, 'b', 'PyQt5\Qt5\plugins\imageformats\qtga.dll'
 23294451, 136072, 390128, 1, 'b', 'PyQt5\Qt5\plugins\imageformats\qtiff.dll'
 23430523, 14444, 30192, 1, 'b', 'PyQt5\Qt5\plugins\imageformats\qwbmp.dll'
 23444967, 243280, 510448, 1, 'b', 'PyQt5\Qt5\plugins\imageformats\qwebp.dll'
 23688247, 447370, 844784, 1, 'b', 'PyQt5\Qt5\plugins\platforms\qminimal.dll'
 24135617, 402492, 754672, 1, 'b', 'PyQt5\Qt5\plugins\platforms\qoffscreen.dll'
 24538109, 188469, 482288, 1, 'b', 'PyQt5\Qt5\plugins\platforms\qwebgl.dll'
 24726578, 726834, 1477104, 1, 'b', 'PyQt5\Qt5\plugins\platforms\qwindows.dll'
 25453412, 29636, 68592, 1, 'b', 'PyQt5\Qt5\plugins\platformthemes\qxdgdesktopportal.dll'
 25483048, 68007, 144368, 1, 'b', 'PyQt5\Qt5\plugins\styles\qwindowsvistastyle.dll'
 25551055, 738447, 2482176, 1, 'b', 'PyQt5\QtCore.pyd'
 26289502, 719707, 2490880, 1, 'b', 'PyQt5\QtGui.pyd'
 27009209, 1313056, 5160960, 1, 'b', 'PyQt5\QtWidgets.pyd'
 28322265, 55154, 120320, 1, 'b', 'PyQt5\sip.cp312-win_amd64.pyd'
 28377419, 58206, 119192, 1, 'b', 'VCRUNTIME140.dll'
 28435625, 25850, 49528, 1, 'b', 'VCRUNTIME140_1.dll'
 28461475, 45480, 84760, 1, 'b', '_bz2.pyd'
 28506955, 58434, 125208, 1, 'b', '_ctypes.pyd'
 28565389, 120859, 252696, 1, 'b', '_decimal.pyd'
 28686248, 29946, 65816, 1, 'b', '_hashlib.pyd'
 28716194, 88542, 159512, 1, 'b', '_lzma.pyd'
 28804736, 19483, 35096, 1, 'b', '_multiprocessing.pyd'
 28824219, 17975, 32536, 1, 'b', '_queue.pyd'
 28842194, 39925, 83224, 1, 'b', '_socket.pyd'
 28882119, 70879, 177432, 1, 'b', '_ssl.pyd'
 28952998, 20138, 36632, 1, 'b', '_wmi.pyd'
 28973136, 1859475, 5191960, 1, 'b', 'libcrypto-3.dll'
 30832611, 23195, 39696, 1, 'b', 'libffi-8.dll'
 30855806, 282334, 787224, 1, 'b', 'libssl-3.dll'
 31138140, 96982, 199448, 1, 'b', 'pyexpat.pyd'
 31235122, 23160, 68376, 1, 'b', 'python3.dll'
 31258282, 2580097, 7009048, 1, 'b', 'python312.dll'
 33838379, 17476, 30488, 1, 'b', 'select.pyd'
 33855855, 417900, 1137944, 1, 'b', 'unicodedata.pyd'
 34273755, 92814, 222720, 1, 'b', 'yaml\_yaml.cp312-win_amd64.pyd'
 34366569, 110, 130, 1, 'x', 'PyQt5\Qt5\translations\qt_ar.qm'
 34366679, 119, 153, 1, 'x', 'PyQt5\Qt5\translations\qt_bg.qm'
 34366798, 119, 153, 1, 'x', 'PyQt5\Qt5\translations\qt_ca.qm'
 34366917, 124, 157, 1, 'x', 'PyQt5\Qt5\translations\qt_cs.qm'
 34367041, 121, 153, 1, 'x', 'PyQt5\Qt5\translations\qt_da.qm'
 34367162, 120, 153, 1, 'x', 'PyQt5\Qt5\translations\qt_de.qm'
 34367282, 25, 16, 1, 'x', 'PyQt5\Qt5\translations\qt_en.qm'
 34367307, 118, 153, 1, 'x', 'PyQt5\Qt5\translations\qt_es.qm'
 34367425, 77186, 293121, 1, 'x', 'PyQt5\Qt5\translations\qt_fa.qm'
 34444611, 97, 117, 1, 'x', 'PyQt5\Qt5\translations\qt_fi.qm'
 34444708, 119, 153, 1, 'x', 'PyQt5\Qt5\translations\qt_fr.qm'
 34444827, 76, 70, 1, 'x', 'PyQt5\Qt5\translations\qt_gd.qm'
 34444903, 78978, 323590, 1, 'x', 'PyQt5\Qt5\translations\qt_gl.qm'
 34523881, 78, 83, 1, 'x', 'PyQt5\Qt5\translations\qt_he.qm'
 34523959, 2804, 8743, 1, 'x', 'PyQt5\Qt5\translations\qt_help_ar.qm'
 34526763, 3125, 10599, 1, 'x', 'PyQt5\Qt5\translations\qt_help_bg.qm'
 34529888, 2224, 7444, 1, 'x', 'PyQt5\Qt5\translations\qt_help_ca.qm'
 34532112, 3810, 15297, 1, 'x', 'PyQt5\Qt5\translations\qt_help_cs.qm'
 34535922, 1524, 4795, 1, 'x', 'PyQt5\Qt5\translations\qt_help_da.qm'
 34537446, 2311, 7570, 1, 'x', 'PyQt5\Qt5\translations\qt_help_de.qm'
 34539757, 25, 16, 1, 'x', 'PyQt5\Qt5\translations\qt_help_en.qm'
 34539782, 3103, 10704, 1, 'x', 'PyQt5\Qt5\translations\qt_help_es.qm'
 34542885, 3090, 10922, 1, 'x', 'PyQt5\Qt5\translations\qt_help_fr.qm'
 34545975, 3187, 10891, 1, 'x', 'PyQt5\Qt5\translations\qt_help_gl.qm'
 34549162, 3114, 10284, 1, 'x', 'PyQt5\Qt5\translations\qt_help_hu.qm'
 34552276, 3050, 10612, 1, 'x', 'PyQt5\Qt5\translations\qt_help_it.qm'
 34555326, 2760, 7917, 1, 'x', 'PyQt5\Qt5\translations\qt_help_ja.qm'
 34558086, 2034, 5708, 1, 'x', 'PyQt5\Qt5\translations\qt_help_ko.qm'
 34560120, 2882, 9673, 1, 'x', 'PyQt5\Qt5\translations\qt_help_pl.qm'
 34563002, 2282, 7288, 1, 'x', 'PyQt5\Qt5\translations\qt_help_ru.qm'
 34565284, 3260, 10388, 1, 'x', 'PyQt5\Qt5\translations\qt_help_sk.qm'
 34568544, 3181, 10363, 1, 'x', 'PyQt5\Qt5\translations\qt_help_sl.qm'
 34571725, 1564, 4629, 1, 'x', 'PyQt5\Qt5\translations\qt_help_tr.qm'
 34573289, 3108, 9750, 1, 'x', 'PyQt5\Qt5\translations\qt_help_uk.qm'
 34576397, 2531, 6441, 1, 'x', 'PyQt5\Qt5\translations\qt_help_zh_CN.qm'
 34578928, 3150, 9301, 1, 'x', 'PyQt5\Qt5\translations\qt_help_zh_TW.qm'
 34582078, 114, 146, 1, 'x', 'PyQt5\Qt5\translations\qt_hu.qm'
 34582192, 119, 153, 1, 'x', 'PyQt5\Qt5\translations\qt_it.qm'
 34582311, 115, 146, 1, 'x', 'PyQt5\Qt5\translations\qt_ja.qm'
 34582426, 115, 146, 1, 'x', 'PyQt5\Qt5\translations\qt_ko.qm'
 34582541, 46643, 165383, 1, 'x', 'PyQt5\Qt5\translations\qt_lt.qm'
 34629184, 86, 89, 1, 'x', 'PyQt5\Qt5\translations\qt_lv.qm'
 34629270, 128, 161, 1, 'x', 'PyQt5\Qt5\translations\qt_pl.qm'
 34629398, 18980, 70334, 1, 'x', 'PyQt5\Qt5\translations\qt_pt.qm'
 34648378, 130, 164, 1, 'x', 'PyQt5\Qt5\translations\qt_ru.qm'
 34648508, 124, 157, 1, 'x', 'PyQt5\Qt5\translations\qt_sk.qm'
 34648632, 61702, 228428, 1, 'x', 'PyQt5\Qt5\translations\qt_sl.qm'
 34710334, 18206, 65851, 1, 'x', 'PyQt5\Qt5\translations\qt_sv.qm'
 34728540, 91, 110, 1, 'x', 'PyQt5\Qt5\translations\qt_tr.qm'
 34728631, 131, 164, 1, 'x', 'PyQt5\Qt5\translations\qt_uk.qm'
 34728762, 40216, 117347, 1, 'x', 'PyQt5\Qt5\translations\qt_zh_CN.qm'
 34768978, 107, 141, 1, 'x', 'PyQt5\Qt5\translations\qt_zh_TW.qm'
 34769085, 48163, 160017, 1, 'x', 'PyQt5\Qt5\translations\qtbase_ar.qm'
 34817248, 47497, 165337, 1, 'x', 'PyQt5\Qt5\translations\qtbase_bg.qm'
 34864745, 57942, 210159, 1, 'x', 'PyQt5\Qt5\translations\qtbase_ca.qm'
 34922687, 50353, 174701, 1, 'x', 'PyQt5\Qt5\translations\qtbase_cs.qm'
 34973040, 51815, 181387, 1, 'x', 'PyQt5\Qt5\translations\qtbase_da.qm'
 35024855, 59624, 220467, 1, 'x', 'PyQt5\Qt5\translations\qtbase_de.qm'
 35084479, 25, 16, 1, 'x', 'PyQt5\Qt5\translations\qtbase_en.qm'
 35084504, 46937, 165170, 1, 'x', 'PyQt5\Qt5\translations\qtbase_es.qm'
 35131441, 50753, 179941, 1, 'x', 'PyQt5\Qt5\translations\qtbase_fi.qm'
 35182194, 46368, 166167, 1, 'x', 'PyQt5\Qt5\translations\qtbase_fr.qm'
 35228562, 50693, 189580, 1, 'x', 'PyQt5\Qt5\translations\qtbase_gd.qm'
 35279255, 42852, 138690, 1, 'x', 'PyQt5\Qt5\translations\qtbase_he.qm'
 35322107, 46650, 160494, 1, 'x', 'PyQt5\Qt5\translations\qtbase_hu.qm'
 35368757, 45046, 161172, 1, 'x', 'PyQt5\Qt5\translations\qtbase_it.qm'
 35413803, 43169, 129911, 1, 'x', 'PyQt5\Qt5\translations\qtbase_ja.qm'
 35456972, 52269, 156799, 1, 'x', 'PyQt5\Qt5\translations\qtbase_ko.qm'
 35509241, 44974, 153608, 1, 'x', 'PyQt5\Qt5\translations\qtbase_lv.qm'
 35554215, 46899, 162982, 1, 'x', 'PyQt5\Qt5\translations\qtbase_pl.qm'
 35601114, 58556, 203767, 1, 'x', 'PyQt5\Qt5\translations\qtbase_ru.qm'
 35659670, 37339, 125763, 1, 'x', 'PyQt5\Qt5\translations\qtbase_sk.qm'
 35697009, 56449, 194487, 1, 'x', 'PyQt5\Qt5\translations\qtbase_tr.qm'
 35753458, 46633, 158274, 1, 'x', 'PyQt5\Qt5\translations\qtbase_uk.qm'
 35800091, 45464, 127849, 1, 'x', 'PyQt5\Qt5\translations\qtbase_zh_TW.qm'
 35845555, 544159, 1703997, 1, 'x', 'base_library.zip'
 36389714, 157527, 290282, 1, 'x', 'certifi\cacert.pem'
 36547241, 8, 0, 1, 'x', 'certifi\py.typed'
 36547249, 2317932, 2317932, 0, 'z', 'PYZ-00.pyz'
? ? 

New contributor

Robert Wölte is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật