python - 无法导入 Google Protobuf Python 模块

标签 python linux ubuntu protocol-buffers

我正在使用 Ubuntu 14.04 机器,尝试将 google.protobuf 模块导入 python 2.7。

我试过了

apt-get python-protobuf 

pip install protobuf 

没有成功。

在 python 中,我收到一条错误消息:

"ImportError: No module named google.protobuf"

编辑 1:

抱歉并感谢所有发表评论的人。我还是 Ubuntu 和 StackOverflow 的新手。

具体来说,我在命令行中输入

python
import google.protobuf

并获得反馈

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

ImportError: No module named google.protobuf

然后我输入

exit()

我试过输入

sudo apt-get install python-protobuf

响应

Reading package lists... Done Building dependency tree
Reading state information... Done python-protobuf is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 283 not upgraded.

然后我回到 python 并尝试

import google.protobuf

再次出现,但我得到与之前完全相同的错误。

最后,我试过了

pip install protobuf

响应

Requirement already satisfied: protobuf in /usr/local/lib/python2.7/dist-packages

Requirement already satisfied: six>=1.9 in /usr/local/lib/python2.7/dist-packages (from protobuf)

Requirement already satisfied: setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf)

我试过了

python
import google.protobuf

并得到完全相同的错误。放

import protobuf

进入 python 也得到同样的错误。

一些相关信息:我已经尝试使用 apt-get 和 pip 进行多次卸载/重新安装来修复错误,但没有任何改变。此外,我在获得 Ubuntu 后做的第一件事就是从网站下载 python 2.7 并安装它,但没有意识到 Python 是 Ubuntu 自带的。

再次感谢。

最佳答案

pip install --ignore-installed six

sudo pip install protobuf

关于python - 无法导入 Google Protobuf Python 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46478988/

相关文章:

Python - 从标记列表到词袋

ubuntu - 控制flume自身生成的日志文件大小

python - 通过字典有效地替换 Pandas 系列中的值

python - 在 keras 中定义模型(include_top = True)

linux - 使用 mailx 发送邮件正文和附件 - Linux

regex - 在每行的开头和结尾添加字符串和标签

php - Digital Ocean Ubuntu LAMP 服务器 : Laravel cannot access router group

ubuntu - 使用 Make 编译

python - 用python将一些网站的HTML保存在一个txt文件中

c++ - 未从 LD_PRELOAD 的库中调用 system() 函数