即使已安装,也无法在 conda env 中导入 protobuf

Cannot import protobuf in conda env even though it's installed

在 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'

有什么想法吗?

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

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