chroma: [Bug]: Chromadb import error. Dependency issue: Install pydantic-settings package

What happened?

What happened? There was a PydanticImportError when trying to import chromadb. The error occurred because the BaseSettings class has been moved to the pydantic-settings package.

What did you expect to happen? I expected to import chromadb successfully without any errors.

Versions

Python 3.11.3

Relevant log output

import chromadb

---------------------------------------------------------------------------
PydanticImportError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 import chromadb

File G:\RajArun\os\chroma\chromaenv\Lib\site-packages\chromadb\__init__.py:1
----> 1 import chromadb.config
      2 import logging
      3 from chromadb.telemetry.events import ClientStartEvent

File G:\RajArun\os\chroma\chromaenv\Lib\site-packages\chromadb\config.py:1
----> 1 from pydantic import BaseSettings
      2 # from pydantic_settings import BaseSettings
      3 from typing import Optional, List, Any, Dict, TypeVar, Set, cast, Iterable, Type

File G:\RajArun\os\chroma\chromaenv\Lib\site-packages\pydantic\__init__.py:206, in __getattr__(attr_name)
    204 dynamic_attr = _dynamic_imports.get(attr_name)
    205 if dynamic_attr is None:
--> 206     return _getattr_migration(attr_name)
    208 from importlib import import_module
    210 module = import_module(_dynamic_imports[attr_name], package=__package__)

File G:\RajArun\os\chroma\chromaenv\Lib\site-packages\pydantic\_migration.py:279, in getattr_migration.<locals>.wrapper(name)
    277     return import_string(DEPRECATED_MOVED_IN_V2[import_path])
    278 if import_path == 'pydantic:BaseSettings':
--> 279     raise PydanticImportError(
    280         '`BaseSettings` has been moved to the `pydantic-settings` package. '
    281         f'See https://docs.pydantic.dev/{VERSION}/migration/#basesettings-has-moved-to-pydantic-settings '
    282         'for more details.'
    283     )
    284 if import_path in REMOVED_IN_V2:
    285     raise PydanticImportError(f'`{import_path}` has been removed in V2.')

PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package. See https://docs.pydantic.dev/2.0.2/migration/#basesettings-has-moved-to-pydantic-settings for more details.

For further information visit https://errors.pydantic.dev/2.0.2/u/import-error

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 11
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Downgrading to an even older version of pydantic seems to do the trick (as far as workarounds go): pip install pydantic==1.9.0

Python 3.9 installed with conda also got this err.

update: downgrade package pydantic from 2.0.2 to 2.0 works fine for me.

We are looking into this, thanks everyone!

FastAPI recently released v0.100.0 where they started using Pydantic v2, which does not work with ChromaDB. Installing fastapi==0.99.1 fixed the issue for me.

A short-term fix could be setting the FastAPI dependency in ChromaDB to fastapi >=0.85.1, <=0.99.1. Settingpydantic >=1.9 , <=1.10.11 might also do the trick.

hey @husy8 this solution doesn’t works for me, and I’m using the same version.

Thank you for the quick fix! Love your product - keep up the good work!

Python3.7 and Python3.10 also meet this import problem. This error should be fixed! I solve this by installing pedantic-settings and modify the first line of config.py file to import pedatic-settings.

Hi, I have the same issue that chromadb is using pydantic 1.10.12 but it clash with elevenlabs which use pydantic 2.30. Beside chromadb I use gradio and langchain. I see that gradio is using fastapi also… How did u solve it?

For those langchain users - chroma is cutting a new release momentarily to fix the pydantic version conflict - https://github.com/chroma-core/chroma/pull/799