I was unable to import usearch in Python after installing it using pip install usearch.
When I tried to run the example code given in the README, the following error gets thrown:
Traceback (most recent call last):
line 2, in <module> from usearch.index import Index
File "C:\Users\omkar\miniconda3\envs\memdnn\Lib\site-packages\usearch\__init__.py", line 13, in <module>
sqlite = importlib.util.find_spec("usearch.compiled").origin
^^^^^^^^^^^^^^
AttributeError: module 'importlib' has no attribute 'util'
I am using a conda environment created using miniconda. I tried various Python versions (3.9 - 3.12), the error existed in all of them.
The Fix:
I was able to fix the error by manually adding import importlib.util to the __init__.py file of usearch package as follows:
import importlib
import importlib.util
from usearch.compiled import (
VERSION_MAJOR,
VERSION_MINOR,
VERSION_PATCH,
)
__version__ = f"{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}"
# The same binary file (.so, .dll, or .dylib) that contains the pre-compiled
# USearch code also contains the SQLite3 binding
sqlite = importlib.util.find_spec("usearch.compiled").origin
Steps to reproduce
Create a conda environment using miniconda
conda create -n temp python=3.10
Install usearch
pip install usearch
Test on the example code given
import numpy as np
from usearch.index import Index
* Importlib attribute error gets thrown for the line `from usearch.index import Index`
### Expected behavior
usearch package gets imported correctly without the attribute error
### USearch version
v2.9.1
### Operating System
Windows 11 Home
### Hardware architecture
x86
### Which interface are you using?
Python bindings
### Contact Details
omkar.ranadive@u.northwestern.edu
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Describe the bug
I was unable to import usearch in Python after installing it using
pip install usearch
.When I tried to run the example code given in the README, the following error gets thrown:
I am using a conda environment created using miniconda. I tried various Python versions (3.9 - 3.12), the error existed in all of them.
The Fix: I was able to fix the error by manually adding
import importlib.util
to the__init__.py
file of usearch package as follows:Steps to reproduce
index = Index(ndim=3)
vector = np.array([0.2, 0.6, 0.4]) index.add(42, vector)
matches = index.search(vector, 10)
assert matches[0].key == 42 assert matches[0].distance <= 0.001 assert np.allclose(index[42], vector)