Python 没有名为 google.protobuf 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31308812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No module named google.protobuf
提问by lecorbu
I am trying to run Google's deep dream. For some odd reason I keep getting
我正在努力实现 Google 的深切梦想。出于某种奇怪的原因,我不断收到
ImportError: No module named google.protobuf
导入错误:没有名为 google.protobuf 的模块
after trying to import protobuf. I have installed protobuf using sudo install protobuf
. I am running python 2.7 OSX Yosemite 10.10.3.
在尝试导入 protobuf 之后。我已经使用sudo install protobuf
. 我正在运行 python 2.7 OSX Yosemite 10.10.3。
I think it may be a deployment location issue but i cant find anything on the web about it. Currently deploying to /usr/local/lib/python2.7/site-packages.
我认为这可能是部署位置问题,但我在网上找不到任何关于它的信息。当前部署到 /usr/local/lib/python2.7/site-packages。
回答by Oren Haliva
According to your comments, you have multiply versions of python what could happend is that you install the package with pip of anthor python
根据你的评论,你有多个版本的 python 可能发生的是你用 anthor python pip 安装包
pip is actually link to script that donwload and install your package.
pip 实际上是指向下载和安装包的脚本的链接。
two possible solutions:
两种可能的解决方案:
- go to $(PYTHONPATH)/Scripts and run pip from that folder that way you insure you use the correct pip
- create alias to pip which points to $(PYTHONPATH)/Scripts/pip and then run pip install
- 转到 $(PYTHONPATH)/Scripts 并从该文件夹运行 pip 以确保您使用正确的 pip
- 创建指向 $(PYTHONPATH)/Scripts/pip 的 pip 的别名,然后运行 pip install
how will you know it worked? Simple if the new pip is used the package will be install successfully, otherwise the package is already installed
你怎么知道它有效?简单如果使用新的 pip 包将安装成功,否则包已经安装
回答by iSean
In my case I
就我而言,我
downloaded the source code, compiled and installed:
$ ./configure $ make $ make check $ sudo make install`
for python I located its folder(python) under source code, and ran commands:
$ python setup.py build $ python setup.py install'
下载源代码,编译安装:
$ ./configure $ make $ make check $ sudo make install`
对于python,我在源代码下找到了它的文件夹(python),并运行了命令:
$ python setup.py build $ python setup.py install'
Not sure if this could help you..
不知道这是否可以帮助你..
回答by Martin Thoma
I got the same error message when I tried to use Tensor Flow. The solution was simply to uninstallTensor Flow and protobuf:
当我尝试使用 Tensor Flow 时,我收到了同样的错误消息。解决方案只是卸载Tensor Flow 和 protobuf:
$ sudo pip uninstall protobuf
$ sudo pip uninstall tensorflow
And reinstall it again: pip installation of Tensorflow. Currently, this is:
并再次重新安装:Tensorflow 的 pip 安装。目前,这是:
# Ubuntu/Linux 64-bit, CPU only:
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled:
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl
# Mac OS X, CPU only:
$ sudo easy_install --upgrade six
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0rc0-py2-none-any.whl
回答by Panfeng Li
There is another possibility, if you are running a python 2.7.11 or other similar versions,
还有另一种可能性,如果您运行的是 python 2.7.11 或其他类似版本,
sudo pip install protobuf
is ok.
没问题。
But if you are in a anaconda environment, you should use
但是如果你在anaconda环境中,你应该使用
conda install protobuf
回答by neouyghur
I installed the protobuf with this command:
我使用以下命令安装了 protobuf:
conda install -c anaconda protobuf=2.6.1
(you should check the version of protobuf)
(你应该检查protobuf的版本)
回答by Dan Nissenbaum
Locating the google
directory in the site-packages
directory (for the proper latter directory, of course) and manually creating an (empty) __init__.py
resolved this issue for me.
在google
目录中定位site-packages
目录(当然是正确的后一个目录)并手动创建(空)__init__.py
为我解决了这个问题。
(Note that within this directory is the protobuf
directory but my installation of Python 2.7 did not accept the new-style packages so the __init__.py
was required, even if empty, to identify the folder as a package folder.)
(请注意,在此目录中是protobuf
目录,但我安装的 Python 2.7 不接受新样式的包,因此__init__.py
即使为空,也需要将文件夹标识为包文件夹。)
...In case this helps anyone in the future.
...以防这对将来的任何人有帮助。
回答by YellowStar5
In my case, MacOS has the permission control.
sudo -H pip3 install protobuf
就我而言,MacOS 具有权限控制。
sudo -H pip3 install protobuf
回答by blpasd
I had this problem to when I had a google.py file in my project files.
It is quite easy to reproduce.
main.py: import tensorflow as tf
google.py: print("Protobuf error due to google.py")
当我的项目文件中有一个 google.py 文件时,我遇到了这个问题。
很容易重现。
main.py: import tensorflow as tf
google.py:print("Protobuf error due to google.py")
Not sure if this is a bug and where to report it.
不确定这是否是一个错误以及在哪里报告它。
回答by leon wu
when I command pip install protobuf, I get the error:
当我命令pip install protobuf 时,出现错误:
Cannot uninstall 'six'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
无法卸载“六”。这是一个 distutils 安装的项目,因此我们无法准确确定哪些文件属于它,这只会导致部分卸载。
If you have the same problem as me, you should do the following commands.
如果你和我有同样的问题,你应该执行以下命令。
pip install --ignore-installed six
sudo pip install protobuf
pip install --ignore-installed six
sudo pip install protobuf