2016-03-12 11 views
56

Ich habe gerade letzten tensorflow auf Ubuntu neu installiert:Fehler beim Ausführen des Grund tensorflow Beispiel

$ 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 

Wenn die Anweisungen folgende testet es mit versagt Namen importieren kann nicht 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 

Gibt es eine zusätzliche Änderung benötigt, um meine Python oder Ubuntu/Bash-Umgebung?

Antwort

162

Aus dem Pfad in Ihrem Stack-Trace (/git/tensorflow/tensorflow/…) sieht es so aus, als ob Ihr Python-Pfad die Tensorflow-Bibliotheken aus dem Quellverzeichnis statt der installierten Version lädt. Daher kann die (kompilierte) pywrap_tensorflow-Bibliothek, die in einem anderen Verzeichnis installiert ist, nicht gefunden werden.

Eine übliche Lösung ist es, aus dem cd/git/tensorflow Verzeichnis vor python oder ipython starten.

+3

Entschuldigung für die Verzögerung. Es scheint, dass Sie richtig waren: Ich habe gerade Ipython von meinem Home-Dir gestartet und es funktioniert gut "importieren Tensorflow als tf" – javadba

+2

Danke, brillant beantwortet, das war ein Problem für einige Stunden jetzt. – iratzhash

+0

Hervorragend! Ich habe Tage damit verschwendet. Es scheint, dass ich schließlich eine funktionierende Version habe –

-6

Ich löse das Problem. Versuchen Sie, den Follow-Befehl:

pip install --upgrade pip

4

ich zusammengestellt, installiert TensorFlow von der Quelle (GitHub: https://github.com/tensorflow/tensorflow) in einem Python 2.7 virtuellen Umgebung (Venv). Es funktionierte gut, aber ich brauchte (wie andere bereits erwähnt haben, z. B. Benutzer "mrry" unter Error running basic tensorflow example), aus der Partition, in der ich TensorFlow kompiliert hatte, auf eine andere Partition zu cd, um Tensorflow in Python importieren zu können. Ansonsten habe ich verschiedene Fehler, je nachdem, welche (Quellpartition) Verzeichnis ich in war zu klären.

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

ich später folgte nur die Anweisungen hier,

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

und alles funktioniert einfach, fein .

Als Referenz Ich betreibe INSTALL auf

  • Arch Linux [4.6.3-1-ARCH] x86_64
  • Intel i7-4790
  • Xfce 4.12 Desktop-Umgebung

SCHRITTE:

Ändern Sie Pfade, Venv Namen nach Ihren Vorlieben.

  1. erstellen tf-env:

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

Hinweis: Um die 'Anaconda' metapackage anhängt installiert alle Anaconda-Pakete (NumPy; ...).

  1. Quelle, die Venv (tf-env)

    source activate tf-env 
    

Hinweis aktivieren: hinzugefügt ~/.bashrc als Alias:

alias tf='echo " [TensorFlow in Anaconda Python 2.7 venv (source activate tf]" && source activate tf-env' 
  1. Installieren TensorFlow in dem tf-env Venv:

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

dies die Verwendung von pip umgeht (einschließlich der * .whl Installationsskript), ein alternativer Ansatz TensorFlow zu installieren, die hier beschrieben wird:

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

WORKS!

(tf-env)[[email protected] ~]$ 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)[[email protected] ~]$ 

Sie können dann mit TensorFlow im tf-env arbeiten; B. in Jupyter-Notebooks, die in diesem (tf-env) -Ventus gestartet werden.

0

Befehl unten half mir.

pip install tensorflow --upgrade --force-reinstall 
Verwandte Themen