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