当我想使用命令安装 grpcio-tools 时:
python3 -m pip install grpcio-tools
[![在此处输入图像描述][1]][1]
另一方面,当我想运行 pip3 install mysql-connector-python 来安装 mysql-connector-python 时: [![在此处输入图像描述][2]][2]
对于这种不兼容我该怎么办?
whereis protoc
protoc: /usr/local/bin/protoc
pip show protobuf
Name: protobuf
Version: 3.20.1
Summary: Protocol Buffers
Home-page: https://developers.google.com/protocol-buffers/
Author: None
Author-email: None
License: BSD-3-Clause
Location: /home/lfathi/.local/lib/python3.8/site-packages
Requires:
Required-by: mysql-connector-python, grpcio-tools
protoc --version
libprotoc 3.2.0
这会导致 grpc 运行出现问题 [1]:https://i.sstatic.net/NZ15N.png [2]:https://i.sstatic.net/LXpM1.png
mysql-connector-python
确实需要 protobuf
:
python3 -m venv venv
source venv/bin/activate
python3 -m pip install mysql-connector-python==8.0.31
python3 -m pip freeze
产量:
mysql-connector-python==8.0.31
protobuf==3.20.1
或者
/path/to/venv/lib/python3.9/site-packages/mysql_connector_python-8.0.31.dist-info/METADATA
Metadata-Version: 2.1
Name: mysql-connector-python
Version: 8.0.31
Summary: MySQL driver written in Python
Home-page: http://dev.mysql.com/doc/connector-python/en/index.html
Author: Oracle and/or its affiliates
Author-email:
License: GNU GPLv2 (with FOSS License Exception)
Download-URL: http://dev.mysql.com/downloads/connector/python/
Keywords: mysql db
Platform: UNKNOWN
[edited]
Requires-Dist: protobuf (<=3.20.1,>=3.11.0)
[edited]
Google 在 3.20.1 和 4.20.1 之间对 Protocol Buffers 的 Python 实现进行了重大更改。
您需要找到使用grpcio-tools
的
<=3.20.1
版本。奇怪的是,
1.46.0
应该可以工作(2022年5月3日),因为它在protobuf
3.20.1
(2022年4月21日)和
3.20.2
(2022年9月13日)之间,但是,这也失败了。请尝试:
python3 -m pip install mysql-connector-python==8.0.31
python3 -m pip install grpcio-tools==1.44.0
python3 -m pip freeze
产量:
grpcio==1.51.1
grpcio-tools==1.44.0
mysql-connector-python==8.0.31
protobuf==3.20.3
当可以复制粘贴文本时,请不要在堆栈溢出问题中使用屏幕截图。使用图像会抑制其他人复制和粘贴内容来帮助回答问题的能力,并且不能保证图像会与问题一样持久。
RUN pip install -r requirements.txt
处出错,如下所示:
ERROR: Cannot install grpcio-status==1.53.0, mysql-connector-python==8.0.32 and protobuf==4.22.1
because these package versions have conflicting dependencies
grpcio-status 1.53.0 depends on protobuf>=4.21.6
mysql-connector-python 8.0.32 depends on protobuf<=3.20.3 and >=3.11.0
To fix this you could try to:
1. loosen the range of package versions you have specified
2. remove package versions to allow pip attempt to solve the dependency conflict
删除软件包版本(如建议的修复 2 中所示)解决了我的问题。
requirements.txt
(与包版本的依赖关系):
grpcio-status==1.53.0
mysql-connector-python==8.0.32
protobuf==4.22.1
grpcio-status
mysql-connector-python
protobuf
或者,按如下方式一起安装软件包。 Pip 将尝试解决冲突:
pip install mysql-connector-python grpcio-tools protobuf