I am a new users for Python and want to use tensorflow. I think I successfully installed tensorflow on my mac OSX via Anaconda. But I still can't figure out how to use tensorflow on Spyder. Could someone help me? Many thanks!
-
Could you try to run tensorflow (examples) in the command line first? – Sung Kim May 05 '16 at 04:45
-
I can run tensorflow in Python. But in Spyder interface, it doesn't work. – Oscar May 05 '16 at 13:46
8 Answers
System default python maybe used on command line, first verify that you are using the python from anaconda distro. Set up the environment variables first.
If you are not building tensorflow with GPU support. you can install tensorflow through conda in one command.
$ conda install -c https://conda.anaconda.org/jjhelmus tensorflow
in Spyder: import tensorflow as tf. and you're good to go.

- 599
- 10
- 18
-
1wow! it really works even though I don't understand why this works while it doesn't work if I follow the installation guidance on the official website. Can you give me some reasons? – Oscar May 05 '16 at 14:00
-
@Oscar Python comes pre-installed on Mac OS X, so when you install anaconda distribution, it may not change the PATH to anaconda's python. Installing tensorflow through pip, you may not see it with anaconda python. pip and conda (anaconda's package manager) don't play very well together. best way is to build a conda package and install it through conda. – Irtaza May 11 '16 at 11:09
After installing Tensorflow using Anaconda based on Installing TensorFlow on Windows you must change your Environment for Spyder.
1) Open Anaconda Navigator
2) In top left corner you see Selector: "Applications on: base(root)"
3) Change: "base root" for "Tensorflow" it assumes that it was already installed based on link above
4) Install Spyder
5) Open Spyder and make your first test file:
010 import tensorflow as tf
020 hello = tf.constant('Hello, TensorFlow!')
030 sess = tf.Session()
040 print(sess.run(hello))
6) Run it in Spyder and it will work

- 61
- 1
- 1
I had tensorflow running in ipython and from a command line. Where you have tensorflow working, find out the search path by typing
import sys
print (sys.path)
In spyder ipython console do the same thing and you will probably get different answers. Now drag the mouse over path where tensorflow works and copy it. Start a program with the command
import sys
sys.path = [ path cut from ipython window]
For example, my command line with working tensorflow had the path
['', '/home/gaw/anaconda3/envs/tensorflow/lib/python35.zip', \
'/home/gaw/anaconda3/envs/tensorflow/lib/python3.5', \
'/home/gaw/anaconda3/envs/tensorflow/lib/python3.5/plat-linux', \
'/home/gaw/anaconda3/envs/tensorflow/lib/python3.5/lib-dynload', \
'/home/gaw/anaconda3/envs/tensorflow/lib/python3.5/site-packages', \
'/home/gaw/anaconda3/envs/tensorflow/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg']
My spyder window where tensorflow did not work had the path
sys.path = ['', '/home/gaw/anaconda3/envs/tensorflow/lib/python35.zip', '/home/gaw/anaconda3/envs/tensorflow/lib/python3.5', '/home/gaw/anaconda3/envs/tensorflow/lib/python3.5/plat-linux', '/home/gaw/anaconda3/envs/tensorflow/lib/python3.5/lib-dynload', '/home/gaw/anaconda3/envs/tensorflow/lib/python3.5/site-packages', '/home/gaw/anaconda3/envs/tensorflow/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg']
In spyder I put
sys.path = ['', '/home/gaw/anaconda3/envs/tensorflow/lib/python35.zip', \
'/home/gaw/anaconda3/envs/tensorflow/lib/python3.5', \
'/home/gaw/anaconda3/envs/tensorflow/lib/python3.5/plat-linux', \
'/home/gaw/anaconda3/envs/tensorflow/lib/python3.5/lib-dynload', \
'/home/gaw/anaconda3/envs/tensorflow/lib/python3.5/site-packages', \
'/home/gaw/anaconda3/envs/tensorflow/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg']
Set the path in spyder to the same value as the one that works.

- 49,044
- 25
- 144
- 182

- 21
- 1
-
I had the same problem and what you described is exactly the reason why Spyder cannot find the tensorflow packages. My solution to fix this is to use the PYTHONPATH manager under the Tools tab in the spyder to add the directories where tensorflow packages are installed and click synchronize button. Then restart the ipython console and it works. I can now import tensorflow in spyder with no problem. – rort1989 Mar 17 '18 at 21:29
The first answer doesn't work properly, it installs all the old libraries.
By old I mean : It installs version : 0.10.0
Latest Version : 1.0.0 (Can be installed in the tensorflow website)
Install using the below link: https://www.tensorflow.org/versions/r0.12/get_started/os_setup#anaconda_installation
After the installation, I was able to work with IPython too, without any issues. Please don't skip any steps

- 11
- 2
You might want to try this:
conda install -c huggingface transformers
(otherwise all the prebuilt model (like bert) won't work)
The information you need is here: https://pypi.org/project/transformers/

- 36
- 2
My answer assumes that you're using a Python virtual environment.
I ran into some problems -- not being able to import TensorFlow -- when using Spyder in a virtual environment.
TensorFlow was installed but could not be imported in code running from within Spyder.
To configure your system properly within your virtual Python enviornment (where Tensorflow is installed), consider what Oussema Aroua suggests, near the bottom, here: How to run Spyder in virtual environment?
There are also some other problems when actually running Tensorflow programs from within Spyder.
For example, TensorFlow's runtime continues running even after a TF program has run and finished from within Spyder. (This is a Spyder+TF issue.) This leads to some funny results. For example, an RNN cell and its name space might not be cleaned up. I have not tested this from within Notebook but I suspect you will run into a similar issue there.

- 97
- 8
In my case, I have python 3.6 installed with Spyder 3 on ubuntu 18.04.02
- I set the spyder3 to use a custom Python interpreter
Use the following Python interpreter:
/usr/bin/python3
- Then I install tensorflow for python3.x as such from the terminal
pip3 install tensorflow
- Test it Launch spyder3 and import it for a test
import tensorflow as tf
print(tf.version)
I think the easiest way to run Tensorflow on Spyder is via loading Spyder in Anaconda under certain conditions, as follows:
after all atuo-installations proceed with loading spyder and tensorflow shoul work upon importing.

- 31
- 3