How I successfully installed Tensorflow

Like many other people, I had difficulty installing tensorflow. Some supposedly contributing factors include my computer's operating system being both Windows 10 and upgraded from Windows 8, along with having both the latest version of Python installed (3.5.4) along side a separate installation of Anaconda3.

I followed the official tutorials on the Tensorflow website, and it did not work. In the testing step, I got an error, the module for tensorflow could not be found.

Long story short, instead of using: pip install --ignore-installed --upgrade tensorflow

I used: C:\Anaconda3\envs\TFenv1\Scripts\pip install --ignore-installed --upgrade tensorflow

That is, I just replaced "pip" with the file location of this particular pip I needed to use. The one that was in my virtual environment (which is called "TFenv1", for tensorflow environment 1). I got that tip here.

Now, to explain in detail...

Tutorials result in an Error
So, since I previously had lots of difficulty before trying to install and use this and other things (like django, and virtualenv which ironically was itself supposed to fix the problems, both of which installed but failed to work properly), I really wanted to follow the official tutorials and make sure I was doing everything right.

Also I learned that Anaconda is good for easily handling a lot of dependencies and such. Previously I just used Python and pip on its own.

Starting with the Anaconda Tutorial
So I got Anaconda and did the getting started tutorial before going anywhere near tensorflow. I wanted to take this one step at a time, make sure everything worked correctly.

Oh ya, first I learned that windows "powershell" does not activate virtual environments when you tell it to (among other difficulties), so I used the Anaconda Prompt, which I learned had no such issues. Once I did that, the Anaconda getting started tutorial went without any difficulty.

(C:\Anaconda3) C:\Users\Brian>cd C:\Anaconda3 (C:\Anaconda3) C:\Anaconda3>cd C:\Anaconda3\Scripts (C:\Anaconda3) C:\Anaconda3\Scripts>conda info --envs # bunnies                 C:\Anaconda3\envs\bunnies myEnvironment1          C:\Anaconda3\envs\myEnvironment1 root                 *  C:\Anaconda3 (C:\Anaconda3) C:\Anaconda3\Scripts>activate bunnies (bunnies) C:\Anaconda3\Scripts>conda info --envs # bunnies              *  C:\Anaconda3\envs\bunnies myEnvironment1          C:\Anaconda3\envs\myEnvironment1 root                    C:\Anaconda3 (bunnies) C:\Anaconda3\Scripts>deactivate C:\Anaconda3\Scripts>conda info --envs # bunnies                 C:\Anaconda3\envs\bunnies myEnvironment1          C:\Anaconda3\envs\myEnvironment1 root                 *  C:\Anaconda3
 * 1) conda environments:
 * 1) conda environments:
 * 1) conda environments:

So, I could now activate a virtual environment!

On to the Tensorflow Tutorial
So, I went on to the Tensorflow official tutorial for installing on Windows with Anaconda.

