langchain icon indicating copy to clipboard operation
langchain copied to clipboard

"No module named 'chromadb'" — add chromadb as dependency?

Open slhck opened this issue 1 year ago • 19 comments

Trying to follow the guides:

  • https://langchain.readthedocs.io/en/latest/modules/indexes/getting_started.html
  • https://langchain.readthedocs.io/en/latest/modules/indexes/vectorstore_examples/chroma.html

But when I run:

db = Chroma.from_documents(texts, embeddings)

I get:

ModuleNotFoundError                       Traceback (most recent call last)
File ~/Library/Caches/pypoetry/virtualenvs/docs-bot-z8dlOdVH-py3.10/lib/python3.10/site-packages/langchain/vectorstores/chroma.py:40, in Chroma.__init__(self, collection_name, embedding_function, persist_directory)
     39 try:
---> 40     import chromadb
     41     import chromadb.config

ModuleNotFoundError: No module named 'chromadb'

In my Poetry dependencies, I only had langchain and openai.

I'd suggest adding a line somewhere in the docs that this is an optional dependency and should be installed?

Once I do:

poetry add chromadb

It works.

slhck avatar Mar 02 '23 14:03 slhck

Interestingly I did not hit this exception path:

https://github.com/hwchase17/langchain/blob/4b5e850361bd4b47ac739748232d696deac79eaf/langchain/vectorstores/chroma.py#L32-L46

Using v0.0.98 within a Jupyter notebook.

slhck avatar Mar 02 '23 15:03 slhck

Even though I have installed chromadb using pip install chromadb but error still persists Is their any underlying issue ,version issue or any other ? Can't make it work

from langchain.embeddings.openai import OpenAIEmbeddings from langchain.vectorstores import Chroma embeddings= OpenAIEmbeddings(openai_api_key=os.environ['OPENAI_API_KEY']) docsearch= Chroma.from_documents(texts, embeddings)

error

Traceback (most recent call last): File "/home/ubuntu/.local/lib/python3.10/site-packages/langchain/vectorstores/chroma.py", line 62, in init import chromadb ModuleNotFoundError: No module named 'chromadb'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/ubuntu/textToQuery.py", line 22, in docsearch = Chroma.from_documents(texts, embeddings) File "/home/ubuntu/.local/lib/python3.10/site-packages/langchain/vectorstores/chroma.py", line 265, in from_documents return cls.from_texts( File "/home/ubuntu/.local/lib/python3.10/site-packages/langchain/vectorstores/chroma.py", line 228, in from_texts chroma_collection = cls( File "/home/ubuntu/.local/lib/python3.10/site-packages/langchain/vectorstores/chroma.py", line 65, in init raise ValueError( ValueError: Could not import chromadb python package. Please install it with pip install chromadb

IqraShahid-dev avatar Mar 20 '23 13:03 IqraShahid-dev

Make sure that it's installed in the same site packages directory. You may have used a different version of pip from a different python environment.

slhck avatar Mar 20 '23 13:03 slhck

pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)

I don't think so it's a pip problem. I have noticed that during pip install chromadb , torch process gets killed maybe memory issue.

Capture (2)

with this pip install torch --no-cache-dir

Capture (3)

What's the chromadb package size?

IqraShahid-dev avatar Mar 21 '23 05:03 IqraShahid-dev

This is the size:

~/Library/Caches/pypoetry/virtualenvs/docs-bot-z8dlOdVH-py3.10
➜ du -hs lib/python3.10/site-packages/chromadb/
376K	lib/python3.10/site-packages/chromadb/

~/Library/Caches/pypoetry/virtualenvs/docs-bot-z8dlOdVH-py3.10
➜ du -hs lib/python3.10/site-packages/chromadb-0.3.10.dist-info
 32K	lib/python3.10/site-packages/chromadb-0.3.10.dist-info

For me using the following pyproject.toml was enough, using Poetry:

[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
authors = [""]
readme = "README.md"
packages = [{include = "test"}]

[tool.poetry.dependencies]
python = "^3.10,<3.11"
langchain = "^0.0.98"
openai = "^0.27.0"
chromadb = "^0.3.10"


[tool.poetry.group.dev.dependencies]
flake8 = "^6.0.0"
mypy = "^1.0.1"
isort = "^5.12.0"
jupyter = "^1.0.0"
notebook = "^6.5.2"
black = "^23.1.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

Then run poetry install. I generally prefer to use Poetry over user or system library installations.

(Make sure to update to the most recent version of the packages; the above are a bit outdated.)

slhck avatar Mar 21 '23 09:03 slhck

Thanks, Well my main issue was memory. With combination of larger instance and poetry ,I am able to resolve my problem.

IqraShahid-dev avatar Mar 23 '23 11:03 IqraShahid-dev

Thanks, Well my main issue was memory. With combination of larger instance and poetry ,I am able to resolve my problem.

Can you please help me out with how you took care of the situation. I am also facing the same issue...will be really helpful if you could elaborate the steps

UdayanSL avatar Jun 08 '23 14:06 UdayanSL

Did you restart the terminal after the installation. try that it worked for me.

RatanPrakash avatar Jun 30 '23 07:06 RatanPrakash

Hi everyone, this is how you can fix this error.

berkayaltug avatar Jul 12 '23 19:07 berkayaltug

Did you restart the terminal after the installation? I have tried lot of different combination like install with pip, conda etc but it solved with just restarting kernel

khurramwbox avatar Aug 24 '23 07:08 khurramwbox

After restart it worked for me

vijay-pushparaj avatar Aug 24 '23 11:08 vijay-pushparaj

Close this issue for now.

RatanPrakash avatar Aug 26 '23 10:08 RatanPrakash

I will close this issue once the chromadb dependency is properly documented. I'm not sure if this has been done in the meantime.

slhck avatar Aug 26 '23 10:08 slhck

im getting below error for chroma db

pip install chromadb
Using cached exceptiongroup-1.1.3-py3-none-any.whl (14 kB)
Building wheels for collected packages: chroma-hnswlib
  Building wheel for chroma-hnswlib (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for chroma-hnswlib (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [5 lines of output]
      running bdist_wheel
      running build
      running build_ext
      building 'hnswlib' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for chroma-hnswlib
Failed to build chroma-hnswlib
ERROR: Could not build wheels for chroma-hnswlib, which is required to install pyproject.toml-based projects

akashAD98 avatar Aug 30 '23 16:08 akashAD98

I found this was a version mismatch - langchain expected version 1.5.6. Pinning "chromadb": "1.5.6" in my package.json sorted the issue in my node project, i assume you will need to just align the version in python as well :)

hilarykitz avatar Oct 10 '23 11:10 hilarykitz

In my case, it is because I named a file with chromadb.py. Python tries to import from this file instead of installed package. I solved it after renaming the file. Hope it help people new to python.

wingleungchoi avatar Oct 20 '23 11:10 wingleungchoi

Restart the terminal.It worked for me

Lykos2 avatar Feb 08 '24 07:02 Lykos2

chromadb

refer this link for solution: https://stackoverflow.com/questions/64261546/how-to-solve-error-microsoft-visual-c-14-0-or-greater-is-required-when-inst

harshpatel0204 avatar Apr 08 '24 06:04 harshpatel0204

image

Tho I installed chromadb, still have this issue pls help anyone

ashishnex007 avatar Apr 20 '24 04:04 ashishnex007