首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PyInstaller: FIleNotFoundError

PyInstaller: FIleNotFoundError
EN

Stack Overflow用户
提问于 2022-07-03 23:41:57
回答 1查看 233关注 0票数 0

我正在尝试捆绑一个文件应用程序。当我试图执行我的.exe文件时,我会得到以下错误:

代码语言:javascript
复制
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!

如果我正确理解,在执行开始后,pyinstaller将创建一个临时文件夹_MEIxxxxx,它无法找到包含.dll文件的tables.libs文件夹。

  • 我尝试将这个文件夹包含到pathex中。这不管用。

代码语言:javascript
复制
pathex = ['C:\\Users\\natas\\Documents\\SINDEL\\MDM_ver1\\mdm_ver1', 'C:\\Users\\natas\\Documents\\SINDEL\\MDM_ver1\\.venv\\Lib\\site-packages\\tables.libs']

  • 然后我从文件夹中添加了每个.dll文件:

代码语言:javascript
复制
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,
)

但这也没用。

  • 只在我创建了一个单文件夹程序并手动将'tables.libs‘添加到程序目录中时才有效.

因此,我的问题是,如何将“tables.libs”包含到我的一个文件.exe中?

我的.spec文件:

代码语言:javascript
复制
# -*- 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,
)

我使用python 3.10,pyinstaller 5.1

EN

回答 1

Stack Overflow用户

发布于 2022-07-13 12:23:52

我只需要在数据中将所有.dll文件添加到tables.libs中:

代码语言:javascript
复制
datas=[(r'C:\Users\natas\Documents\SINDEL\MDM_ver1\.venv\Lib\site-packages\tables.libs\*.dll', 'tables.libs')],
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72850603

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档