C:\Anaconda3\Scripts>conda create -n TFenv1 python=3.5 Fetching package metadata ............. Solving package specifications:. Package plan for installation in environment C:\Anaconda3\envs\TFenv1: The following NEW packages will be INSTALLED: certifi:       2017.11.5-py35h456c6ae_0 pip:           9.0.1-py35h691316f_4 python:        3.5.4-h1357f44_23 setuptools:    36.5.0-py35h21a22e4_0 vc:            14-h2379b0c_2 vs2015_runtime: 14.0.25123-hd4c4e62_2 wheel:         0.30.0-py35h38a90bc_1 wincertstore:  0.2-py35hfebbdb8_0 Proceed ([y]/n)? y # # # # C:\Anaconda3\Scripts>activate TFenv1 (TFenv1) C:\Anaconda3\Scripts>pip install --ignore-installed --upgrade tensorflow Collecting tensorflow Downloading tensorflow-1.4.0-cp36-cp36m-win_amd64.whl (28.3MB) 100% |████████████████████████████████| 28.3MB 59kB/s Collecting six>=1.10.0 (from tensorflow) Using cached six-1.11.0-py2.py3-none-any.whl Collecting wheel>=0.26 (from tensorflow) Using cached wheel-0.30.0-py2.py3-none-any.whl Collecting enum34>=1.1.6 (from tensorflow) Downloading enum34-1.1.6-py3-none-any.whl Collecting protobuf>=3.3.0 (from tensorflow) Downloading protobuf-3.5.0.post1-py2.py3-none-any.whl (389kB) 100% |████████████████████████████████| 389kB 2.2MB/s Collecting tensorflow-tensorboard<0.5.0,>=0.4.0rc1 (from tensorflow) Downloading tensorflow_tensorboard-0.4.0rc3-py3-none-any.whl (1.7MB) 100% |████████████████████████████████| 1.7MB 1.7MB/s Collecting numpy>=1.12.1 (from tensorflow) Downloading numpy-1.13.3-cp36-none-win_amd64.whl (13.1MB) 100% |████████████████████████████████| 13.1MB 433kB/s Collecting setuptools (from protobuf>=3.3.0->tensorflow) Downloading setuptools-37.0.0-py2.py3-none-any.whl (481kB) 100% |████████████████████████████████| 491kB 1.2MB/s Collecting html5lib==0.9999999 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow) Downloading html5lib-0.9999999.tar.gz (889kB) 100% |████████████████████████████████| 890kB 1.9MB/s Collecting markdown>=2.6.8 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow) Downloading Markdown-2.6.9.tar.gz (271kB) 100% |████████████████████████████████| 276kB 688kB/s Collecting bleach==1.5.0 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow) Downloading bleach-1.5.0-py2.py3-none-any.whl Collecting werkzeug>=0.11.10 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow) Downloading Werkzeug-0.12.2-py2.py3-none-any.whl (312kB) 100% |████████████████████████████████| 317kB 1.5MB/s Building wheels for collected packages: html5lib, markdown Running setup.py bdist_wheel for html5lib ... done Stored in directory: C:\Users\Brian\AppData\Local\pip\Cache\wheels\6f\85\6c\56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962 Running setup.py bdist_wheel for markdown ... done Stored in directory: C:\Users\Brian\AppData\Local\pip\Cache\wheels\bf\46\10\c93e17ae86ae3b3a919c7b39dad3b5ccf09aeb066419e5c1e5 Successfully built html5lib markdown Installing collected packages: six, wheel, enum34, setuptools, protobuf, numpy, html5lib, markdown, bleach, werkzeug, tensorflow-tensorboard, tensorflow Successfully installed bleach-2.0.0 enum34-1.1.6 html5lib-0.999999999 markdown-2.6.9 numpy-1.13.3 protobuf-3.5.0.post1 setuptools-37.0.0 six-1.11.0 tensorflow-1.4.0 tensorflow-tensorboard-0.4.0rc3 werkzeug-0.12.2 wheel-0.30.0 (TFenv1) C:\Anaconda3\Scripts>$ python '$' is not recognized as an internal or external command, operable program or batch file. (TFenv1) C:\Anaconda3\Scripts>python Python 3.5.4 |Anaconda, Inc.| (default, Nov 8 2017, 14:34:30) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf Traceback (most recent call last): File " ", line 1, in ImportError: No module named 'tensorflow'
 * 1) To activate this environment, use:
 * 1) > activate TFenv1
 * 1) To deactivate an active environment, use:
 * 1) > deactivate
 * 1) * for power-users using bash, you must source

So, there's the error. No module named tensorflow.

Trying to solve the Error
I went to google and found many people having this same error. All kinds of fixes were proposed. I didn't know which to try. (I did try "python3" instead of "python", which worked for some people, but just gave me an error, "not a recognizeable command operable program or batch file")

Didn't it install successfully?
I found I could check what was in my virtual environment, wasn't tensorflow installed successfully? Here's what I found: (TFenv1) C:\Anaconda3\Scripts>conda list # certifi                  2017.11.5        py35h456c6ae_0 pip                      9.0.1            py35h691316f_4 python                   3.5.4               h1357f44_23 setuptools               36.5.0           py35h21a22e4_0 vc                       14                   h2379b0c_2 vs2015_runtime           14.0.25123           hd4c4e62_2 wheel                    0.30.0           py35h38a90bc_1 wincertstore             0.2              py35hfebbdb8_0
 * 1) packages in environment at C:\Anaconda3\envs\TFenv1:

So hmm, it wasn't there. That's basically the list of stuff inside the folder dedicated to this virtual environment, but it isn't showing up.

What I did next was open the folder that my Anaconda3 is installed in, and simply searched for "tensorflow". I found the files that were installed. Every one of them was in C:\Anaconda3\Lib\site-packages.

They weren't in the folder of my virtual environment.

Not installed in the right place, so how to fix that?
I actually tried just copying and pasting one of those tensorflow folders into the correct folder in my virtual environment folder. Then I tested to see if this worked: (TFenv1) C:\Anaconda3\Scripts>conda list # certifi                  2017.11.5        py35h456c6ae_0 pip                      9.0.1            py35h691316f_4 python                   3.5.4               h1357f44_23 setuptools               36.5.0           py35h21a22e4_0 vc                       14                   h2379b0c_2 vs2015_runtime           14.0.25123           hd4c4e62_2 wheel                    0.30.0           py35h38a90bc_1 wincertstore             0.2              py35hfebbdb8_
 * 1) packages in environment at C:\Anaconda3\envs\TFenv1:

So, it didn't show up when I tried this again, but what the heck, I decided to check if the error still happened or what: (TFenv1) C:\Anaconda3\Scripts>python Python 3.5.4 |Anaconda, Inc.| (default, Nov 8 2017, 14:34:30) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf Traceback (most recent call last): File " ", line 1, in   File "C:\Anaconda3\envs\TFenv1\lib\site-packages\tensorflow\__init__.py", line 24, in      from tensorflow.python import * File "C:\Anaconda3\envs\TFenv1\lib\site-packages\tensorflow\python\__init__.py", line 47, in     import numpy as np ImportError: No module named 'numpy'

