Home Articles

python更新后的Tensorflow导入错误

Asked
Viewed 1065 times
1

我在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 Answer

  • 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
    

Related