【问题标题】:Cannot import protobuf in conda env even though it's installed即使已安装,也无法在 conda env 中导入 protobuf
【发布时间】:2021-12-13 22:35:21
【问题描述】:

在 Ubuntu 20.04 上,我无法导入 protobuf

(r-torch) brucezepplin@brucezepplin-HP-ProBook-440-G7:~$ conda list | grep protobuf
libprotobuf               3.17.2               h4ff587b_1  
protobuf                  3.17.2           py39h295c915_0  
(r-torch) brucezepplin@brucezepplin-HP-ProBook-440-G7:~$ python
Python 3.9.7 (default, Sep 16 2021, 13:09:58) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import protobuf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'protobuf'

有什么想法吗?

【问题讨论】:

  • 在我看来导入是 import google.protobuffrom google.protobuf import ... 等。
  • 这行得通 - 请作为答案,以便我接受。

标签: python protocol-buffers conda


【解决方案1】:

protobuf 的 python 包有一个使用google 作为根前缀的包结构:

import google.protobuf
from google.protobuf import <pkg-name> 

【讨论】:

    猜你喜欢
    • 2018-07-22
    • 2016-11-26
    • 2018-07-21
    • 1970-01-01
    • 2019-12-27
    • 2012-10-24
    • 2019-03-12
    • 1970-01-01
    • 2018-04-15
    相关资源
    最近更新 更多