GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Python] A file with this name is already in the pool. · Issue #3002 · protocolbuffers/protobuf

[Python] A file with this name is already in the pool. #3002

New issue
Copy link
New issue
Copy link
Closed
Closed
[Python] A file with this name is already in the pool.#3002
Copy link

Description

@rossengeorgiev
rossengeorgiev
opened on Apr 22, 2017
Issue body actions

This problem arises from the linux binary wheels for protobuf==3.2.0. Using the pure python implementation works fine.

In my case I proto file that collides with name of proto file from another package. Importing both python packages is not possible as I get this error.

Steps to replicate

Directory tree:

./module1
./module1/messages.proto
./module1/messages_pb2.py
./module1/__init__.py
./module2
./module2/messages.proto
./module2/messages_pb2.py
./module2/__init__.py

./module1/messages.proto

syntax = "proto2";
package module1;

./module2/messages.proto

syntax = "proto2";
package module2;

Trying to import:

python -c "import module1.messages_pb2, module2.messages_pb2"
------
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "module2/messages_pb2.py", line 22, in <module>
    serialized_pb=_b('\n\x0emessages.proto\x12\x07module2')
  File "/home/vagrant/env/local/lib/python2.7/site-packages/google/protobuf/descriptor.py", line 824, in __new__
    return _message.default_pool.AddSerializedFile(serialized_pb)
TypeError: Couldn't build proto file into descriptor pool!
Invalid proto descriptor for file "messages.proto":
  messages.proto: A file with this name is already in the pool.

