Linux安装Anaconda和cuda、cdnn和Tensorflow-gpu


总结

网址: http://blog.csdn.net/wolframalpha
作者: 李毅

全部看完在敲命令。先安装

Anaconda,在安装cuda和

cudnn,最后是tensorflow
安装tensorflow根据官网:
https://www.tensorflow.org/install/install_linux#installing_with_anaconda

上不了的同学可以到 :
http://blog.csdn.net/wolframalpha/article/details/79096840
我已经把他复制下来了

给出的安装方法,共有5种安装方法。
  • virtualenv
  • "native" pip
  • Docker
  • Anaconda
  • installing from sources, which is documented in a separate guide.
在这里, 选择 Anaconda安装

tensorflow有cpu版本和gpu版本,首先确定安装的版本。
You must choose one of the following types of TensorFlow to install:
  • TensorFlow with CPU support only. If your system does not have a NVIDIA® GPU, you must install this version. Note that this version of TensorFlow is typically much easier to install (typically, in 5 or 10 minutes), so even if you have an NVIDIA GPU, we recommend installing this version first.
  • TensorFlow with GPU support. TensorFlow programs typically run significantly faster on a GPU than on a CPU. Therefore, if your system has a NVIDIA® GPU meeting the prerequisites shown below and you need to run performance-critical applications, you should ultimately install this version.



NVIDIA requirements to run TensorFlow with GPU support
If you are installing TensorFlow with GPU support using one of the mechanisms described in this guide, then the following NVIDIA software must be installed on your system:
  • CUDA® Toolkit 8.0. For details, see NVIDIA's documentation. Ensure that you append the relevant Cuda pathnames to the LD_LIBRARY_PATH environment variable as described in the NVIDIA documentation.
  • The NVIDIA drivers associated with CUDA Toolkit 8.0.
  • cuDNN v6.0. For details, see NVIDIA's documentation. Ensure that you create the CUDA_HOME environment variable as described in the NVIDIA documentation.
  • GPU card with CUDA Compute Capability 3.0 or higher. See NVIDIA documentation for a list of supported GPU cards.
  • The libcupti-dev library, which is the NVIDIA CUDA Profile Tools Interface. This library provides advanced profiling support. To install this library, issue the following command:sudo apt-get install libcupti-dev(查资料此命令针对ubuntu的,其他Linux系统不用执行此命令)

If you have an earlier version of the preceding packages, please upgrade to the specified versions. If upgrading is not possible, then you may still run TensorFlow with GPU support, but only if you do the following:
  • Install TensorFlow from sources as documented in Installing TensorFlow from Sources.
  • Install or upgrade to at least the following NVIDIA versions:
    • CUDA toolkit 7.0 or greater
    • cuDNN v3 or greater
    • GPU card with CUDA Compute Capability 3.0 or higher.

