首页 文章

如何:在支持GPU的情况下从Conda导入Jupyter笔记本中的TensorFlow?

提问于
浏览
10

我已经使用tensorflow website中提到的anaconda环境安装了tensorflow,并且在更改了我的python安装路径之后 .

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

并且安装了Jupyter . 我假设如果我能够在conda环境中导入和使用tensorflow,我将能够在Jupyter中执行相同操作 . 但事实并非如此 -

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

由于上面的导入成功,我试图在jupyter中做同样的事情(在环境中启动了jupyter)但是我在导入时遇到以下错误 -

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

ImportError: No module named tensorflow

我的猜测是笔记本电脑不是在康达环境中运行的 . 所以,你能告诉我如何强迫它做同样的事情吗?

或者您可以向我提供有关如何在jupyter中导入tensorflow的详细信息

EDIT #1:

我已经使用 conda install -c jjhelmus tensorflow=0.9.0 命令在anaconda安装中成功安装了tensorflow . [来源:conda.anaconda.org/jjhelmus]

但这会禁用GPU支持,因此像下面的代码会返回错误

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:

提到here,只有在为目标GPU构建源时才支持GPU . If that is true, please provide details about how it can be done 所以我有一个GPU启用tensorflow安装 .

2 回答

相关问题