PyInstaller: FIleNotFoundError

746 Views Asked by At

I am trying to bundle a one-file app. When I try to execute my .exe file I get the following error:

Traceback (most recent call last):
  File "__main__.py", line 19, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "tables\__init__.py", line 38, in <module>
  File "tables\__init__.py", line 22, in _delvewheel_init_patch_0_0_17
  File "os.py", line 1117, in add_dll_directory
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\natas\\AppData\\Local\\Temp\\_MEI104162\\tables.libs'
[2216] Failed to execute script '__main__' due to unhandled exception!

If I understood correctly, after execution starts pyinstaller creates a temporary folder _MEIxxxxx and it can't find tables.libs folder which contains .dll files.

  • I tried to include this folder to pathex. It didn't work.
pathex = ['C:\\Users\\natas\\Documents\\SINDEL\\MDM_ver1\\mdm_ver1', 'C:\\Users\\natas\\Documents\\SINDEL\\MDM_ver1\\.venv\\Lib\\site-packages\\tables.libs']
  • Then I added every .dll file from the folder:
p = r'C:\Users\natas\Documents\SINDEL\MDM_ver1\.venv\Lib\site-packages\tables.libs'
added_binaries = [
    (os.path.join(p, 'blosc-965398da.dll'), '.'),
    (os.path.join(p, 'hdf5-a241c97c.dll'), '.'),
    (os.path.join(p, 'libbz2-e4ba6a29.dll'), '.'),
    (os.path.join(p, 'zlib-e2d94386.dll'), '.'),
    (os.path.join(p, 'zstd-34920894.dll'), '.')
]
a = Analysis(
    ['__main__.py'],
    pathex=['C:\\Users\\natas\\Documents\\SINDEL\\MDM_ver1\\mdm_ver1'],
    binaries=added_binaries,
    datas=[],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)

But it didn't work too.

  • Only when I created a one-folder program and manually added 'tables.libs' to program directory it worked.

So my question is how can I include 'tables.libs' to my one-file .exe?

My .spec file:

# -*- mode: python ; coding: utf-8 -*-

import os

block_cipher = None

a = Analysis(
    ['__main__.py'],
    pathex=['C:\\Users\\natas\\Documents\\SINDEL\\MDM_ver1\\mdm_ver1'],
    binaries=[],
    datas=[],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name='__main__',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)

I use python 3.10, pyinstaller 5.1

1

There are 1 best solutions below

0
knv_777 On

I just needed to add all .dll files to tables.libs in datas:

datas=[(r'C:\Users\natas\Documents\SINDEL\MDM_ver1\.venv\Lib\site-packages\tables.libs\*.dll', 'tables.libs')],