1)安装CUDA
1.下载cuda10.0.13 deb包
2.安装cuda
sudo dpkg -i cuda-repo-ubuntu1804-10-0-local-10.0.130-410.48_1.0-1_amd64.deb
sudo apt-key add /var/cuda-repo-10-0-local-10.0.130-410.48/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda
3.创建环境变量
sudo gedit ~/.bashrc
export CUDA_HOME=/usr/local/cuda-10.0
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH
export PATH=/usr/local/cuda-10.0/bin:$PATH
source ~/.bashrc
4.测试是否安装成功
1)nvcc -V 后可以看到cuda的版本号
2)
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
输入命令后可以看到Result = PASS
表示cuda安装成功
2)安装CUDNN
1.进入cudnn安装文件夹
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn.so.7.4.1
2.查看版本
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
版本查看完为7.4.1即可
3)安装anaconda
1.官网下载Anaconda3-5.2.0-Linux-x86_64.sh
bash Anaconda3-5.2.0-Linux-x86_64.sh
然后全程一直yes即可
安装完之后执行:
source ~/.bashrc
检查是否安装成功
终端执行:conda list
若提示命令无法找到,则修改.profile文件:
sudo gedit ~/.profile
添加以下几行:
if [ -d "$HOME/anaconda3/bin" ] ; then
PATH="$HOME/anaconda3/bin:$PATH"
fi
2.创建虚拟环境
conda create -n tensorflow python=3.6
激活虚拟环境后在该环境下安装tensorflow
source activate tensorflow
4)安装tensorflow
1.首先准备好tensorflow.whl文件
pip install tensorflow_gpu-1.13.1-cp36-cp36m-manylinux1_x86_64.whl
2.安装完以后如果出现
ImportError: libcudnn.so.7: cannot open shared object file: No such file or directory
采取如下操作
cd /usr/local/cuda/lib64
sudo rm -rf libcudnn.so libcudnn.so.7 #删除原有版本号,版本号在cudnn/lib64中查询
sudo ln -s libcudnn.so.7.4.1 libcudnn.so.7 #生成软连接,注意自己下载的版本号
sudo ln -s libcudnn.so.7 libcudnn.so
sudo ldconfig
#立即生效
3.查看tensorflow版本
终端下输入python
tf.__version__
4.测试tensorflow是否安装好
import tensorflow as tf
sess = tf.Session()
a = tf.constant(1)
b = tf.constant(2)
print(sess.run(a+b))
能输出结果3
5)安装pycharm
1.解压后sh pycharm.sh 即可
2.配置pycharm的开发环境
打开pycharm,新建一个project,在File->setting->project->project interpreter
选择conda环境
3.制作pycharm快捷方式
sudo gedit /usr/share/applications/Pycharm.desktop
写入
[Desktop Entry]
Type=Application
Name=Pycharm
GenericName=Pycharm3
Comment=Pycharm3:The Python IDE
Exec=sh /home/xyfang/software/pycharm-community-2019.1.1/bin/pycharm.sh
Icon=/home/xyfang/software/pycharm-community-2019.1.1/bin/pycharm.png
Terminal=pycharm
Categories=Pycharm;