How to install TensorFlow on Anaconda – Easiest method to follow by TopBullets.com

Topbullets.comTensorFlow is mainly developed by Google and released under open source license. We can easily access Tensorflow in Python to create Deep Learning models. I had to use Keras library for Recurrent Neural Networks and found that I need to install Tensorflow to use Keras. I really found the process very tough. For people like me who has very less knowledge about Python or pip or conda, it was a nightmare. Finally, I could solve the issue and installed the package successfully but had to read hundreds of articles and followed more than 10-15 methods, installed Anaconda more than 7-10 times to get the right version. As I have faced all these issues and installed it successfully, I thought of writing about it. Also, one of my dearest friends keeps me pushing to write a blog at least once a week so hopefully this will help me. Though there are hundreds of articles and there is very less chance that my blog would appear in Google search like other articles, but it is worth sharing and writing.

What are the problems I faced?
1. Tensorflow is asking for specific Python version 3.5 or 3.6
2. pip install command is not working
3. It is advised to create a new environment on Anaconda. Why and how?
4. How to access the new environment on Anaconda.
and many more. Let me explain few things. As per my knowledge you need Python 3.5+ to install Tensorflow on Windows. And we create a new environment on Anaconda so that our existing codes which were written in different versions are not affected. It should not matter which Anaconda or Python version you currently have, just follow my code below. Currently, I have Python 2.7 but let me show you how to do it.

Open “Anaconda Prompt” and run this code. We are creating a new environment names ‘tensorflow_demo’.

conda create -n tensorflow_demo python=3.5

Pic1

Press ‘Y’ and let the new packages get installed. Once everything is installed, it will ask to “Activate it”

activate tensorflow_demo

Once you run the above command your prompt should change. It should look like below image.

Pic2

It means you are inside this environment and can run or install any package independently. Now we need to install Tensorflow and Spyder in this environment.

pip install --ignore-installed --upgrade tensorflow

then let’s install Spyder.

conda install spyder

Now let’s test if Tensorflow is installed successfully through Spyder. But this Spyder is not the default one. We need to run the recently installed Spyder. So the best way to reach to the folder is search ‘Spyder’ in Search and right click to go to the folder.

Pic3

Otherwise, you can look into this folder.
C:\Users\REPLACE.WITH.PCNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda2 (64-bit).
Run the recently installed Spyder (tensorflow_demo). Now we are ready to run some basic code using Tensorflow package.

Pic4

Run the below code in Spyder.

import tensorflow as ts
sess = ts.Session()
a = ts.constant(10)
b = ts.constant(32)
print(sess.run(a+b)) 

Pic5

If you want to delete the enviroment from Anaconda, run this command in Anaconda Prompt.

conda env remove -n tensorflow_demo

I will keep posting about new things I experiment with this package. Until that time thank you for reading. Here are few references that helped me to compile this article.
1. https://www.tensorflow.org/install/install_windows
2. https://www.tensorflow.org/versions/r0.12/get_started/os_setup#anaconda_installation
3. https://www.tensorflow.org/versions/r1.2/install/install_windows
4. https://github.com/antoniosehk/keras-tensorflow-windows-installation
5. https://github.com/spyder-ide/spyder/issues/4223

Signature

Deepesh Singh
logo

Advertisement

4 thoughts on “How to install TensorFlow on Anaconda – Easiest method to follow by TopBullets.com

  1. I did this but now when I try to import OpenCv or matplotlib using “import cv2”, I get error message saying “no module named cv2”. What to do now??? Plz help.

  2. I did all the mentioned steps and it does create an instance of Spyder but Spyder does not open.
    Please let me know if there is a fix for this . Thank you

Please leave your valuable comment.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s