Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Got an error when trying to import Tensorflow in Anaconda

I installed tensorflow with pip3, then validated it with

# Python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

And all works fine in terminal. However, when i try to import tensorflow in Anaconda it throws up an error:

import tensorflow as tf
Traceback (most recent call last):

  File "<ipython-input-4-64156d691fe5>", line 1, in <module>
    import tensorflow as tf

  File "/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *

  File "/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 51, in <module>
    from tensorflow.python import pywrap_tensorflow

  File "/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)

ImportError: Traceback (most recent call last):
  File "/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/Users/Ivan/anaconda3/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/Users/Ivan/anaconda3/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: dlopen(/Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 10): Library not loaded: @rpath/libcublas.8.0.dylib
  Referenced from: /Users/Ivan/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so
  Reason: image not found


Failed to load the native TensorFlow runtime.

I tried some things which I found on the internet, and this is what I get:

  1. When I'm trying commands like

    conda update --all
    

    I get "conda: command not found". In the terminal and in Anaconda prompt too. But if in the terminal I enter

    zsh
    conda info
    

    It works

  2. If I change "Applications on..." in Anaconda from root to tensorflow, it doesn't help.

    Screenshot that shows "Applications on tensorflow":

  3. I think I wrongly downloaded and installed the GPU version of tensorflow, but I uninstalled tensorflow and reinstalled CPU version.

I'm using OS X Sierra and Anaconda 4.4.10. How should I approach this problem? I have only basic understanding of terminal.

like image 372
Иван Кузнецов Avatar asked Oct 22 '25 22:10

Иван Кузнецов


2 Answers

Search for Anaconda Prompt from the Start menu. Right click on it and select Run as Administrator. In the terminal that opens up, type:

conda install tensorflow

This worked for me.

like image 94
Vidya P V Avatar answered Oct 25 '25 11:10

Vidya P V


Thanks everyone for your input) Here is how I solved the problem eventually:

These steps brought me to working tensorflow, but I'm not sure if every one of them was critical.

1) I made sure that my zsh profile worked correctly. It seems that it somehow didn't know conda is installed, I solved it with export PATH=~/anaconda3/bin:$PATH to ~/.zshrc file.

2) I uninstalled wrong versions of tensorflow (with gpu support) and updated everything (Anaconda, python, pip, etc.).

3) Then I created virtual environment following instructions here specifically for Anaconda installation https://www.tensorflow.org/install/install_mac#the_url_of_the_tensorflow_python_package​ (I created environment exactly for python 3.6, previously I unthinkingly just used python 3.3 from example, my bad).

4) I chose this environment in Spyder - everything works.

like image 40
Иван Кузнецов Avatar answered Oct 25 '25 13:10

Иван Кузнецов