运行基本张量stream程示例时出错

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

当按照指示testing失败, 无法导入名称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环境进行更改?

从堆栈跟踪( /git/tensorflow/tensorflow/… )中的path看起来,您的Pythonpath可能正在从源目录加载张量stream库,而不是您已经安装的版本。 因此,无法find(编译的) pywrap_tensorflow库,该库安装在不同的目录中。

一个常用的解决scheme是在启动pythonipython之前cd /git/tensorflow目录。

我编译,在Python 2.7的虚拟环境(venv)中从源代码(GitHub: https : //github.com/tensorflow/tensorflow )安装TensorFlow。 它工作正常,但我需要(如其他人提到的,例如用户“mrry”在运行基本tensorflow示例的错误 )cd从我已编译TensorFlow的分区到另一个分区,为了能够导入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桌面环境

安装步骤:

修改path,venv名称根据您的喜好。

  1. 创buildtf-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 

这避免了使用点(包括* .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笔记本电脑。

我解决了这个问题。 尝试以下命令:

pip install --upgrade pip