LangGraph Cloud deployment fails with pymilvus - setuptools pkg_resources module not found

I’m trying to deploy my application on LangGraph Cloud but running into issues with pymilvus library. The deployment keeps failing with this error:

ModuleNotFoundError: No module named 'pkg_resources'

The problem seems to be that pymilvus needs pkg_resources which it imports like this:

from pkg_resources import get_distribution

Looking at the error traceback, I can see it’s failing right in the pymilvus client initialization:

File "/usr/local/lib/python3.11/site-packages/pymilvus/client/__init__.py", line 6, in <module>
    from pkg_resources import DistributionNotFound, get_distribution
ModuleNotFoundError: No module named 'pkg_resources'

From what I can tell in the build logs, the Docker image strips out setuptools and related packages during the build process:

#7 [langgraph-api  3/12] RUN pip uninstall -y pip wheel && \
     rm -rf /usr/local/lib/python*/site-packages/pip* \
            /usr/local/lib/python*/site-packages/wheel* && \
     find /usr/local/bin -name "pip*" -delete

I think setuptools gets removed too which breaks pkg_resources availability.

Since I can’t modify the deployment Docker setup myself, what are my options here? Is there a way to keep setuptools available at runtime or maybe work around this dependency issue with pymilvus? Would really appreciate any suggestions on how to handle this.

i faced this too! make sure to include setuptools in your requirements.txt - it’s easy to overlook. also, check if a newer version of pymilvus is available that might not depend on pkg_resources anymore, could help a lot!

Had this exact headache last month deploying a RAG pipeline with Milvus.

LangGraph Cloud intentionally removes setuptools for security and smaller images, but pymilvus still needs the old pkg_resources pattern.

Two fixes that worked:

Option 1: Add both to requirements.txt:

setuptools>=65.0.0
pymilvus==2.x.x

Option 2: Switch to importlib.metadata if you’re on Python 3.8+. You’ll probably need to patch pymilvus locally or use a fork with the newer import system.

I went with option 1 - less risky. The overhead’s minimal and setuptools stays installed after build cleanup.

Also check your pymilvus version. Anything after 2.3.0 should handle this better, but I’ve seen weird behavior depending on the container’s Python version.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.