【问题标题】:protofile.proto: A file with this name is already in the poolprotofile.proto:该名称的文件已经在池中
【发布时间】:2018-06-13 14:24:15
【问题描述】:

具有以下结构:

- project1
  - project1.py
  - protofile_pb2.py
  - protofile_pb2_grpc.py
- project2
  - project2.py
  - protofile_pb2.py
  - protofile_pb2_grpc.py

project1.py:

import protofile_pb2.py
...

project2.py:

import protofile_pb2
import project1
...

运行 project2.py 时,我收到此错误:

TypeError: Couldn't build proto file into descriptor pool!
Invalid proto descriptor for file "protofile.proto":
protofile.proto: A file with this name is already in the pool.

【问题讨论】:

    标签: python protocol-buffers grpc file-descriptor


    【解决方案1】:

    您正在使用生成的 protofile.proto 的不同版本。确保重新生成 protobuf 文件,它应该可以正常工作。

    【讨论】:

      【解决方案2】:

      根据this comment,它对我有用:

      pip uninstall protobuf
      pip install --no-binary protobuf protobuf
      

      【讨论】:

        【解决方案3】:

        我在 Python 中部署谷歌云函数时遇到了类似的问题。我的云功能在我的模块中使用了不同版本的 .proto 文件(这又是一个我想使用 requirements.txt 安装的私有模块)。解决方案是使用纯python实现而不是使用protobuf的二进制实现。要在云函数或云构建中解决此问题,您可以设置云函数 env 变量以使用协议缓冲区的 python 实现。

        在您的 gcloud 云功能部署命令中使用以下选项:

        <start of command> --set-env-vars=PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION='python' <your rest of the command>
        

        或者如果您在任何其他环境/操作系统中,只需执行此操作

        export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION='python' 
        

        这解决了我的问题。

        【讨论】:

        • 谢谢!使用sentencepiece_model_pb2 时,您的解决方法似乎也使事情变得更快
        猜你喜欢
        • 1970-01-01
        • 2012-03-02
        • 2014-05-01
        • 1970-01-01
        • 2014-05-18
        • 2023-04-06
        • 1970-01-01
        • 1970-01-01
        • 2015-07-22
        相关资源
        最近更新 更多