使用 pyInstaller 创建的 Exe 中的 sqlite 驱动程序崩溃,并显示消息 NotADirectoryError: MultiplexedPath 仅支持目录

问题描述 投票:0回答:1

Python 3.10.9 我正在使用 pyInstaller 创建可执行文件。我使用以下命令在 conda 环境中创建它:

python -m PyInstaller --noconfirm app.spec

app.spec 有以下内容 # -- 模式:python ;编码:utf-8 --

a = Analysis(
    ['E:\\development\\chromDB_server\\app.py'],
    pathex=['C:\\Users\\user\\.conda\\envs\\cuda118', 'C:\\Users\\user\\.conda\\envs\\cuda118\\lib\\site-packages', 'E:\\development\\chromDB_server'],
    binaries=[],
    datas=[],
    hiddenimports=['onnxruntime', 'tokenizers', 'chromadb.telemetry.posthog', 'chromadb.api.segment','chromadb.db.impl',
'chromadb.db.impl.sqlite','chromadb.migrations', 'chromadb.migrations.embeddings_queue'],
    collectsubmodules=['chromadb', 'chromadb.migrations', 'chromadb.telemetry', 'chromadb.api','chromadb.db'],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
)
pyz = PYZ(a.pure)

exe = EXE(
    pyz,
    a.scripts,
    [],
    exclude_binaries=True,
    name='app',
    clean=True,
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
coll = COLLECT(
    exe,
    a.binaries,
    a.datas,
    strip=False,
    upx=True,
    upx_exclude=[],
    name='app',
)

exe运行时的错误是;

  ...
  File "chromadb\db\impl\sqlite.py", line 65, in __init__
  File "importlib_resources\_common.py", line 46, in wrapper
  File "importlib_resources\_common.py", line 56, in files
  File "importlib_resources\_common.py", line 113, in from_package
  File "importlib_resources\_compat.py", line 79, in get_resource_reader
  File "importlib_resources\_compat.py", line 56, in _namespace_reader
  File "importlib_resources\readers.py", line 133, in __init__
  File "importlib_resources\readers.py", line 70, in __init__
  NotADirectoryError: MultiplexedPath only supports directories
  [11508] Failed to execute script 'app' due to unhandled exception!

sqlite.py 中的第 65 行如下

self._migration_imports = [
        files("chromadb.migrations.embeddings_queue"),
        ...
    ]

我已经阅读了如何使用类似代码测试冻结环境

if getattr(sys, 'frozen', False): # If the application is run as a bundle, the PyInstaller bootloader # extends the sys module by a flag frozen=True and sets the app # path into variable _MEIPASS'. application_path = sys._MEIPASS else: application_path = os.path.dirname(os.path.join('..',os.path.abspath(__file__)))
但我不确定如何在这种情况下应用它。

python-3.x pyinstaller
1个回答
0
投票
我在 PyInstaller 和 ChromaDB 中遇到了类似的问题。作为解决方法,我刚刚创建了一个空文件:

\Python\Python311\Lib\site-packages\chromadb\migrations\embeddings_queue\__init__.py
这对我来说很有效。我也对 chromadb 包的其他“未找到”子模块执行了相同的操作。

© www.soinside.com 2019 - 2024. All rights reserved.