Well isn't that interesting? The "no module named 'tensoflow'" error was gone! That means it now saw a module named tensorflow, the one I pasted into the folder.

Of course, now it couldn't find the next thing it needed, numpy, which I hadn't pasted in.

So I had learned from this experiment where the module needed to be (I kinda knew that before, but was even more sure now).

Then I found a response online that said how to correctly use the pip inside the virtual environment to install stuff inside of the virtual environment(I had to quickly rename that pasted tensorflow folder so that it wouldn't interfere with this new installation, then I deleted it): (TFenv1) C:\Anaconda3\Scripts>C:\Anaconda3\envs\TFenv1\Scripts\pip install --ignore-installed --upgrade tensorflow Collecting tensorflow Downloading tensorflow-1.4.0-cp35-cp35m-win_amd64.whl (28.3MB) 100% |################################| 28.3MB 29kB/s Collecting protobuf>=3.3.0 (from tensorflow) Using cached protobuf-3.5.0.post1-py2.py3-none-any.whl Collecting enum34>=1.1.6 (from tensorflow) Using cached enum34-1.1.6-py3-none-any.whl Collecting six>=1.10.0 (from tensorflow) Using cached six-1.11.0-py2.py3-none-any.whl Collecting tensorflow-tensorboard<0.5.0,>=0.4.0rc1 (from tensorflow) Using cached tensorflow_tensorboard-0.4.0rc3-py3-none-any.whl Collecting wheel>=0.26 (from tensorflow) Using cached wheel-0.30.0-py2.py3-none-any.whl Collecting numpy>=1.12.1 (from tensorflow) Downloading numpy-1.13.3-cp35-none-win_amd64.whl (13.1MB) 100% |################################| 13.1MB 107kB/s Collecting setuptools (from protobuf>=3.3.0->tensorflow) Using cached setuptools-37.0.0-py2.py3-none-any.whl Collecting markdown>=2.6.8 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow) Using cached Markdown-2.6.9.tar.gz Collecting werkzeug>=0.11.10 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow) Using cached Werkzeug-0.12.2-py2.py3-none-any.whl Collecting bleach==1.5.0 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow) Using cached bleach-1.5.0-py2.py3-none-any.whl Collecting html5lib==0.9999999 (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow) Using cached html5lib-0.9999999.tar.gz Building wheels for collected packages: markdown, html5lib Running setup.py bdist_wheel for markdown ... done Stored in directory: C:\Users\Brian\AppData\Local\pip\Cache\wheels\bf\46\10\c93e17ae86ae3b3a919c7b39dad3b5ccf09aeb066419e5c1e5 Running setup.py bdist_wheel for html5lib ... done Stored in directory: C:\Users\Brian\AppData\Local\pip\Cache\wheels\6f\85\6c\56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962 Successfully built markdown html5lib Installing collected packages: six, setuptools, protobuf, enum34, markdown, werkzeug, html5lib, bleach, wheel, numpy, tensorflow-tensorboard, tensorflow Successfully installed bleach-1.5.0 enum34-1.1.6 html5lib-0.9999999 markdown-2.6.9 numpy-1.13.3 protobuf-3.5.0.post1 setuptools-37.0.0 six-1.11.0 tensorflow-1.4.0 tensorflow-tensorboard-0.4.0rc3 werkzeug-0.12.2 wheel-0.30.0 (TFenv1) C:\Anaconda3\Scripts>conda list # bleach                   1.5.0 certifi                  2017.11.5        py35h456c6ae_0 enum34                   1.1.6 html5lib                 0.9999999 Markdown                 2.6.9 numpy                    1.13.3 pip                      9.0.1            py35h691316f_4 protobuf                 3.5.0.post1 python                   3.5.4               h1357f44_23 setuptools               36.5.0           py35h21a22e4_0 setuptools               37.0.0 six                      1.11.0 tensorflow               1.4.0 tensorflow-tensorboard   0.4.0rc3 vc                       14                   h2379b0c_2 vs2015_runtime           14.0.25123           hd4c4e62_2 Werkzeug                 0.12.2 wheel                    0.30.0 wheel                    0.30.0           py35h38a90bc_1 wincertstore             0.2              py35hfebbdb8_0 (TFenv1) C:\Anaconda3\Scripts>python Python 3.5.4 |Anaconda, Inc.| (default, Nov 8 2017, 14:34:30) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf >>> hello = tf.constant('hello tensorFLOW!') >>> sess = tf.Session >>> print(sess.run(hello)) b'hello tensorFLOW!' >>> print('why is there a b?') why is there a b? >>> print(sess.run(hello)) b'hello tensorFLOW!' >>>
 * 1) packages in environment at C:\Anaconda3\envs\TFenv1:

It works!

As for that curious "b" at the end, it looks like that's fine and not an issue at all.