我正在使用 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/