深度学习(TensorFlow)环境搭建:(三)Ubuntu16.04+CUDA8.0+cuDNN7+Anaconda4.4+Python3.6+TensorFlow1.3
紧接着上一篇的文章《深度学习(TensorFlow)环境搭建:(二)Ubuntu16.04+1080Ti显卡驱动》,这篇文章,主要讲解如何安装CUDA+CUDNN,不过前提是我们是已经把NVIDIA显卡驱动安装好了
一、安装CUDA
CUDA(Compute Unified Device Architecture),是英伟达公司推出的一种基于新的并行编程模型和指令集架构的通用计算架构,它能利用英伟达GPU的并行计算引擎,比CPU更高效的解决许多复杂计算任务,想使用GPU就必须要使用CUDA。
1.1、下载CUDA
首先在官网(https://developer.nvidia.com/cuda-downloads)下载对应的CUDA,如图所示:
注意请务必下载runfile文件(后缀为.run),不能是其它文件。或者直接通过wget命令下载:
wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
如图所示:
1.2、安装CUDA(一定要按顺序执行)
下载完成后先执行安装相关依赖的命令,如果不先执行安装依赖包,后面安装CUDA会以下错误报错:
-------------------------------------------------------------
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?
(y)es/(n)o/(q)uit: n
Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda-8.0 ]:
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y
Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y
Enter CUDA Samples Location
[ default is /home/xxxxxxxx ]:
Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Missing recommended library: libGLU.so
Missing recommended library: libX11.so
Missing recommended library: libXi.so
Missing recommended library: libXmu.so
Installing the CUDA Samples in /home/xxxxxxxx ...
Copying samples to /home/xxxxxxxx/NVIDIA_CUDA-8.0_Samples now...
Finished copying samples.
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /home/xxxxxxxx, but missing recommended libraries
Please make sure that
- PATH includes /usr/local/cuda-8.0/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run -silent -driver
所有大家一定要安装顺序进行安装,先安装依赖的库文件。
(1)安装缺失的依赖库文件
命令如下:
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-devlibgl1-mesa-glx libglu1 #安装依赖库
(2)安装执行文件
sudo sh cuda_8.0.61_375.26_linux.run #执行安装文件
注意:安装过程中会提示你进行一些确认操作,首先是接受服务条款,输入accept确认,然后会提示是否安装cuda tookit、cuda-example等,均输入Y进行确定。但请注意,当询问是否安装附带的驱动时,一定要选N!
因为前面我们已经安装好最新的驱动NVIDIA381,附带的驱动是旧版本的而且会有问题,所以不要选择安装驱动。其余的都直接默认或者选择是即可。
(3)设置环境变量
- 输入命令,编辑环境变量配置文件
sudo vim ~/.bashrc
- 在文本末端追加以下两行代码(按键“i”进行编辑操作)
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda
- 保存退出(按“!wq”),执行下面命令,使环境变量立刻生效
#环境变量立即生效
sudo source ~/.bashrc
sudo ldconfig
如图所示:
(4)检查cuda是否配置正确
到这一步,基本的CUDA已经安装完成了,我们可以通过以下命令查看CUDA是否配置正确:
nvcc --version
如图所示:
(5)测试CUDA的sammples
为什么需要安装cuda samples?一方面为了后面学习cuda使用,另一方面,可以检验cuda是否真的安装成功。如果cuda samples全部编译通过,没有一个Error信息(Warning忽略),那么就说明成功地安装了cuda。如果最后一行虽然显示PASS,但是编译过程中有ERROR,请自行网上搜索相关错误信息解决之后。
# 切换到cuda-samples所在目录
cd /usr/local/cuda-8.0/samples 或者 cd /home/NVIDIA_CUDA-8.0_Samples
# 没有make,先安装命令 sudo apt-get install cmake,-j是最大限度的使用cpu编译,加快编译的速度
make –j
# 编译完毕,切换release目录(/usr/local/cuda-8.0/samples/bin/x86_64/linux/release完整目录)
cd ./bin/x86_64/linux/release
# 检验是否成功,运行实例
./deviceQuery
# 可以认真看看自行结果,它显示了你的NVIDIA显卡的相关信息,最后能看到Result = PASS就算成功。
如图所示:
输出结果看到显卡相关信息,并且最后Result = PASS ,这说明CUDA才真正完全安装成功了
二、安装cuDNN
2.1、下载cuDNN
cuDNN是GPU加速计算深层神经网络的库。首先去官网(https://developer.nvidia.com/rdp/cudnn-download)下载cuDNN,需要注册一个账号才能下载,没有的话自己注册一个。由于本人的显卡是GTX1080Ti,所以下载版本号如图所示,最新的版本是v7:
2.2、安装cuDNN
安装cudnn比较简单,简单地说,就是复制几个文件:库文件和头文件。将cudnn的头文件复制到cuda安装路径的include路径下,将cudnn的库文件复制到cuda安装路径的lib64路径下。具体操作如下
1 #解压文件 2 tar -zxvf cudnn-8.0-linux-x64-v7.tgz 3 4 #切换到刚刚解压出来的文件夹路径 5 cd cuda 6 #复制include里的头文件(记得转到include文件里执行下面命令) 7 sudo cp /include/cudnn.h /usr/local/cuda/include/ 8 9 #复制lib64下的lib文件到cuda安装路径下的lib64(记得转到lib64文件里执行下面命令) 10 sudo cp lib* /usr/local/cuda/lib64/ 11 12 #设置权限 13 sudo chmod a+r /usr/local/cuda/include/cudnn.h 14 sudo chmod a+r /usr/local/cuda/lib64/libcudnn* 15 16 #======更新软连接====== 17 cd /usr/local/cuda/lib64/ 18 sudo rm -rf libcudnn.so libcudnn.so.7 #删除原有动态文件,版本号注意变化,可在cudnn的lib64文件夹中查看 19 sudo ln -s libcudnn.so.7.0.2 libcudnn.so.7 #生成软衔接(注意这里要和自己下载的cudnn版本对应,可以在/usr/local/cuda/lib64下查看自己libcudnn的版本) 20 sudo ln -s libcudnn.so.7 libcudnn.so #生成软链接 21 sudo ldconfig -v #立刻生效
备注:上面的软连接的版本号要根据自己实际下载的cudnn的lib版本号
如图所示:
最后我们看看验证安装cudnn后cuda是否依旧可用
nvcc --version # or nvcc -V
2.3、检验cuDNN是否安装成功
到目前为止,cuDNN已经安装完了,但是,是否成功安装,我们可以通过cuDNN sample测试一下(https://developer.nvidia.com/rdp/cudnn-archive 页面中找到对应的cudnn版本,里面有 cuDNN v5 Code Samples,点击该链接下载即可,版本可能不一样,下载最新的就行)
下载完,转到解压出的目录下的mnistCUDNN,如图所示:
通过下面命令,进行校验
#运行cudnn-sample-v5 tar –zxvf cudnn-sample-v5.tgz #解压压缩包 cd mnistCUDNN #转到解压的mnistCUDNN目录下 make #make 命令下 ./mnistCUDNN #在mnistCUDNN目录下执行./mnistCUDNN #改程序运行成功,如果结果看到Test passed!说明cudnn安装成功。
如果结果看到Test passed!说明cudnn安装成功
至此、cuDNN已经成功安装了
三、安装Anaconda
Anaconda是python的一个科学计算发行版,内置了数百个python经常会使用的库,也包括许多做机器学习或数据挖掘的库,这些库很多是TensorFlow的依赖库。安装好Anaconda可以提供一个好的环境直接安装TensorFlow。
去Anaconda官网(https://www.anaconda.com/download/)下载需要版本的Anaconda
下载完后执行如下命令
sudo bash Anaconda3-4.4.0-Linux-x86_64.sh
如图所示:
安装anaconda,回车后,是许可文件,接收许可。直接回车即可。最后会询问是否把anaconda的bin添加到用户的环境变量中,选择yes。在终端输入python发现依然是系统自带的python版本,这是因为环境变量的更新还没有生效,命令行输入如下命令是安装的anaconda生效。如果conda --version没有找到任何信息,说明没有加入到环境变量没有,需要手动加入,如图所示:
刷新环境变量
source /etc/profile 或者 source ~/.bashrc #(全局的环境变量)
三、安装TensorFlow
大家可以参考TensorFlow的官方安装教程(https://www.tensorflow.org/install/),官网提供的了 Pip, Docker, Virtualenv, Anaconda 或 源码编译的方法安装 TensorFlow,我们这里主要介绍以Anaconda安装。其他安装方式,大家可以到官方安装教程查看。
3.1安装TensorFlow
通过Anaconda安装TensorFlow CPU,TensorFlow 的官方下载源现在已经在GitHub上提供了(https://github.com/tensorflow/tensorflow),找到对应的版本号,如图所示:
(1)、创建一个名为tensorflow的conda环境Python 3.6
#Python 2.7 conda create -n tensorflow python=2.7 #Python 3.4 conda create -n tensorflow python=3.4 #Python 3.5 conda create -n tensorflow python=3.5
#Python 3.6 conda create -n tensorflow python=3.6 #我下的TensorFlow对应的Python是3.6版本,那么我就使用这行
备注:(根据TensorFlow版本号,一定要设置Python版本号,切记切记切记!!!!!重要的事情说三遍!否则后面会报各种错的)
(2)、激活 conda 环境
source activate tensorflow
(3)、TensorFlow 各个版本(最新的貌似是1.3的版本了)
然后根据要安装的不同tensorflow版本选择对应的一条下载链接(操作系统,Python版本,CPU版本还是CPU+GPU版本),官方文档都有相关信息。
Python 2.7 CPU: https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp27-none-linux_x86_64.whl GPU: https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp27-none-linux_x86_64.whl ===============================================================================================
Python 3.4 CPU: https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp34-cp34m-linux_x86_64.whl GPU: https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp34-cp34m-linux_x86_64.whl ===============================================================================================
Python 3.5 CPU: https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp35-cp35m-linux_x86_64.whl GP: https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp35-cp35m-linux_x86_64.whl ===============================================================================================
Python 3.6 CPU: https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp36-cp36m-linux_x86_64.whl GPU: https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl
(4)、在conda环境中安装TensorFlow GPU版(本文主要以安装GPU版讲解)
因为我们前面选择了conda环境为Python3.6的,所以我们选择Python3.6版本的GPU链接地址,进行安装
#如何进行安装,我们这里安装Python版本为3.6的TensorFlow sudo pip3 install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl 备注:连接里的cpxx和cpxxm的xx是对应Python的版本号
错误归纳-重点关注!!!:
安装whl包的时候出现“tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl is not a supported wheel on this platform”的问题。我们需要下载GPU版的安装包,在安装包下载之后,然后手动进入环境,安装TensorFlow。
具体操作如下(因为我碰到这样问题,只能用下面这种方式安装了):
source activate tensorflow #激活tensorflow环境(这步操作了,就忽略) cd /Downloads #切换到whl文件所在文件夹 pip install --ignore-installed --upgrade tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl #切记,不要用sudo pip,也不要用pip3,然后--ignore-installed --upgrade等参数也不能省略,否则会出错。
如图所示,TensorFlow安装成功了:
完整日志:
xxxxxxxx@xxxxxxxx:~$ conda create -n tensorflow python=3.6 Fetching package metadata ......... Solving package specifications: . Package plan for installation in environment /home/xxxxxxxx/.conda/envs/tensorflow: The following NEW packages will be INSTALLED: certifi: 2016.2.28-py36_0 openssl: 1.0.2l-0 pip: 9.0.1-py36_1 python: 3.6.2-0 readline: 6.2-2 setuptools: 36.4.0-py36_1 sqlite: 3.13.0-0 tk: 8.5.18-0 wheel: 0.29.0-py36_0 xz: 5.2.3-0 zlib: 1.2.11-0 Proceed ([y]/n)? y # # To activate this environment, use: # > source activate tensorflow # # To deactivate this environment, use: # > source deactivate tensorflow # xxxxxxxx@xxxxxxxx:~$ source activate tensorflow (tensorflow) xxxxxxxx@xxxxxxxx:~$ wget https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl --2017-09-26 10:06:45-- https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl Resolving storage.googleapis.com (storage.googleapis.com)... 216.58.200.48, 2404:6800:4008:801::2010 Connecting to storage.googleapis.com (storage.googleapis.com)|216.58.200.48|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 159078494 (152M) [application/octet-stream] Saving to: ‘tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl.1’ tensorflow_gpu-1.3. 100%[===================>] 151.71M 2.99MB/s in 52s 2017-09-26 10:07:38 (2.89 MB/s) - ‘tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl.1’ saved [159078494/159078494] (tensorflow) xxxxxxxx@xxxxxxxx:~$ pip install --ignore-installed --upgrade tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl Processing ./tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl Collecting six>=1.10.0 (from tensorflow-gpu==1.3.0) Using cached six-1.11.0-py2.py3-none-any.whl Collecting tensorflow-tensorboard<0.2.0,>=0.1.0 (from tensorflow-gpu==1.3.0) Downloading tensorflow_tensorboard-0.1.6-py3-none-any.whl (2.2MB) 100% |████████████████████████████████| 2.2MB 345kB/s Collecting numpy>=1.11.0 (from tensorflow-gpu==1.3.0) Downloading numpy-1.13.1-cp36-cp36m-manylinux1_x86_64.whl (17.0MB) 100% |████████████████████████████████| 17.0MB 93kB/s Collecting protobuf>=3.3.0 (from tensorflow-gpu==1.3.0) Downloading protobuf-3.4.0-cp36-cp36m-manylinux1_x86_64.whl (6.2MB) 100% |████████████████████████████████| 6.2MB 203kB/s Collecting wheel>=0.26 (from tensorflow-gpu==1.3.0) Using cached wheel-0.30.0-py2.py3-none-any.whl Collecting bleach==1.5.0 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow-gpu==1.3.0) Downloading bleach-1.5.0-py2.py3-none-any.whl Collecting markdown>=2.6.8 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow-gpu==1.3.0) Downloading Markdown-2.6.9.tar.gz (271kB) 100% |████████████████████████████████| 276kB 834kB/s Collecting werkzeug>=0.11.10 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow-gpu==1.3.0) Downloading Werkzeug-0.12.2-py2.py3-none-any.whl (312kB) 100% |████████████████████████████████| 317kB 985kB/s Collecting html5lib==0.9999999 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow-gpu==1.3.0) Downloading html5lib-0.9999999.tar.gz (889kB) 100% |████████████████████████████████| 890kB 673kB/s Collecting setuptools (from protobuf>=3.3.0->tensorflow-gpu==1.3.0) Using cached setuptools-36.5.0-py2.py3-none-any.whl Building wheels for collected packages: markdown, html5lib Running setup.py bdist_wheel for markdown ... done Stored in directory: /home/xxxxxxxx/.cache/pip/wheels/bf/46/10/c93e17ae86ae3b3a919c7b39dad3b5ccf09aeb066419e5c1e5 Running setup.py bdist_wheel for html5lib ... done Stored in directory: /home/xxxxxxxx/.cache/pip/wheels/6f/85/6c/56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962 Successfully built markdown html5lib Installing collected packages: six, html5lib, bleach, markdown, numpy, werkzeug, setuptools, protobuf, wheel, tensorflow-tensorboard, tensorflow-gpu Successfully installed bleach-1.5.0 html5lib-0.9999999 markdown-2.6.9 numpy-1.13.1 protobuf-3.4.0 setuptools-36.5.0 six-1.11.0 tensorflow-gpu-1.3.0 tensorflow-tensorboard-0.1.6 werkzeug-0.12.2 wheel-0.30.0
(5)、在conda环境中安装TensorFlow CPU版
因为我们前面选择了conda环境为Python3.6的,所以我们选择Python3.6版本的CPU链接地址,进行安装
#如何进行安装,我们这里安装Python版本为3.6的TensorFlow sudo pip3 install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp36-cp36m-linux_x86_64.whl
备注:连接里的cpxx和cpxxm的xx是对应Python的版本号
错误归纳:
安装whl包的时候出现“tensorflow-1.3.0-cp36-cp36m-linux_x86_64.whl is not a supported wheel on this platform”的问题,和上面安装GPU一样的错误。我们需要下载CPU版的安装包,在安装包下载之后,注意!!!这个时候我们需要将whl文件重命名为tensorflow-1.3.0-py3-none-linux_x86_64.whl,然后手动进入环境,安装TensorFlow。
具体操作如下:
source activate tensorflow #激活tensorflow环境(这步操作了,就忽略) cd /Downloads #切换到whl文件所在文件夹 pip install --ignore-installed --upgrade tensorflow-1.3.0-py3-none-linux_x86_64.whl #切记,不要用sudo pip,也不要用pip3,然后--ignore-installed --upgrade等参数也不能省略,否则会出错。
其他的和GPU安装是一样的,具体不做讲解。
(6)、当你不用 TensorFlow 的时候,关闭环境
source deactivate tensorflow
(7)、安装成功后,每次使用 TensorFlow 的时候需要激活 conda 环境(操作步骤2就可以了)
3.2、常见问题以及错误
问题一、如果安装后,运行实例提示ModuleNotFoundError: No module named ‘tensorflow’的话
import tensorflow as tf
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘tensorflow’
解决办法:下载的TensorFlow对应的Python版本一定要和conda create -n tensorflow python=x.x的版本一样才行,所以TensorFlow版本有时候太高反而不好,低版本兼容性更好,这个看个人意愿。
问题二、出现“ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory”错误信息
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf Traceback (most recent call last): File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/imp.py", line 342, in load_dynamic return _load(spec) ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module> from tensorflow.python import * File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module> from tensorflow.python import pywrap_tensorflow File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module> raise ImportError(msg) ImportError: Traceback (most recent call last): File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "/home/xxxxxxxx/.conda/envs/tensorflow/lib/python3.6/imp.py", line 342, in load_dynamic return _load(spec) ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory
这些都是有套路的,解决方法:
- 首先检查是否存在libcundnn.so.*
find / -name libcudnn.so.*
找到文件就下一步,没找到,检查下cudnn的依赖库,就是前面的环境变量做对了没
- 建立硬连接
sudo ln -s <path>libcudnn.so.7.* <path>libcudnn.so.6 #path就是libcudnn.so.7的所在目录
或者
sudo ln -s libcudnn.so.7.* libcudnn.so.6 #cd 到 libcudnn.so.7的所在目录
这个应该是没有问题
问题三、出现“CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.continuum.io/pkgs/main/linux-64/repodata.json.bz2>
Elapsed: -”错误信息
完整错误信息
ubutu@ubutu-All-Series:~$ conda create -n tensorflow python=3.6 Solving environment: failed CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.continuum.io/pkgs/main/linux-64/repodata.json.bz2> Elapsed: - An HTTP error occurred when trying to retrieve this URL. HTTP errors are often intermittent, and a simple retry will get you on your way. ProxyError(MaxRetryError("HTTPSConnectionPool(host='repo.continuum.io', port=443): Max retries exceeded with url: /pkgs/main/linux-64/repodata.json.bz2 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f7f87046828>: Failed to establish a new connection: [Errno 111] Connection refused',)))",),)
解决办法:检查你是不是开启了(喂~~皮~~N),这种问题很少出现,出现这个问题挺一头雾水的,我们只要关闭就可以了~
3.3、卸载TensorFlow
如果我们需要卸载TensorFlow的话,使用下面命令
sudo pip uninstall tensorflow #Python2.7
sudo pip3 uninstall tensorflow #Python3.x
3.4、测试TensorFlow
在python的环境中,运行简单的TensorFlow程序测试(官方demo)
>>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> sess.run(hello) 'Hello, TensorFlow!' >>> a = tf.constant(10) >>> b = tf.constant(32) >>> sess.run(a + b) 42 >>> sess.close()
运行如图所示:
至此,TensorFlow安装成功,过程充满了艰辛..(。•ˇ‸ˇ•。)…所以大家安装的时候每一步都至关重要~
PS:如有疑问,请留言,未经允许,不得私自转载,转载请注明出处:http://www.cnblogs.com/xuliangxing/p/7575586.html