linux從零開始安裝nvidia驅動和tensorflow
阿新 • • 發佈:2019-01-09
安裝nvidia驅動和CUDA
- 下載驅動和CUDA安裝包,在官網下載對應版本就行
- sudo apt-get install linux-headers-$(uname -r) 或者 linux-headers-generic.否則直接安裝會報錯 kernel not found
- 安裝 nvidia 驅動,一路accept和yes
- 安裝 CUDA,一路yes。安裝路徑:/usr/local/cuda-8.0/。是否安裝推薦的驅動, no
最後顯示類似下面Summary內容,表示安裝成功。 - 在/etc/profile中新增:
export PATH=/usr/local/cuda-8.0/lib64:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
儲存後
# source /etc/profile
# nvcc -V 檢查CUDA
# apt-get install cmake 安裝cmake
# cd /usr/local/cuda-8.0/samples
# make 測試CUDA
測試時間較長,一段沒有error即可中止
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /storage/installers/cuda_samples, 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
Logfile is /tmp/cuda_install_16018.log
安裝CUDNN
- 下載cudnn-8.0-linux-x64-v5.1.tgz
- tar -xvzf cudnn-8.0-linux-x64-v5.1.tgz 解壓完會有一個cuda資料夾
# cd cuda
# cp include/cudnn.h
/usr/local/cuda/include
# cp lib64/libcudnn.* /usr/local/cuda/lib64
cuDNN安裝完成!
有的部落格說要建立軟連結,但是我沒有做,步驟如下:
# cd /usr/local/cuda/lib64
# rm -rf libcudnn.so libcudnn.so.5
# ln -s libcudnn.5.1.3 libcudnn.so.5
# ln -s libcudnn.so.5 libcudnn.so
首先安裝anaconda, 因為很多python庫都包含在裡面了,一次性安裝很方便
安裝anaconda
- 從官網下載最新的anaconda安裝包,我下的是Anaconda2-4.2.0
- bash Anaconda2-4.2.0-Linux-x86_64.sh
- PREFIX=/usr/share/anaconda2
- # vim /etc/profile (新增環境變數)
export PATH=$PATH:/usr/share/anaconda2/bin
再source /etc/profile生效
修改映象檔案,使得系統預設python為anaconda中的python
# mv /usr/bin/python /usr/bin/python_bk
# ln -s /usr/share/anaconda2/bin/python /usr/bin/python
安裝h5py
conda install h5py #注意必須先安裝anaconda2
這時會提示升級anaconda,yes即可
安裝tensorflow
ln -s /usr/anaconda2/bin/pip /usr/bin/pip 建立軟連線
github下載 tensorflow_gpu-0.12.0rc0-cp27-none-linux-x86_64.whl
pip install tensorflow_gpu-0.12.0rc0-cp27-none-linux-x86_64.whl
安裝完成。測試:
python && import tensorflow 測試tensorflow
或者:
# cd /usr/share/anaconda2/lib/python2.7/site-packages/tensorflow/models/image/mnist
# CUDA_VISIBLE_DEVICES = 0(選擇顯示卡) python convolutional.py
開頭出現以下字樣表示安裝成功:
Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (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:128] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally