简体   繁体   English

无法导入Google Protobuf Python模块

[英]Unable to Import Google Protobuf Python Module

I am working with an Ubuntu 14.04 machine, trying to import the google.protobuf module into python 2.7. 我正在使用Ubuntu 14.04机器,试图将google.protobuf模块导入python 2.7。

I have tried 我试过了

apt-get python-protobuf 

and

pip install protobuf 

without success. 没有成功。

Inside python, I get an error saying: 在python里面,我收到一个错误说:

"ImportError: No module named google.protobuf" “ImportError:没有名为google.protobuf的模块”

Edit 1: 编辑1:

Sorry and thank you to everyone who commented. 对不起,谢谢所有评论的人。 I'm still new to Ubuntu and StackOverflow. 我还是Ubuntu和StackOverflow的新手。

Specifically, I type in to command line 具体来说,我输入命令行

python
import google.protobuf

and get the feedback 并获得反馈

Traceback (most recent call last): Traceback(最近一次调用最后一次):

File "<stdin>", line 1, in <module> 在<module>中的文件“<stdin>”,第1行

ImportError: No module named google.protobuf ImportError:没有名为google.protobuf的模块

I then type 然后我输入

exit()

I tried inputting 我尝试输入

sudo apt-get install python-protobuf

which responds with 响应

Reading package lists... Done Building dependency tree 阅读包列表...完成构建依赖关系树
Reading state information... Done python-protobuf is already the newest version. 阅读国家信息......完成python-protobuf已经是最新版本了。 0 upgraded, 0 newly installed, 0 to remove and 283 not upgraded. 0升级,0新安装,0删除,283未升级。

Then I go back into python and try 然后我回到python并尝试

import google.protobuf

again, but I get exactly the same error as before. 再次,但我得到与以前完全相同的错误。

Finally, I tried 最后,我试过了

pip install protobuf

which responded with 作出回应

Requirement already satisfied: protobuf in /usr/local/lib/python2.7/dist-packages 要求已经满足:/usr/local/lib/python2.7/dist-packages中的protobuf

Requirement already satisfied: six>=1.9 in /usr/local/lib/python2.7/dist-packages (from protobuf) 要求已经满足:6> = 1.9 in /usr/local/lib/python2.7/dist-packages(来自protobuf)

Requirement already satisfied: setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf) 要求已经满足:/usr/local/lib/python2.7/dist-packages中的setuptools(来自protobuf)

I tried 我试过了

python
import google.protobuf

and got exactly the same error. 并得到完全相同的错误。 Putting

import protobuf

into python also gets the same error. 进入python也会得到同样的错误。

Some related information: I have tried doing multiple uninstalls/reinstalls with both apt-get and pip to fix th error, with no change. 一些相关信息:我尝试使用apt-get和pip进行多次卸载/重新安装以修复错误,没有任何更改。 Also, one of the first things I did after getting Ubuntu was to download python 2.7 from the website and install it, not realizing python came with Ubuntu. 另外,我在获得Ubuntu之后做的第一件事就是从网站下载python 2.7并安装它,而不是实现python与Ubuntu一起出现。

Thanks again. 再次感谢。

pip install --ignore-installed six

sudo pip install protobuf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM