Python &引用;ImportError:没有名为google.protobuf的模块;但是它';它肯定安装好了

Python &引用;ImportError:没有名为google.protobuf的模块;但是它';它肯定安装好了,python,protocol-buffers,python-3.5,Python,Protocol Buffers,Python 3.5,我已经安装了protobuf包,但无法导入它 > pip uninstall protobuf ... uninstalls > pip install protobuf ... installs. confirm that it's installed: pip install protobuf Requirement already satisfied (use --upgrade to upgrade): protobuf in ./.venv/lib/python3.

我已经安装了
protobuf
包,但无法导入它

> pip uninstall protobuf
... uninstalls
> pip install protobuf
... installs. confirm that it's installed:
pip install protobuf
Requirement already satisfied (use --upgrade to upgrade): protobuf in     ./.venv/lib/python3.5/site-packages
Requirement already satisfied (use --upgrade to upgrade): setuptools in ./.venv/lib/python3.5/site-packages (from protobuf)
Requirement already satisfied (use --upgrade to upgrade): six>=1.9 in ./.venv/lib/python3.5/site-packages (from protobuf)
回到
ipython

In [1]: from google.protobuf import descriptor as _descriptor
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-3baca6afb060> in <module>()
----> 1 from google.protobuf import descriptor as _descriptor

ImportError: No module named google.protobuf

In [2]:

我也遇到了同样的问题,并发现了以下建议的解决方法:

1.添加新文件tensorflow/google/init.py:

try:
    import pkg_resources
    pkg_resources.declare_namespace(__name__)
except ImportError:
    import pkgutil
    __path__ = pkgutil.extend_path(__path__, __name__)

    Add namespace_packages to tensorflow/google/protobuf/python/setup.py:

setup(
    name='protobuf',
    namespace_packages=['google'],
    ...
)
  • 重新编译/pip安装。祝你好运
    你是从活跃的venv开始的ipython?我不是。但是,在通过pip在venv中本地安装ipython后,同样的错误也会发生。请阅读本文,希望这会有所帮助。
    try:
        import pkg_resources
        pkg_resources.declare_namespace(__name__)
    except ImportError:
        import pkgutil
        __path__ = pkgutil.extend_path(__path__, __name__)
    
        Add namespace_packages to tensorflow/google/protobuf/python/setup.py:
    
    setup(
        name='protobuf',
        namespace_packages=['google'],
        ...
    )