Skip to content

Commit

Permalink
[BUG]: Python client sqlite issue (#1211)
Browse files Browse the repository at this point in the history
Refs: #1206

## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
	 - Conditional import of sqlite for python client

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python

Additional test in older disto (debian buster) was run:

```
pip install chromadb-client
root@c26a0fadfcdc:~# python
Python 3.10.12 (main, Jun 13 2023, 12:02:28) [GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> print(sqlite3.sqlite_version_info)
(3, 27, 2)
>>> import chromadb
>>>
```

## Documentation Changes
N/A
  • Loading branch information
tazarov authored Oct 6, 2023
1 parent e3a60a9 commit e357ef3
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions chromadb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Dict
import logging
import sqlite3
import chromadb.config
from chromadb.config import Settings, System
from chromadb.api import API
Expand Down Expand Up @@ -54,22 +53,31 @@
except ImportError:
IN_COLAB = False

if sqlite3.sqlite_version_info < (3, 35, 0):
if IN_COLAB:
# In Colab, hotswap to pysqlite-binary if it's too old
import subprocess
import sys

subprocess.check_call(
[sys.executable, "-m", "pip", "install", "pysqlite3-binary"]
)
__import__("pysqlite3")
sys.modules["sqlite3"] = sys.modules.pop("pysqlite3")
else:
raise RuntimeError(
"\033[91mYour system has an unsupported version of sqlite3. Chroma requires sqlite3 >= 3.35.0.\033[0m\n"
"\033[94mPlease visit https://docs.trychroma.com/troubleshooting#sqlite to learn how to upgrade.\033[0m"
)
is_client = False
try:
from chromadb.is_thin_client import is_thin_client # type: ignore
is_client = is_thin_client
except ImportError:
is_client = False

if not is_client:
import sqlite3
if sqlite3.sqlite_version_info < (3, 35, 0):
if IN_COLAB:
# In Colab, hotswap to pysqlite-binary if it's too old
import subprocess
import sys

subprocess.check_call(
[sys.executable, "-m", "pip", "install", "pysqlite3-binary"]
)
__import__("pysqlite3")
sys.modules["sqlite3"] = sys.modules.pop("pysqlite3")
else:
raise RuntimeError(
"\033[91mYour system has an unsupported version of sqlite3. Chroma requires sqlite3 >= 3.35.0.\033[0m\n"
"\033[94mPlease visit https://docs.trychroma.com/troubleshooting#sqlite to learn how to upgrade.\033[0m"
)


def configure(**kwargs) -> None: # type: ignore
Expand Down

0 comments on commit e357ef3

Please sign in to comment.