运行基本的TensorFlow示例时出错
python
tensorflow
5
0

我刚刚在ubuntu上重新安装了最新的tensorflow:

$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
[sudo] password for ubuntu: 
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting tensorflow==0.7.1 from https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
  Downloading https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl (13.8MB)
    100% |████████████████████████████████| 13.8MB 32kB/s 
Requirement already up-to-date: six>=1.10.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: protobuf==3.0.0b2 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: wheel in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: numpy>=1.8.2 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf==3.0.0b2->tensorflow==0.7.1)
Installing collected packages: tensorflow
  Found existing installation: tensorflow 0.7.1
    Uninstalling tensorflow-0.7.1:
      Successfully uninstalled tensorflow-0.7.1
Successfully installed tensorflow-0.7.1

当按照说明进行测试时,它失败并无法导入名称pywrap_tensorflow

$ ipython

/git/tensorflow/tensorflow/__init__.py in <module>()
     21 from __future__ import print_function
     22 
---> 23 from tensorflow.python import *

/git/tensorflow/tensorflow/python/__init__.py in <module>()
     43 _default_dlopen_flags = sys.getdlopenflags()
     44 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
---> 45 from tensorflow.python import pywrap_tensorflow
     46 sys.setdlopenflags(_default_dlopen_flags)
     47 

ImportError: cannot import name pywrap_tensorflow

我的python或ubuntu / bash环境是否需要进行其他更改?

参考资料:
Stack Overflow
收藏
评论
共 3 个回答
高赞 时间 活跃

从堆栈跟踪中的路径( /git/tensorflow/tensorflow/… ),看来您的Python路径可能正在从源目录而不是已安装的版本加载tensorflow库。结果,无法找到(编译的) pywrap_tensorflow库,该库安装在其他目录中。

常见的解决方案是在启动pythonipython之前,将cd/git/tensorflow目录中ipython

收藏
评论

下面的命令帮助了我。

 pip install tensorflow --upgrade --force-reinstall
收藏
评论

我在Python 2.7虚拟环境(venv)中从源代码(GitHub: https : //github.com/tensorflow/tensorflow )编译安装了TensorFlow。它工作正常,但是我需要(如其他人所提到的,例如Error运行基本tensorflow示例的错误处的用户“ mrry”)从已经编译TensorFlow的分区中cd出到另一个分区,以便能够导入tensorflow进入Python。否则,我会遇到各种错误,具体取决于我所在的(源分区)目录。

         source: /mnt/Vancouver/apps/tensorflow
can't import tf: Python launched in any of /mnt/...
  can import tf: Python launched in /home/victoria/...

我后来只是按照这里的指示进行操作,

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation

一切都正常,很好。

供参考,我正在

  • Arch Linux [4.6.3-1-ARCH] x86_64
  • 英特尔i7-4790
  • xfce 4.12桌面环境

安装步骤:

根据您的喜好修改路径,虚拟名称。

  1. 创建tf-env:

     cd /home/victoria/anaconda3/envs conda create -n tf-env python=2.7 anaconda 

注意:附加'anaconda'元软件包将安装所有Anaconda软件包(NumPy; ...)。

  1. 源激活该venv(tf-env)

     source activate tf-env 

注意:作为别名添加到〜/ .bashrc中:

alias tf='echo "  [TensorFlow in Anaconda Python 2.7 venv (source activate tf]" && source activate tf-env'
  1. 在tf-env venv中安装TensorFlow:

     (tf-env)$ conda install -c conda-forge tensorflow 

这避免了pip的使用(包括* .whl安装脚本),这是安装TensorFlow的另一种方法,如下所述:

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md).

作品!

(tf-env)[victoria@victoria ~]$ P

  [P: python]
Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jul  2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org

>>> import tensorflow
>>> print tensorflow.__version__
0.9.0
>>> [Ctrl-D]

(tf-env)[victoria@victoria ~]$

然后,您可以在tf-env中使用TensorFlow;例如,在(tf-env)venv中推出的Jupyter笔记本中。

收藏
评论
新手导航
  • 社区规范
  • 提出问题
  • 进行投票
  • 个人资料
  • 优化问题
  • 回答问题

关于我们

常见问题

内容许可

联系我们

@2020 AskGo
京ICP备20001863号