Activity

  1. feifangit commented on Jun 21, 2017

    @feifangit
    feifangit
    on Jun 21, 2017
    More actions

    I ran into this issue too. I have to make the .proto files in unique file names.

  2. ndwhelan commented on Jul 10, 2017

    @ndwhelan
    ndwhelan
    on Jul 10, 2017
    More actions

    Ran in to this issue. If anyone finds this, I resolved it by running pip uninstall protobuf and then pip install --no-binary protobuf protobuf. That made sure that only the source was installed, and, as mentioned above, for some reason, things work fine in the pure python version.

    Reacted by 0xfffffffffffffffffffe, Rossen, Corentin Jemine, Jim MacArthur, Ferdi Schmidt, Fujia Luo, D., ZHANG Qianhao (Jason), zlh, Sameh Methnani and 24 more
    Reacted by justgos, Sameh Methnani, Abdul Aziz Muslim Al Qudsy and kenmaro
    Reacted by ivonatau, Sameh Methnani, Abdul Aziz Muslim Al Qudsy, Pranay Sawant, bkioshn, Makariy, Hommus and Julia Okuniewska
    Reacted by Abdul Aziz Muslim Al Qudsy and Chengzheng Li
  3. trianta2 commented on Aug 28, 2017

    @trianta2
    trianta2
    on Aug 28, 2017
    More actions

    I found that doing

    export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION='python'
    

    before running my Python code resolved the issue. I got the flag from the bottom of https://developers.google.com/protocol-buffers/docs/reference/python-generated

    Reacted by Stian Lind Petlund, pyang30, Simon Pickles, Caleb Madrigal, Ferdi Schmidt, Cindy, Yue Chen, David Thor, kg6kvq, Foster Lockwood and 35 more
    Reacted by Anand.M.L
    Reacted by Muzamil Hussain Syed
  4. xfxyjwf commented on Aug 28, 2017

    @xfxyjwf
    xfxyjwf
    on Aug 28, 2017
    Contributor
    More actions

    The error (file already in pool) indicates an actual problem you need to fix on the .proto files. A simple solution is to put one of the .proto file in a subdirectory.

    Right now you can hide the problem by switching to the pure python implementation (which doesn't check conflicts), but that won't really solve the issue. You are going to run into the same problem if you are using a different language, or if we fix the pure python implementation to check conflict as well.

  5. rossengeorgiev commented on Aug 29, 2017

    @rossengeorgiev
    rossengeorgiev
    on Aug 29, 2017
    Author
    More actions

    @xfxyjwf I think you are confused. The original issue cannot be fixed by doing anything the protos, except renaming the duplicate message.

    The pure python implementation uses the directory for namespacing, and that works. Just as described in the documentation https://developers.google.com/protocol-buffers/docs/proto#packages

    The problem is that the C++ implementation doesn't do that, nor does it respect the package directive. This issue is not noted in the documentation at all. In fact, the documentation advises on using package in protos (see my example at the top), but that does not work in C++ implementation. So, clearly a bug.

    Reacted by asaff1, ggokm, Artem Khramov, junpeiz and Chen Xiaoyuan
  6. xfxyjwf commented on Aug 29, 2017

    @xfxyjwf
    xfxyjwf
    on Aug 29, 2017
    Contributor
    More actions

    @rossengeorgiev Can you regenerate the *_pb2.py files by invoking:

    $ protoc --python_out=. module1/messages.proto module2/messages.proto

    ? That should solve the issue you are having. Note that the python import path must match the file path you passed to protoc.

  7. rossengeorgiev commented on Sep 23, 2017

    @rossengeorgiev
    rossengeorgiev
    on Sep 23, 2017
    Author
    More actions

    I managed to figure out what caused the original issue. The clue was in the error. The descriptor name is derived from the relative path.

    serialized_pb=_b('\n\x0emessages.proto\x12\x07module2')

    That means I compiled the code by going into each directory and running protoc --python_out=. messages.proto. If I run it as you suggest, or even as protoc --python_out=. module1/messages.proto; protoc --python_out=. module2/messages.proto; it will work regardless. The descriptor name will always be different as it is derived from the relative path.

    serialized_pb=_b('\n\x16module1/messages.proto\x12\x07module1')

    In addition if we have duplicate messages like so:

    ./module1/messages.proto

    syntax = "proto2";
    message mymessage { }

    ./module2/messages.proto

    syntax = "proto2";
    message mymessage { }  

    If we invoke protoc like so, we get an error and nothing gets compiled.

    protoc --python_out=. module2/messages.proto module1/messages.proto
    module1/messages.proto:3:9: "mymessage" is already defined in file "module2/messages.proto".

    Alternatively, we could do:

     protoc --python_out=. module2/messages.proto
     protoc --python_out=. module1/messages.proto

    No error and compiles fine. However we get an error when we try to import in the C++ protobuf package, and no error in the pure one.

    $ python -c "import module1.messages_pb2, module2.messages_pb2"
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "module2/messages_pb2.py", line 22, in <module>
        serialized_pb=_b('\n\x16module2/messages.proto\"\x0b\n\tmymessage')
      File "/home/vagrant/env/local/lib/python2.7/site-packages/google/protobuf/descriptor.py", line 824, in __new__
        return _message.default_pool.AddSerializedFile(serialized_pb)
    TypeError: Couldn't build proto file into descriptor pool!
    Invalid proto descriptor for file "module2/messages.proto":
      mymessage: "mymessage" is already defined in file "module1/messages.proto".

    At this point we have two options. Use pure python protobuf package, or set package directive in our proto files. I think this covers everything. Thanks @xfxyjwf

    Reacted by trianta2 and Xiangji Zeng
  8. BSBandme
    added
    to close
    on Dec 11, 2017
  9. jtattermusch
    closed this as completedon Dec 11, 2017
  10. kr-ish commented on May 31, 2019

    @kr-ish
    kr-ish
    on May 31, 2019
    More actions

    @rossengeorgiev could you clarify what you mean by "set package directive in our proto files"? I'm having this same issue and I'm trying to solve it without using the pure python protobuf package

  11. kr-ish commented on May 31, 2019

    @kr-ish
    kr-ish
    on May 31, 2019
    More actions

    I was working with tensorflow protos that I was trying to compile and use outside of tensorflow- there were a couple of issues but the main issue seems to have been not making sure I had uninstalled tensorflow and from my python environment entirely because one of my services was using a tf service which was causing the conflict- after I refactored that to not use tf and got rid of tf for good measure, I stopped seeing this issue

  12. felipesanches
    added 3 commits that reference this issue on Feb 18, 2022

    updated and simplified the textproto definition

    b2af58c

    updated and simplified the textproto definition

    14ad3af

    updated and simplified the textproto definition

    6ce744c
  13. brary commented on Jan 6, 2023

    @brary
    brary
    on Jan 6, 2023
    More actions

    Hi, I was facing this issue on adding a dependency and tried using --no-binary=protobuf. But post adding it, my existing pipeline has started failing. I am getting this exception on same protobuf version which I was using earlier(3.20.3)

    Traceback (most recent call last):
     File "/tmp/tmpmgkm82oc/installed_wheels/48d30b6cca1d176ff8918486633b04f54a436a15435696d2baba61d4595d690c/protobuf-3.20.3-py2.py3-none-any.whl/google/protobuf/internal/python_message.py", line 1128, in MergeFromString
      if self._InternalParse(serialized, 0, length) != length:
     File "/tmp/tmpmgkm82oc/installed_wheels/48d30b6cca1d176ff8918486633b04f54a436a15435696d2baba61d4595d690c/protobuf-3.20.3-py2.py3-none-any.whl/google/protobuf/internal/python_message.py", line 1164, in InternalParse
      (tag_bytes, new_pos) = local_ReadTag(buffer, pos)
     File "/tmp/tmpmgkm82oc/installed_wheels/48d30b6cca1d176ff8918486633b04f54a436a15435696d2baba61d4595d690c/protobuf-3.20.3-py2.py3-none-any.whl/google/protobuf/internal/decoder.py", line 174, in ReadTag
      while buffer[pos] & 0x80:
    TypeError: unsupported operand type(s) for &: 'bytes' and 'int' 
    
  14. dkbarn commented on Jan 4, 2024

    @dkbarn
    dkbarn
    on Jan 4, 2024
    More actions

    Years later and it's still unclear from this conversation what the proper solution is. Avoiding use of the binary wheels by forcing pip to install the pure python implementation is a workaround. What is the proper fix?

    @rossengeorgiev said:

    At this point we have two options. Use pure python protobuf package, or set package directive in our proto files. I think this covers everything.

    Setting the package directive does not fix the issue. I currently have this setup:

    ./foo/messages.proto

    syntax = "proto2";
    package foo;

    ./bar/messages.proto

    syntax = "proto2";
    package bar;

    And I still get this error:

    TypeError: Couldn't build proto file into descriptor pool!
    Invalid proto descriptor for file "messages.proto":
      messages.proto: A file with this name is already in the pool.
    
    Reacted by Tobías Lifschitz
  15. tlifschitz commented on Apr 9, 2024

    @tlifschitz
    tlifschitz
    on Apr 9, 2024
    More actions

    Agreed @dkbarn, still having the same issue, this is definitely not solved. The pure python implementation workaround it is obviously much slower at runtime. @jtattermusch @BSBandme

  16. Wavator commented on Jun 28, 2025

    @Wavator
    Wavator
    on Jun 28, 2025
    More actions

    I solved the problem by using protoc --descriptor_set_out= to rebuild a new pool but not using the default pool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.