知道了大概的步骤,接下来开始安装。 利用Anaconda安装(教程多)
第一步:安装Anaconda
最好根官网来( https://docs.anaconda.com/anaconda/install/linux

上不了官网的同学可以到:
http://blog.csdn.net/wolframalpha/article/details/79096950

1.下载Anaconda(.sh文件)
2.执行下面命令
    
bash  Anaconda3 - 5.0 . 1 - Linux - x86_64 . sh

3.最后出现下面的字样
Do you wish the installer to prepend the Anaconda<2 or 3> install location to PATH in your /home//.bashrc ?” 
输入yes.
否则自己添加环境变量。

第二步:安装cuda
官网: http://docs.nvidia.com/cuda/cuda-installation-guide-linux/#cross-installation
上不了官网的同学可以到这下载:
 http://download.csdn.net/my/uploads

1.首先是各种检查,看你服务器是否支持gpu
2.安装
Run the installer and follow the on-screen prompts:
$ sudo sh cuda__linux.run
The installer will prompt for the following:
  1. EULA Acceptance
  2. CUDA Driver installation
  3. CUDA Toolkit installation, location, and /usr/local/cuda symbolic link
  4. CUDA Samples installation and location
The default installation locations for the toolkit and samples are:

Component
Default Installation Directory
CUDA Toolkit
usr/local/cuda-9.1
CUDA Samples
$(HOME)/NVIDIA_CUDA-9.1_Samples


The /usr/local/cuda symbolic link points to the location where the CUDA Toolkit was installed. This link allows projects to use the latest CUDA Toolkit without any configuration file update.
The installer must be executed with sufficient privileges to perform some actions. When the current privileges are insufficient to perform an action, the installer will ask for the user's password to attempt to install with root privileges. Actions that cause the installer to attempt to install with root privileges are:
  1. installing the CUDA Driver
  2. installing the CUDA Toolkit to a location the user does not have permission to write to
  3. installing the CUDA Samples to a location the user does not have permission to write to
  4. creating the /usr/local/cuda symbolic link
Running the installer with sudo, as shown above, will give permission to install to directories that require root permissions. Directories and files created while running the installer with sudo will have root ownership.
If installing the driver, the installer will also ask if the openGL libraries should be installed. If the GPU used for display is not an NVIDIA GPU, the NVIDIA openGL libraries should not be installed. Otherwise, the openGL libraries used by the graphics driver of the non-NVIDIA GPU will be overwritten and the GUI will not work. If performing a silent installation, the --no-opengl-libs option should be used to prevent the openGL libraries from being installed. See the Advanced Options section for more details.
If the GPU used for display is an NVIDIA GPU, the X server configuration file, /etc/X11/xorg.conf, may need to be modified. In some cases, nvidia-xconfig can be used to automatically generate a xorg.conf file that works for the system. For non-standard systems, such as those with more than one GPU, it is recommended to manually edit the xorg.conf file. Consult the xorg.conf documentation for more information.
Note: Installing Mesa may overwrite the /usr/lib/libGL.so that was previously installed by the NVIDIA driver, so a reinstallation of the NVIDIA driver might be required after installing these libraries.
Reboot the system to reload the graphical interface.
Verify the device nodes are created properly.
Perform the post-installation actions.

3.禁用 Nouveau
要安装显示驱动程序,必须先禁用Nouveau驱动程序。 Linux的每个发行版都有不同的禁用Nouveau的方法。
    如果输入一下命令将会打印内容,也就是加载Nouveau驱动程序:
lsmod | grep nouveau

创建一个文件   /usr/lib/modprobe.d/blacklist-nouveau.conf  并输入 以下内容:
blacklist nouveau
options nouveau modeset=0
然后输入:
sudo /sbin/mkinitrd

3.添加环境变量
The PATH variable needs to include /usr/local/cuda-9.1/bin
To add this path to the PATH variable:

$ export PATH=/usr/local/cuda-9.1/bin${PATH:+:${PATH}}

In addition, when using the runfile installation method, the LD_LIBRARY_PATH variable needs to contain /usr/local/cuda-9.1/lib64 on a 64-bit system,  To change the environment variables for 64-bit operating systems:

$ export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64\
                         ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}

最后得source 一下。
source .bashrc

note:
安装过程中发现貌似又一次安装了显卡驱动,安装完毕后运行“nvidia-smi”提示错误:Failed to initialize NVML: Driver/library version mismatch,这个时候是需要重启机器让新的版本的显卡驱动生效,再次运行“nvidia-smi”:

4.安装cudnn

tar -zxvf cudnn-9.0-linux-x64-v7.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/ -d
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

第三部:安装tensorflow
1. Create a conda environment named tensorflow to run a version of Python by invoking the following command:
conda create -n tensorflow python=2.7 # or python=3.3, etc.
2. Activate the conda environment by issui ng the following command:
  source activate tensorflow
(tensorflow)$ # Your prompt should change
3.输入以下命令

conda install -c conda-forge tensorflow


上面的步骤完成后,从conda环境中退出:
source deactivate
在这里好像得先退出再进去,也就是先source deactivat再 source activate tensorflow

4.测试安装
source activate tensorflow 

 Enter the following short program inside the python interactive shell:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))



由于tensorflow给的pip方法连接失败,也试过pip install tensorflow-gpu ,虽然可以安装成功,但是运行时有错误。只有使用conda install -c conda-forge tensorflow命令安装成功











你可能感兴趣的:(DeepLearning,linux,Anaconda,tensorflow,Cuda)