1

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'
HMLDude
  • 1,547
  • 7
  • 27
  • 47
  • `import 'tensorflow'` ?? or `import tensorflow` ?? is typo? – eyllanesc Sep 03 '17 at 18:56
  • @cricket_007 Somehow the first line was working yesterday but not today. I changed the post to reflect that. You are correct. – HMLDude Sep 03 '17 at 23:43
  • @eyllanesc I re-ran the code in 3.6.1 and edited the post to include the accurate error message. – HMLDude Sep 03 '17 at 23:47
  • Did you create a conda env and install it there? In the folder `env` in your anaconda folder do you see the virtual environment you created, by it name. If its there go to the site-packages folder,within that env folder and look for tensorflow, is it there? – DJK Sep 05 '17 at 21:59
  • I had problems with Python 3.6 on my Arch Linux. It worked with Python 3.5.2. Maybe try that? – ITiger Sep 06 '17 at 07:22
  • If @igrinis option doesn't solve your problem, try using https://pypi.python.org/pypi/tensorflow. I had to put that in comment as someone downvoted me without giving any reason. – Beta Sep 06 '17 at 11:37

3 Answers3

3

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.

Lan
  • 6,470
  • 3
  • 26
  • 37
  • thanks for your response. Unfortunately, as I mentioned in my question. No "conda" commands work for me in my terminal. – HMLDude Sep 07 '17 at 18:36
  • @HMLDude Not sure I understand. What do you mean "no conda commands"? conda command is part of the anaconda distribution. If you mean it is not found or when you run it, it throws an error? – Lan Sep 07 '17 at 18:51
  • All attempts to use "conda" from terminal result in the following errror. zsh: ``command not found: conda`` – HMLDude Sep 07 '17 at 20:54
  • @HMLDude The conda command should be located in /bin/conda. You do not find the conda command there? I don't know what happens to your anaconda installation and you might want to reinstall it. But again, you can still use pip to install without using conda to create a virtual environment. You can skip the step 3 in my instruction and it should still work. In this case, the tensorflow will be installed in your root environment and spyder is launched in the root environment too. – Lan Sep 07 '17 at 20:59
  • 3
    You should have anaconda in your [path](https://stackoverflow.com/questions/19029333/how-to-check-that-the-anaconda-package-was-properly-installed), may save your life :) – DJK Sep 07 '17 at 21:38
  • I got tensorflow working by creating a new environment in Anaconda-Navigator and using the visual installer to install Python3.5, Theano and Tensorflow. The only thing that is stopping me from having a working environment is Keras, which does not seem to yet be supported by the visual installer. Everything related to my Python installation from the command line seems to be a mess! – HMLDude Sep 08 '17 at 21:19
1

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
Anurag Sharma
  • 76
  • 1
  • 5
1

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! :)