HMLDude
HMLDude

Reputation: 1637

Tensorflow Not Working from Anaconda on Mac

When it comes to installing Tensorflow, I've tried each of the installation suggestions on this page.

https://www.tensorflow.org/install/install_mac

-Pip + Pip3

-virtualenv

-With Docker

The only installation method that I was unable to apply was Conda. My default environment for Data Science is Spyder launched from Anaconda_Navigator. However, I am unable to get the Conda command to work, in any form, from the command line.

My goal is to get tensor flow working from the iPython console from with in Spyder.

I am trying to run the suggested validation code:

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

Here is the information on my iPython installation:

Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
Type "copyright", "credits" or "license" for more information.

IPython 5.3.0 -- An enhanced Interactive Python.

The first line of code throws the following error.

ModuleNotFoundError: No module named 'tensorflow'

When I try to run from Python 2.7 in the command line from terminal, I get:

ImportError: numpy.core.multiarray failed to import


Failed to load the native TensorFlow runtime.

When I try to run it from the terminal command line in Python 3.6.1, I get the following error in regards to the second line of code:

AttributeError: module 'tensorflow' has no attribute 'constant'

Upvotes: 1

Views: 3018

Answers (3)

Felipe Leite Antunes
Felipe Leite Antunes

Reputation: 101

The first error

ModuleNotFoundError: No module named 'tensorflow'

is related to Anaconda path. Anaconda does't use the PYTHONPATH. Try:

unset PYTHONPATH
source activate anaconda-x.x #your version instead of x.x
python
>>>> import tensorflow as tf

The second error

ImportError: numpy.core.multiarray failed to import

Failed to load the native TensorFlow runtime.

is due numpy version needs of tensorflow, try upgrade numpy.

The third error,

AttributeError: module 'tensorflow' has no attribute 'constant'

may be related to your binary (hint: check if you are using the correct CPU (or GPU) for your OS).

Let me know if something helped you. Good luck! :)

Upvotes: 1

Anurag Sharma
Anurag Sharma

Reputation: 76

Try this:

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

sudo pip install --upgrade $TF_BINARY_URL

Upvotes: 1

Lan
Lan

Reputation: 6660

I followed the below steps and it worked for me.

  1. Use Conda to create a new virtual environment called "tensorflow" and install the tensorflow in the new conda environment, following the instructions of below link: https://www.tensorflow.org/install/install_mac. The section name is "Installing with Anaconda". All these steps are run through a MAC terminal.
  2. Launch the Anaconda Navigator as usual
  3. Switch to the new "tensorflow" environment using the drop-down box at the top. This is important. By default, "root" environment is chosen.
  4. The new "tensorflow" environment does not have spyder installed. Click the "Install" button. You should see the screenshot like below

enter image description here 5. Launch spyder and type the sample tensorflow codes you want to execute.

Good luck.

Upvotes: 3

Related Questions