python更新后的Tensorflow导入错误

时间:2017-02-14 11:11:53

标签: python-2.7 import tensorflow protocol-buffers importerror

我在python 2.7中使用tensorflow。但是,在将python 2.7.10更新为2.7.13之后,我得到了tensorflow的导入错误

File "", line 1, in 
  File "/Users/usrname/Library/Python/2.7/lib/python/site-
                        packages/tensorflow/__init__.py", line 24, in 
    from tensorflow.python import *
  File "/Users/usrname/Library/Python/2.7/lib/python/site-
                        packages/tensorflow/python/__init__.py", line 63, in 
    from tensorflow.core.framework.graph_pb2 import *
  File "/Users/usrname/Library/Python/2.7/lib/python/site-
                        packages/tensorflow/core/framework/graph_pb2.py", line 6, in 
    from google.protobuf import descriptor as _descriptor
ImportError: No module named google.protobuf

pip install protobuf

的输出
Requirement already satisfied: protobuf in /usr/local/lib/python2.7/site-packages 
Requirement already satisfied: setuptools in /Users/usrname/Library/Python/2.7/lib/
    python/site-packages (from protobuf) 
Requirement already satisfied: six>=1.9 in /Library/Python/2.7/site-packages/
    six-1.10.0-py2.7.egg (from protobuf) 
Requirement already satisfied: appdirs>=1.4.0 in /usr/local/lib/python2.7/site-packages
    (from setuptools->protobuf) 
Requirement already satisfied: packaging>=16.8 in /usr/local/lib/python2.7/site-packages 
    (from setuptools->protobuf) 
Requirement already satisfied: pyparsing in /usr/local/lib/python2.7/site-packages 
    (from packaging>=16.8->setuptools->protobuf) 

which python的输出:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python

我相信这条路径在python更新后发生了变化,但不确定。解决方案可能是降级python,但这似乎是一个糟糕的解决方案?当我在团队中工作时,我想避免重新安装Tensorflow,因为最终会有不同的版本,但这可能是要走的路?有什么建议吗?

更新:我厌倦了全部安装tensorflow,但同样的错误不断弹出。也许问题是环境变量,which pip返回/usr/local/bin/pip(与哪个python不同)?

1 个答案:

答案 0 :(得分:0)

我有类似的问题。键入which pipwhich python时,请确保pip和python具有相同的路径。如果它们不同,请更改〜.bash_profile以使python路径与pip路径匹配,并使用source ~\.bash_profile

如果这不起作用,我会尝试重新安装pip和tensorflow。

我使用此命令安装了pip:

wget https://bootstrap.pypa.io/get-pip.py
sudo python2.7 get-pip.py