1. 安装anaconda/miniconda
pip install anaconda/miniconda
2. 创建环境
conda create -n [envs_name]
3. 安装tensorflow(cuda+cudnn会被捆绑安装)
3.1 激活环境
source activate [envs_name]
3.2 在该环境下安装tensorflow-gpu版本
conda install tensorflow-gpu
4. 测试tensorflow
进入python环境: $ python
加载tensorflow:
>> import tensorflow as tf
>> hello = tf.constant('hello,world!')
>> sess = tf.Session()
>> print(sess.run(hello))
打印输出b'hello,world!',则表示成功。
注意:
如出现
ImportError: libnvidia-fatbinaryloader.so.375.51: cannot open shared object file: No such file or directory Failed to load the native TensorFlow runtime.
则可以通过下面两种方式设置环境变量解决
第一种,临时修改环境变量
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib:/usr/local/cuda/lib64:/usr/lib/x86_64-linux-gnu:/usr/lib/nvidia-375 export LIBRARY_PATH=${LIBRARY_PATH}:/usr/local/cuda/lib64:/usr/lib/x86_64-linux-gnu:/usr/lib/nvidia-375
第二种,永久修改,每次打开终端都会被读取
打开~/.bashrc文件,将下面两行写入并保存
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib:/usr/local/cuda/lib64:/usr/lib/x86_64-linux-gnu:/usr/lib/nvidia-375 export LIBRARY_PATH=${LIBRARY_PATH}:/usr/local/cuda/lib64:/usr/lib/x86_64-linux-gnu:/usr/lib/nvidia-375
参考: https://github.com/tensorflow/tensorflow/issues/9071
原文链接:https://www.f2er.com/ubuntu/350868.html