获取模块“google.protobuf.descriptor_pool”在我的python脚本中没有属性“默认”

Mob*_*een 9 python pip protocol-buffers python-3.x google-bigquery

我是 python 新手,正在使用其他人编写的 python 脚本。我在另一台电脑上运行得很好。只是要安装软件包包括轿跑车pip3google-cloudgoogle-cloud-bigquerypandas

现在,当我在不同的 PC 上安装相同的软件包时,我无法运行该脚本。首先显示以下错误:

module = 'google.protobuf.descriptor_pb2' TypeError: expected bytes, Descriptor found
Run Code Online (Sandbox Code Playgroud)

但是,当在清除/重新安装/更新的软件包中并添加 protobuf3 和 protobuf-py3 软件包时,错误已更新为以下消息:

from google.cloud import bigquery
  File "/home/mobeen/.local/lib/python3.6/site-packages/google/cloud/bigquery/__init__.py", line 35, in <module>
    from google.cloud.bigquery.client import Client
  File "/home/mobeen/.local/lib/python3.6/site-packages/google/cloud/bigquery/client.py", line 50, in <module>
    import google.cloud._helpers
  File "/home/mobeen/.local/lib/python3.6/site-packages/google/cloud/_helpers.py", line 33, in <module>
    from google.protobuf import duration_pb2
  File "/home/mobeen/.local/lib/python3.6/site-packages/google/protobuf/duration_pb2.py", line 8, in <module>
    from google.protobuf import symbol_database as _symbol_database
  File "/home/mobeen/.local/lib/python3.6/site-packages/google/protobuf/symbol_database.py", line 193, in <module>
    _DEFAULT = SymbolDatabase(pool=descriptor_pool.Default())
AttributeError: module 'google.protobuf.descriptor_pool' has no attribute 'Default'
Run Code Online (Sandbox Code Playgroud)

. 在这方面的任何帮助或线索将不胜感激

abd*_*dev 11

我通过卸载protobuf解决了这个问题:

pip3 uninstall protobuf

pip3 uninstall python3-protobuf

注意:您应该重复此命令,直到收到一条消息,指出没有名为 protobuf 的包。

之后执行:

pip3 install protobuf

只安装 protobuf ,不要安装 python3-protobuf

希望这个解决方案可以帮助你。


小智 0

你也尝试过这个吗?

“我解决了安装后导入tensorflow时显示属性错误:‘模块’对象没有属性‘默认’的问题,方法是删除冗余的protobuf文件。

原因是某些 google/protobuf/descriptor_pool.py 没有定义“默认”。这通常发生在旧版本的 protobuf 上,所以我升级成功,但问题没有解决。通过检查 PATH 并搜索“google/protobuf”,我发现它存在于“/usr/local/lib/python2.7/dist-packages/google/protobuf/”和“/usr/lib/python2.7”中/dist-packages/google/protobuf/”。前一个具有“默认”属性,但第二个没有。我尝试导入 google.protobuf 和 google.protobuf。文件,它显示'/usr/lib/python2.7/dist-packages/google/protobuf/init.pyc'。我删除了 /usr/lib/python2.7/dist-packages/google/protobuf 并尝试导入tensorflow,成功了。”