Docker构建运行时遇TypeError:opentelemetry proto文件重复
构建Docker镜像时的Protobuf重复文件错误
错误信息
TypeError: Couldn't build proto file into descriptor pool: duplicate file name opentelemetry/proto/common/v1/common.proto
requirements.txt 内容
numpy~=1.26.4 oauthlib==3.2.2 openai==1.12.0 pandas==1.5.3 pandas-stubs==1.2.0.39 requests==2.32.0 requests-oauthlib==1.3.0 uvicorn==0.23.0 anyio==3.5.0 tenacity==8.2.3 plotly==5.13.0 scipy scikit-learn pydantic~=1.10.12 tiktoken==0.5.2 regex PyPDF2==3.0.1 docx2txt==0.8 python-docx==0.8.11 python-multipart==0.0.9 pybase64==1.2.3 slowapi==0.1.8 nltk==3.8.1 Jinja2==3.1.4 pytailwindcss==0.1.4 pdf2image==1.16.3 pypdf==3.17.0 langchain==0.1.14 langchain-community==0.0.30 langchain-openai==0.0.4 typing_extensions==4.8.0 unstructured==0.6.11 python-pptx==0.6.23 APScheduler==3.10.4 python-socketio==5.8.0 websockets==11.0.3 google-cloud-aiplatform==1.44.0 pandasai==2.1 bs4==0.0.1 matplotlib==3.7.2 matplotlib-inline==0.1.6 PyMySQL==1.1.1 SQLAlchemy==1.4.49 pypandoc-binary==1.12 qdrant-client==1.9.1 chromadb==0.5.0 protobuf==4.25.3
报错调用栈
from pandasai.ee.vectorstores.pinecone import Pinecone June 07, 2024 at 13:08 (UTC+5:30) File "/venv/lib/python3.12/site-packages/pandasai/ee/vectorstores/__init__.py", line 5, in <module> June 07, 2024 at 13:08 (UTC+5:30) from .chroma import ChromaDB June 07, 2024 at 13:08 (UTC+5:30) File "/venv/lib/python3.12/site-packages/pandasai/ee/vectorstores/chroma.py", line 5, in <module> June 07, 2024 at 13:08 (UTC+5:30) import chromadb June 07, 2024 at 13:08 (UTC+5:30) File "/venv/lib/python3.12/site-packages/chromadb/__init__.py", line 5, in <module> June 07, 2024 at 13:08 (UTC+5:30) from chromadb.auth.token_authn import TokenTransportHeader usw2-dev-taskgpt-core-cn June 07, 2024 at 13:08 (UTC+5:30) File "/venv/lib/python3.12/site-packages/chromadb/auth/token_authn/__init__.py", line 20, in <module> June 07, 2024 at 13:08 (UTC+5:30) from chromadb.telemetry.opentelemetry import ( June 07, 2024 at 13:08 (UTC+5:30) File "/venv/lib/python3.12/site-packages/chromadb/telemetry/opentelemetry/__init__.py", line 12, in <module> June 07, 2024 at 13:08 (UTC+5:30) from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter June 07, 2024 at 13:08 (UTC+5:30) File "/venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py", line 24, in <module> June 07, 2024 at 13:08 (UTC+5:30) from opentelemetry.exporter.otlp.proto.common.trace_encoder import ( June 07, 2024 at 13:08 (UTC+5:30) File "/venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/common/trace_encoder.py", line 16, in <module> June 07, 2024 at 13:08 (UTC+5:30) from opentelemetry.exporter.otlp.proto.common._internal.trace_encoder import ( June 07, 2024 at 13:08 (UTC+5:30) File "/venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py", line 31, in <module> June 07, 2024 at 13:08 (UTC+5:30) from opentelemetry.proto.common.v1.common_pb2 import ( June 07, 2024 at 13:08 (UTC+5:30) File "/venv/lib/python3.12/site-packages/opentelemetry/proto/common/v1/common_pb2.py", line 17, in <module>
解决方案
- 排查依赖冲突:问题源于多个依赖(如chromadb、pandasai)重复引入了OpenTelemetry的proto文件,或protobuf版本与依赖不兼容。
- 固定兼容版本:尝试将protobuf降级到4.24.x版本,同时显式指定opentelemetry-proto版本,在requirements.txt中添加:
opentelemetry-proto==1.24.0 protobuf==4.24.4 - 清理Docker缓存:执行
docker builder prune清理旧构建缓存,避免残留的冲突依赖干扰。 - 移除重复包:requirements中同时存在PyPDF2和pypdf,两者功能重叠会引发依赖冲突,建议保留其中一个(优先保留pypdf==3.17.0)。
- 强制依赖统一:在Docker构建阶段使用
pip install --force-reinstall -r requirements.txt,强制重新安装所有依赖确保版本一致。
内容的提问来源于stack exchange,提问作者Abhi Kanimilli
相关产品推荐
相关产品推荐

