[Share Experiences] deepin安装最新TensorFlow GPU版本的经验
Tofloor
poster avatar
q77190858
deepin
2023-04-11 23:23
Author

直接参考TensorFlow的英文教程,不要选中文,因为有内容没更新!!!

https://tensorflow.google.cn/install/pip

不需要使用apt安装cuda和cudnn,只要用apt装一个小包,其余全部用conda在虚拟环境装就行了

sudo apt install libcuda1
# 后面经过测试,pytorh可能会缺包,因此还是建议完全安装cudatoolkit
sudo apt install nvidia-cuda-toolkit

版本什么的也不用去英伟达官网查来查去了,直接用TensorFlow官方教程推荐的版本

  1. 安装anaconda或者miniconda,这里我用miniconda

    # conda 设置base环境不自动激活
    conda config --set auto_activate_base false
    
  2. pip改为国内豆瓣源,conda改为清华源

    mkdir ~/.pip
    vi .pip/pip.conf
    # 输入以下内容
    [global]
    index-url=http://pypi.douban.com/simple
    [install]
    trusted-host=pypi.douban.com
    vi ~/.condarc
    # 输入以下
    auto_activate_base: false
    channels:
      - defaults
    show_channel_urls: true
    default_channels:
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
    custom_channels:
      conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
    
    
  3. conda创建虚拟环境

    conda create -n tf2 python=3.11
    
  4. 激活进入虚拟环境

    conda activate tf2
    
  5. 在虚拟环境中执行

    conda install -c conda-forge cudatoolkit=11.8.0
    pip install nvidia-cudnn-cu11==8.6.0.163
    mkdir -p $CONDA_PREFIX/etc/conda/activate.d
    echo 'CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
    echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib/:$CUDNN_PATH/lib' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
    vi /media/juju/backup/miniconda3/envs/tf2/etc/conda/activate.d/env_vars.sh
    # 查看设置环境变量的指令已经写进去了,如下
    CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib/:$CUDNN_PATH/lib
    
  6. 重新进入虚拟环境,让环境变量生效

    conda deactivate
    conda activate tf2
    
  7. 在虚拟环境执行,安装TensorFlow2.12

    pip install --upgrade pip
    pip install tensorflow==2.12.*
    
  8. 测试验证一下,打印出GPU信息说明安装成功

    python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
    ......
    [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
    
Reply Favorite View the author
All Replies
ThinkYoung
deepin
2023-04-12 00:00
#1

kissing_heart

好厉害呀! 楼主用tf主要做什么研究呀?

Reply View the author
q77190858
deepin
2023-04-12 05:02
#2
ThinkYoung

kissing_heart

好厉害呀! 楼主用tf主要做什么研究呀?

哈哈,初学者刚开始学

Reply View the author
ThinkYoung
deepin
2023-04-12 06:05
#3
q77190858

哈哈,初学者刚开始学

期待楼主的后续教程!👍👍👍

Reply View the author
fuuko
deepin
2023-04-12 19:18
#4

我选择直接docker pullok

Reply View the author