pytorch 和 tensorflow 在同一环境中可能遇到的问题
问题背景
主包在实现一个语音助手功能的开发时,其中语音识别使用的模型是基于pytorch模型,在语言类别识别和翻译的模型是基于tensorflow训练的模型,主包傻傻的在原来的conda环境中经过严密对比numpy版本为1.26.4,python版本为3.10符合tensorflow版本2.10的安装要求 直接安装了tensorflow结果出现如下报错
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tensorboardx 2.6.2.2 requires protobuf>=3.20, but you have protobuf 3.19.6 which is incompatible.
可是主包观察到原先环境(安装了pytorch相关依赖)中protobuf版本是
protobuf 6.30.2 pypi_0 pypi
因此说明在安装tensorflow的过程当中,安装具有tensorflow依赖项的其他包会触发安装protobuf 3.X从而导致版本变化,造成冲突
接着主包尝试更新protobuf版本>=3.20,又出现如下报错
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tensorboard 2.10.1 requires protobuf<3.20,>=3.9.2, but you have protobuf 3.20.3 which is incompatible.
tensorflow 2.10.0 requires protobuf<3.20,>=3.9.2, but you have protobuf 3.20.3 which is incompatible.
Successfully installed protobuf-3.20.3
结果说明
以上在同一环境中安装pytorch和tensorflow说明了两种框架对protobuf的版本不一致,有不兼容的api和依赖项要求会造成冲突
问题解决
使用不同框架训练的模型需要创建不同的环境
浙公网安备 33010602011771号