(keeping notes here for ease of future references)
See this Stackoverflow forum - Trouble with TensorFlow in Jupyter Notebook
This post is a copy of the answer I submitted (for ease of my own references). i.e. create an environment.yml
file to make this conda / tensorflow installation process more repeatable.
Acknowledgement: The accepted answer (by Zhongyu Kuang) did help me out tons.
environment.yml
looks like this:
name: hello-tensorflow
dependencies:
- python=3.6
- jupyter
- ipython
- pip:
- https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp36-cp36m-linux_x86_64.whl
Note:
- Simply replace the name to whatever you want. (mine is
hello-tensorflow
) - Simply replace the python version to whatever you want. (mine is
3.6
) - Simply replace the tensorflow pip install URL to whatever you want (mine is the Tensorflow URL where Python 3.6 with GPU support)
With the environment.yml
being in the current path you are on, this command creates the environment hello-tensorflow
(or whatever you have renamed it to):
conda env create -f environment.yml
Activate the newly created environment:
source activate hello-tensorflow
which python...
(hello-tensorflow) $ which python
/home/johnny/anaconda3/envs/hello-tensorflow/bin/python
which jupyter...
(hello-tensorflow) $ which jupyter
/home/johnny/anaconda3/envs/hello-tensorflow/bin/jupyter
which ipython...
(hello-tensorflow) $ which ipython
/home/johnny/anaconda3/envs/hello-tensorflow/bin/ipython
You should now be able to import tensorflow from python, jupyter (console / qtconsole / notebook, etc.) and ipython.
Here is what I get:
In [1]: import tensorflow as tf
In [2]: hello = tf.constant('Hello, TensorFlow!')
In [3]: sess = tf.Session()
2017-05-31 17:16:41.853631: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 750 Ti, pci bus id: 0000:01:00.0)
In [4]: print(sess.run(hello))
b'Hello, TensorFlow!'