Repository: chroma-core/chroma

Issue #3493: importlib.metadata.PackageNotFoundError: No package metadata was found for chromadb
Created: 2025-01-15T03:07:46Z
While utilizing docker's latest image I got issues as follows
importlib.metadata.PackageNotFoundError: No package metadata was found for chromadb
Here is the complete traceback,
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/anyio/streams/memory.py", line 111, in receive
    return self.receive_nowait()
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/streams/memory.py", line 106, in receive_nowait
    raise WouldBlock
anyio.WouldBlock

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/anyio/streams/memory.py", line 124, in receive
    return receiver.item
           ^^^^^^^^^^^^^
AttributeError: 'MemoryObjectItemReceiver' object has no attribute 'item'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 157, in call_next
    message = await recv_stream.receive()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/streams/memory.py", line 126, in receive
    raise EndOfStream
anyio.EndOfStream

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/chroma/chromadb/server/fastapi/__init__.py", line 120, in catch_exceptions_middleware
    return await call_next(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 163, in call_next
    raise app_exc
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 149, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 185, in __call__
    with collapse_excgroups():
  File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 82, in collapse_excgroups
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 187, in __call__
    response = await self.dispatch_func(request, call_next)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/chroma/chromadb/server/fastapi/__init__.py", line 144, in check_http_version_middleware
    return await call_next(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 163, in call_next
    raise app_exc
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 149, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 73, in app
    response = await f(request)
               ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1009, in openapi
    return JSONResponse(self.openapi())
                        ^^^^^^^^^^^^^^
  File "/chroma/chromadb/server/fastapi/__init__.py", line 246, in generate_openapi
    version=importlib.metadata.version("chromadb"),
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/metadata/__init__.py", line 1009, in version
    return distribution(distribution_name).version
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/metadata/__init__.py", line 982, in distribution
    return Distribution.from_name(distribution_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/metadata/__init__.py", line 565, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for chromadb
INFO:     [15-01-2025 03:00:09] 172.17.0.1:60326 - "GET /openapi.json HTTP/1.1" 500


Also, while opening swagger docs it shows something like -

Duplicate issue #3755: [Bug]:  OpenAPI Docs Generation Fails with PackageNotFoundError for "chromadb"
Created: 2025-02-11T00:11:31Z
What happened?
When running the official [chromadb/chroma] Docker image, the /docs endpoint fails to load due to a missing package metadata error for the [chromadb] package. Although the core API endpoints (e.g., /api/v2/auth/identity) work correctly, the /openapi.json endpoint returns an HTTP 500 with a PackageNotFoundError.
Steps to Reproduce:
Pull the latest Docker image:
docker pull chromadb/chroma:latest
Run the container on port 8000:
docker run -d -p 8000:8000 chromadb/chroma
Access the interactive documentation in your browser at http://localhost:8000/docs.
Expected Behavior:
The interactive API documentation should load successfully, presenting the OpenAPI schema.
Actual Behavior:
The /docs (and /openapi.json) endpoint returns an HTTP 500 with the following traceback in the logs:
ERROR:    [timestamp] No package metadata was found for chromadb
Traceback (most recent call last):
...
File "/chroma/chromadb/server/fastapi/init.py", line 246, in generate_openapi
version=importlib.metadata.version("chromadb"),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/importlib/metadata/init.py", line 565, in from_name
raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for chromadb
Environment:
OS: Windows (via Docker)
Docker Image: chromadb/chroma:latest
Python Version (inside container): 3.11
Client code (for reference):

import chromadb
from functions import readtextfiles, chunksplitter, getembedding
chromaclient = chromadb.HttpClient(host="localhost", port=8000)
textdocspath = r"C:\Dev\Python Projects\PlayAndLearn\textdocs"
text_data = readtextfiles(textdocspath)
collection_name = "buildragwithpython"
collection = chromaclient.get_or_create_collection(name=collection_name, metadata={"hnsw:space": "cosine"})
for filename, text in text_data.items():
chunks = chunksplitter(text)
embeds = getembedding(chunks)
chunknumber = list(range(len(chunks)))
ids = [filename + str(index) for index in chunknumber]
metadatas = [{"source": filename} for index in chunknumber]
collection.add(ids=ids, documents=chunks, embeddings=embeds, metadatas=metadatas)
print("Collections:", chromaclient.list_collections())

collection = chromaclient.get_collection("buildragwithpython")
print("Collection details:", collection)
docs = collection.get()
print("Documents in collection:", docs)

Additional Context:
The core API endpoints work correctly as seen when calling /api/v2/auth/identity.
The error in question is solely related to generating the OpenAPI docs.
A temporary workaround is to patch the OpenAPI generation code to handle missing package metadata gracefully (e.g., returning "unknown" when metadata is not found).
Proposed Fix or Workaround:
Catch the PackageNotFoundError in the OpenAPI generation logic and return a default version, such as "unknown", so that the schema generation succeeds.
Versions
Chroma Docker Image:
chromadb/chroma:latest (Digest: sha256:e0e78dc7609a599b63c99753442c7d01b1d3d369ce0e3bf3e0540536fec4fa7a)
Python:
The container is using Python 3.11 (observed via the paths in logs, e.g. /usr/local/lib/python3.11/...).
Your local development environment (running importdocs.py) is using a virtual environment, likely Python 3.11 (confirm with python --version if needed).
Operating System:
Windows 10/11 (Running Docker on a Windows machine, as indicated by C:\Dev... paths)
Docker:
Docker version :
Cloud integration: v1.0.35+desktop.5
Version:           24.0.7
API version:       1.43
Go version:        go1.20.10
Git commit:        afdd53b
Built:             Thu Oct 26 09:08:44 2023
OS/Arch:           windows/amd64
Context:           default
Server: Docker Desktop 4.26.1 (131620)
Engine:
Version:          24.0.7
API version:      1.43 (minimum version 1.12)
Go version:       go1.20.10
Git commit:       311b9ff
Built:            Thu Oct 26 09:08:02 2023
OS/Arch:          linux/amd64
Experimental:     false
containerd:
Version:          1.6.25
GitCommit:        d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f
runc:
Version:          1.1.10
GitCommit:        v1.1.10-0-g18a0cb0
docker-init:
Version:          0.19.0
GitCommit:        de40ad0
Additional Context:
The python code in importdocs.py interacts with the Chroma server normally, but the /docs endpoint fails due to missing package metadata for the chromadb package.
Relevant log output

Closing comment (2025-02-12T12:24:54Z): @rikmohlmann, this is fixed with #3500. This is a duplicate of #3493