2016-06-15 25 views
2

TL; DR erhält ImportError: cannot import name pywrap_tensorflow bei der Verwendung von TensorFlow auf El Capitan.Tensorflow ImportError unter OS X

Details: Ich befolgte die TensorFlow-Installationsanweisungen für Mac OS X von here.

Mac OS X, CPU nur, Python 2.7:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0rc0-py2-none-any.whl 

$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0rc0-py2-none-any.whl 

$ sudo pip install --upgrade $TF_BINARY_URL 

Diese Schritte waren erfolgreich.

Also versuchen wir es:

22:54:00/tensorflow $ipython 
Python 2.7.11 (default, Jan 22 2016, 08:29:18) 
Type "copyright", "credits" or "license" for more information. 

IPython 4.2.0 -- An enhanced Interactive Python. 
?   -> Introduction and overview of IPython's features. 
%quickref -> Quick reference. 
help  -> Python's own help system. 
object? -> Details about 'object', use 'object??' for extra details. 
[TerminalIPythonApp] WARNING | File not found: '/shared/.pythonstartup' 

In [1]: import tensorflow as tf 
--------------------------------------------------------------------------- 
ImportError        Traceback (most recent call last) 
<ipython-input-1-41389fad42b5> in <module>() 
----> 1 import tensorflow as tf 

/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>() 
    46 _default_dlopen_flags = sys.getdlopenflags() 
    47 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL) 
---> 48 from tensorflow.python import pywrap_tensorflow 
    49 sys.setdlopenflags(_default_dlopen_flags) 
    50 

ImportError: cannot import name pywrap_tensorflow 
+0

https://github.com/tensorflow/tensorflow/issues/3217 –

Antwort

3

TL; DR: nicht ipython laufen Sie (oder python) von der Wurzel des TensorFlow Git Repository, wenn Sie import tensorflow möchten.

Ich antwortete auf eine ähnliche Frage here. Die einfachste Lösung ist cd aus dem aktuellen Verzeichnis (z. B. cd ~) vor dem Ausführen . Dies verhindert, dass Python durch das Quellverzeichnis tensorflow im aktuellen Pfad verwirrt wird. Das Verzeichnis ./tensorflow im Git-Repository enthält nicht den gesamten generierten Code (z. B. pywrap_tensorflow), der für die Ausführung von TensorFlow erforderlich ist, sondern enthält eine Datei mit der Bezeichnung __init__.py, was den Python-Interpreter verwirrt.

+0

ah Sie sind richtig. das ist so ein seltsamer Fehler, ich kann mich nicht daran erinnern. – javadba

+0

Funktioniert perfekt für mich. Vielen Dank! –