Skip to content

[Bug]: Fix the bug that milvus-lite fails with No module named 'pkg_resources' #48422

@AlimuratYusup

Description

@AlimuratYusup

Is there an existing issue for this?

  • I have searched the existing issues

Environment

- Python 3.11
- pymilvus 2.6.x                                                                 
- milvus-lite (installed via pip install pymilvus[milvus_lite])                  
- setuptools 82.0.1                                                              

Current Behavior

1. Error

File ".../milvus_lite/__init__.py", line 15, in <module>
    from pkg_resources import DistributionNotFound, get_distribution             
ModuleNotFoundError: No module named 'pkg_resources'

2. Root Cause

milvus_lite/__init__.py uses from pkg_resources import ..., which is
deprecated and may not be importable in some environments even when setuptools
is installed (known issue with certain conda/venv setups).

3. Workaround (local patch only — not a permanent fix)

Edit milvus_lite/__init__.py (find the path with pip show milvus-lite):

Before (line 15):

from pkg_resources import DistributionNotFound, get_distribution                 

After:

from importlib.metadata import PackageNotFoundError as DistributionNotFound,
version as _imeta_version                                                        
 
def get_distribution(name):                                                      
    class _D:   
        def __init__(self, v): self.version = v
    return _D(_imeta_version(name))                                              

4. Verify

python -c "from pymilvus import MilvusClient; print('OK')"

Note: This workaround only patches the local installation. The proper fix
is to replace pkg_resources with importlib.metadata in the milvus-lite
source, as pkg_resources has been deprecated by
setuptools
.

Expected Behavior

MilvusClient connects successfully without ModuleNotFoundError.

Steps To Reproduce

pip install "pymilvus[milvus_lite]"
python -c "from pymilvus import MilvusClient; MilvusClient(uri='test.db')"       

Milvus Log

No response

Anything else?

No response

Metadata

Metadata

Assignees

Labels

kind/bugIssues or changes related a bugneeds-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions