【问题标题】:Tensorflow is not installed properlyTensorFlow 未正确安装
【发布时间】:2016-04-17 11:22:57
【问题描述】:

我是初学者,我尝试按照网站上的说明在 Macbook 上安装张量流。

sudo easy_install pip
sudo easy_install --upgrade six
sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.6.0-py2-none-any.whl

安装后,当我尝试导入张量流时,出现以下错误:

    >>> import tensorflow
RuntimeError: module compiled against API version a but this version of numpy is 9
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/tensorflow/__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "/Library/Python/2.7/site-packages/tensorflow/python/__init__.py", line 50, in <module>
    from tensorflow.python.framework.framework_lib import *
  File "/Library/Python/2.7/site-packages/tensorflow/python/framework/framework_lib.py", line 62, in <module>
    from tensorflow.python.framework.ops import Graph
  File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 40, in <module>
    from tensorflow.python.framework import versions
  File "/Library/Python/2.7/site-packages/tensorflow/python/framework/versions.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: numpy.core.multiarray failed to import
>>> 

我是 python 新手,我在互联网上尝试了一些解决方案,但到目前为止都没有奏效。也许错误是由于 pip 安装造成的。自两天以来,我一直坚持这一点。感谢您的帮助!

【问题讨论】:

  • 试过sudo pip install -U numpy?
  • 是的,它显示 Requirement already up-to-date: numpy in /Library/Python/2.7/site-packages
  • 您试过sudo pip install numpy==1.10.4 来获取最新版本吗?还有一个标志可以点,--upgrade 这可能会有所帮助。
  • 不。我试过了,但它仍然显示相同的需求已经是最新的:/Library/Python/2.7/site-packages 中的 numpy –
  • 您可以尝试在virtualenv 中仅使用pip 安装所有这些吗?

标签: python python-2.7 numpy tensorflow


【解决方案1】:

要补充上一个答案 - 在我的 OSX 机器 (10.11) 上,我发现了两个 numpy 的工厂安装 - 一个在 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy,另一个在 /Library/Python/2.7/site-packages/numpy/。据我所知,pip 将升级 /Library 中的那个,但 python 一直尝试首先使用 /System/Library/ 中的那个。

作为临时解决方案,我只是将/System/Library 中的numpy 文件夹重命名为numpy.oldTensorflow 之后正确导入。

【讨论】:

    【解决方案2】:

    我想我遇到了同样的问题。这是由 Max OSX 上工厂安装的 Python 上的早期版本的工厂包含的 numpy 引起的。

    我试过 sudo pip uninstall numpy 并且包含因子的 numpy 仍然存在。为了解决这个问题,我使用easy_install 升级了工厂包含的numpy,然后使用pip 安装tensorflow 并且它起作用了:

    sudo easy_install -U numpy
    sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.6.0-py2-none-any.whl
    

    【讨论】:

      【解决方案3】:

      所以最后我所做的是删除了 tensorflow、pip 和所有内容。问题是我使用的是 Mac OSX python,因此我遇到了问题。我使用 homebrew 安装 python,然后创建 virtualenv 并使用 pip 再次安装 tensorflow。之后它就开始工作了。

      【讨论】:

        【解决方案4】:

        总结

        这解决了我的问题:

        $ sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
        

        详情

        环境和症状

        我的 Mac OS X Yosemite 上安装了 3 个 python:

        • 操作系统自带的2.6
        • 我已经安装的2.7
        • 3.4我已经安装了

        当然,我在正确设置方面做得很差,python 二进制文件和库在 mac 上到处都是。

        我在尝试使用 https://github.com/Ning-Ding/Implementation-CVPR2015-CNN-for-ReID/tree/master/CUHK03 时遇到此错误

        $ python ./main.py --dataset cuhk-03.h5
        
        Using TensorFlow backend.
        RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
        Traceback (most recent call last):
          File "./main.py", line 14, in <module>
            from model import generate_model,compile_model
          File "/Users/rv186016/repositories/Implementation-CVPR2015-CNN-for-ReID/CUHK03/model.py", line 12, in <module>
            from keras.layers import Input
          File "/Library/Python/2.7/site-packages/keras/__init__.py", line 3, in <module>
            from . import activations
          File "/Library/Python/2.7/site-packages/keras/activations.py", line 4, in <module>
            from . import backend as K
          File "/Library/Python/2.7/site-packages/keras/backend/__init__.py", line 73, in <module>
            from .tensorflow_backend import *
          File "/Library/Python/2.7/site-packages/keras/backend/tensorflow_backend.py", line 1, in <module>
            import tensorflow as tf
          File "/Library/Python/2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
            from tensorflow.python import *
          File "/Library/Python/2.7/site-packages/tensorflow/python/__init__.py", line 51, in <module>
            from tensorflow.python import pywrap_tensorflow
          File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
            raise ImportError(msg)
        ImportError: Traceback (most recent call last):
          File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
            from tensorflow.python.pywrap_tensorflow_internal import *
          File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
            _pywrap_tensorflow_internal = swig_import_helper()
          File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
            _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
        ImportError: numpy.core.multiarray failed to import
        
        
        Failed to load the native TensorFlow runtime.
        
        See https://www.tensorflow.org/install/install_sources#common_installation_problems
        
        for some common reasons and solutions.  Include the entire stack trace
        above this error message when asking for help.
        

        解决方案

        查看 se7en007https://github.com/tensorflow/tensorflow/issues/559 的评论后,我运行了这些喜欢我的问题的命令。查看numpy 版本中的差异以及rm 命令前后的路径。

        $ python
        Python 2.7.10 (default, Jul 14 2015, 19:46:27)
        [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
        Type "help", "copyright", "credits" or "license" for more information.
        >>> import numpy
        >>> numpy.__version__
        '1.8.0rc1'
        >>> numpy.__path__
        ['/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy']
        >>> exit()
        
        $ sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
        MUSRV186016-382:CUHK03 rv186016$ python
        Python 2.7.10 (default, Jul 14 2015, 19:46:27)
        [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
        Type "help", "copyright", "credits" or "license" for more information.
        >>> import numpy
        >>> numpy.__path__
        ['/Library/Python/2.7/site-packages/numpy']
        >>> numpy.__version__
        '1.12.0'
        >>> ^D
        
        $ python ./main.py --dataset cuhk-03.h5
        Using TensorFlow backend.
        ____________________________________________________________________________________________________
        Layer (type)                     Output Shape          Param #     Connected to
        ====================================================================================================
        input_1 (InputLayer)             (None, 160, 60, 3)    0
        ____________________________________________________________________________________________________
        input_2 (InputLayer)             (None, 160, 60, 3)    0
        ____________________________________________________________________________________________________
        conv2d_1 (Conv2D)                (None, 156, 56, 20)   1520        input_1[0][0]
                                                                           input_2[0][0]
        ...
        

        【讨论】:

          猜你喜欢
          • 2021-09-16
          • 2020-12-13
          • 2020-06-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-07-21
          • 2021-05-30
          • 2019-06-01
          相关资源
          最近更新 更多