10

I have installed tensorflow using the anaconda environment as mentioned in the tensorflow website and after doing my python installation path changed.

dennis@dennis-HP:~$ which python                                                                                                   
/home/dennis/anaconda2/bin/python  

And Jupyter was installed. I assumed that if I was able to import and use tensorflow in the conda environment that I will be able to do the same in Jupyter. But that was not the case -

Importing tensorflow in my system (without activating the environment)

dennis@dennis-HP:~$ python                                                                                                         
Python 2.7.11 |Anaconda 4.1.0 (64-bit)| (default, Jun 15 2016, 15:21:30)                                                           
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2                                                                                   
Type "help", "copyright", "credits" or "license" for more information.                                                             
Anaconda is brought to you by Continuum Analytics.                                                                                 
Please check out: http://continuum.io/thanks and https://anaconda.org                                                              
>>> import tensorflow as tf                                                                                                        
Traceback (most recent call last):                                                                                                 
  File "<stdin>", line 1, in <module>                                                                                              
ImportError: No module named tensorflow                                                                                                                                                                                                         
>>> exit()                                                                                                                         

Importing tensorflow in conda environment

dennis@dennis-HP:~$ source activate tensorflow                                                                                     
prepending /home/dennis/anaconda2/envs/tensorflow/bin to PATH                                                                      
(tensorflow) dennis@dennis-HP:~$ python                                                                                            
Python 2.7.12 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:42:40)                                                         
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2                                                                                   
Type "help", "copyright", "credits" or "license" for more information.                                                             
Anaconda is brought to you by Continuum Analytics.                                                                                 
Please check out: http://continuum.io/thanks and https://anaconda.org                                                              
>>> import tensorflow as tf                                                                                                        
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally                              
I tensorflow/stream_executor/dso_loader.cc:102] Couldn't open CUDA library libcudnn.so. LD_LIBRARY_PATH: /usr/local/cuda-7.5/lib64 
I tensorflow/stream_executor/cuda/cuda_dnn.cc:2092] Unable to load cuDNN DSO                                                       
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally                               
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so locally                                
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally

As the above import was successful I tried to do the same in jupyter (launched jupyter within the environment) but I got the following error on import -

ImportError                               Traceback (most recent call last)
<ipython-input-1-41389fad42b5> in <module>()
----> 1 import tensorflow as tf

ImportError: No module named tensorflow

My guess is that the notebook is not run within the environment of conda. So, can you tell me how do I force it to do the same?

Or you can just provide me with details about how to import tensorflow in jupyter

EDIT #1:

I have successfully installed tensorflow in anaconda installation using conda install -c jjhelmus tensorflow=0.9.0 command. [Source: conda.anaconda.org/jjhelmus]

But this disables the GPU support, so a code like the one below returns an error

with tf.Session() as sess:
  with tf.device("/gpu:0"): #GPUs are not enabled on the system so it throws an error
    matrix1 = tf.constant([[3., 3.]])
    matrix2 = tf.constant([[2.],[2.]])
    product = tf.matmul(matrix1, matrix2)
    result = sess.run([product])
    print result

So, how do I enable GPU support? Is there an alternate solution to install tensorflow in conda with GPU support?

EDIT #2:

It is mentioned here, that GPU support is possible only if the source is built for the target GPU. If that is true, please provide details about how it can be done so that I have a GPU enabled tensorflow installation.

Naveen Dennis
  • 1,223
  • 3
  • 24
  • 39
  • what platform are you on? If you're on linux, google has now made a pre-built binary you can use very easily with anaconda. https://www.tensorflow.org/versions/r0.9/get_started/os_setup.html#anaconda-installation – user2561747 Jul 08 '16 at 00:06

2 Answers2

22

Have you ever installed jupyter within the tensorflow environment?

Type which jupyter to find out. The result:

(tensorflow) [..]$ <anaconda_home>/envs/tensorflow/bin/jupyter # installed within the tensorflow environment.
(tensorflow) [..]$ <anaconda_home>/bin/jupyter                 # not installed.

If not installed, type pip install jupyter within the tensorflow environment. Then try to import tensorflow in notebook again.

Hope this can help.

filick
  • 336
  • 1
  • 3
  • Yes, I was able to re-install it within the same channels without issues. But I was not able to find out what exactly was wrong the first time. – Naveen Dennis Aug 31 '16 at 00:39
0

Tensorflow 0.9 with GPU for Anaconda Python 2

For linux, use Google's pre-built binary with Cuda 7.5 and CuDNN v4 (https://www.tensorflow.org/versions/r0.9/get_started/os_setup.html#anaconda-installation):

Pseudoscript: https://gist.github.com/nathanielatom/ccdf39d9f20dca4c9e418ea0e00ccd25

For Mac, install from source with Cuda 7.5 and CuDNN v5.1 RC (https://www.tensorflow.org/versions/r0.9/get_started/os_setup.html#installation-for-mac-os-x)

Pseudoscript: https://gist.github.com/nathanielatom/8c51c91d4bde3e37db0db705e8822e70

user2561747
  • 1,333
  • 2
  • 16
  • 39
  • As you mentioned, I have used the links that you have described to install tensorflow with GPU support. Turns out that the issue was on the setting of the path variable. I previously set export PATH="/home/dennis/anaconda2/bin:$PATH" and this caused the problem. It was fixed after setting the path as export PATH="$PATH:/home/dennis/anaconda2/bin" – Naveen Dennis Jul 08 '16 at 08:45
  • Please add the detail about setting the PATH to anaconda so that I can accept your answer – Naveen Dennis Jul 08 '16 at 08:47
  • The PATH with anaconda should already be setup from your anaconda install. Having PATH="/home/dennis/anaconda2/bin:$PATH" prepended means the anaconda python will definitely be the one executed. The fact that it works when you move it to the end implies you're actually executing a different python (maybe the system python?). Try `which python` or check if the anaconda version is printed out in the preamble when you start an interpreter session. Also, check `which pip` as it seems like you might have installed tensorflow into the system/other python. – user2561747 Jul 08 '16 at 20:13
  • If so (anaconda doesn't show up in `pip`s path), try uninstalling the system/other pip, ensure `which pip` gives you the anaconda version (`/home/dennis/anaconda2/bin/pip`) and reinstall the tensorflow pip package. After a successful anaconda install, tensorflow should live in `/home/dennis/anaconda2/lib/python2.7/site-packages/tensorflow`; so try to `ls` that. Also there are a bunch of useful example nets there. – user2561747 Jul 08 '16 at 20:32