1

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.

Expectations

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.

2 Answers 2

0

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!

0

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",
    },
)

Not the answer you're looking for? Browse other questions tagged or ask your own question.