Reputation: 11
I am working with the provided method to create the executable for my Python FastAPI project. Since it is an AI-based project, It contains the vector database to handle the embeddings. I am using chromadb
package to deal with embeddings. When I create the build, it gets created successfully. But when I try to run the exe file of my project it reaches the line import chromadb
. It generates the exception like this:
File "chromadb\utils\embedding_functions\__init__.py", line 57, in DefaultEmbeddingFunction
NameError: name 'ONNXMiniLM_L6_V2' is not defined
[PYI-12904:ERROR] Failed to execute script 'main' due to unhandled exception!
I have manually checked that I can run my project, both with standard uvicorn
and using Docker
as well. But when I try to package my project using pyinstaller
, it generates an exception.
P.S. I am activating the environment at the time of creating the executable so that all packages get bonded into my application (tried without it too).
If any further information is required, I can do that too.
Best, Muhammad Hassan
Here is how I am trying to create the executable of my project:
pyinstaller --name tempname --onefile --specpath . main.py
I have also tried:
pyinstaller -F main.py --clean
I have manually checked for ONNXMiniLM_L6_V2
error, and I can see that these embeddings are available.
I have the supporting package onnxruntime
installed as well.
I am expecting my executable to run when i create it for my FastAPI application with the environment activated when the exe is created with the help of pyinstaller
.
Upvotes: 1
Views: 844
Reputation: 1
This error occurs due to missing of one of the hidden imports i.e.
chromadb.utils.embedding_functions.onnx_mini_lm_l6_v2
To resolve this issue, you need to include this hidden import in your .spec file. However, addressing this will likely lead to additional errors for other missing imports. To ensure your build works correctly, you must include all required imports and also handle the migration data from the virtual environment.
Modify your .spec file to include the necessary hiddenimports and datas entries.
datas=[
('venv/Lib/site-packages/chromadb/migrations', 'chromadb/migrations'),
],
hiddenimports=[
"chromadb.utils.embedding_functions.onnx_mini_lm_l6_v2",
"onnxruntime",
"tokenizers",
"tqdm",
"chromadb.telemetry.product.posthog",
"chromadb.api.segment",
"chromadb.db.impl",
"chromadb.db.impl.sqlite",
"chromadb.migrations",
"chromadb.migrations.embeddings_queue",
"chromadb.segment.impl.manager",
"chromadb.segment.impl.manager.local",
"chromadb.execution.executor.local",
"chromadb.quota.simple_quota_enforcer",
"chromadb.rate_limit.simple_rate_limit",
"chromadb.segment.impl.metadata",
"chromadb.segment.impl.metadata.sqlite"
],
Further use the same .spec file to build the exe.
Upvotes: 0
Reputation: 1
You can try to collect all data related to the chroma DB by following my code. In you .spec file, add these lines
chromadb_datas, chromadb_binaries, chromadb_hiddenimports = collect_all("chromadb")
In the Analysis statement, add corresponding fields:
a = Analysis(
["path/to/file.py"],
pathex=[os.path.abspath(os.curdir)], # Ensure the current directory is in the path
binaries=[
*chromadb_binaries,
# other binaries
],
datas=[
*chromadb_datas,
# other datas
],
hiddenimports=[
*chromadb_hiddenimports,
# other hidden imports
],
hookspath=[],
hooksconfig={},
runtime_hooks=["set_env_vars.py"], # Add the runtime hook here
excludes=[],
noarchive=False,
optimize=0,
module_collection_mode={
"chromadb": "py",
},
)
Upvotes: 0
Reputation: 1
You should include ChromaDB onnx_mini_lm_l6_v2
in hidden imports of .spec file:
hiddenimports=["chromadb.utils.embedding_functions.onnx_mini_lm_l6_v2",]
The root cause is that the pyinstaller does not include this file while building, but the class ONNXMiniLM_L6_V2
is required in the default model through python dynamic import.
Please try this code and give me the result, thanks!
Upvotes: 0