注:之前寫的那篇文章雖然安裝成功了,但用不了gpu,今天從新弄一下,讓它支持gpu
win10 anaconda 安裝 tensorflow-gpu 及 jupyter notebook - Tiac - 博客園 (cnblogs.com)
本文鏈接:win10 anaconda cuda11.1 安裝 tensorlfow-gpu 環境 - Tiac - 博客園 (cnblogs.com)
前期准備:
在安裝 tensorflow-gpu 之前,請確認你已經安裝好了 cuda 工具包及 cudann 補丁
CUDA:https://developer.nvidia.com/cuda-downloads
CUDANN:https://developer.nvidia.com/rdp/cudnn-download
注:需要注冊一個 英偉達的 開發者賬號
一、安裝 anaconda
https://www.anaconda.com/products/individual
注1:選擇適合自己的版本下載安裝即可
注2:為了不必要的麻煩,建議先卸載系統已安裝的python,然后使用anaconda默認環境的python做為系統默認的python
二、安裝 tensorflow-gpu
安裝好 anaconda 后,win+q 搜索 ana ,選擇打開 Anaconda Navigator
三、修改 anaconda 源
打開 C盤 > 用戶 > {用戶名},例如:C:\Users\Tiac
創建或修改 .condarc 文件並保存,內容參考 https://mirror.tuna.tsinghua.edu.cn/help/anaconda/
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 simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
四、創建 tensorflow-gpu 環境,並安裝 tensorflow-gpu
參考鏈接:TensorFlow — Anaconda documentation
官方教程里有幾種方法來安裝 tensorflow-gpu,我試了,只有安裝 nightly 版本的才比較正常(支持gpu)
conda create -n tf-n-gpu python conda activate tf-n-gpu pip install tf-nightly-gpu
五、驗證環境是否正常
python import tensorflow as tf tf.__version__ tf.config.experimental.list_physical_devices('GPU')
注:如圖所示,tensorflow已安裝正常,可以識別到電腦的gpu
六、安裝 jupyterlab
參考 jupyter 官方文檔,用 conda 命令安裝 jupyterlab
https://jupyter.org/install.html
conda install -c conda-forge jupyterlab
七、運行 jupyter-lab 及測試
本文鏈接:win10 anaconda cuda11.1 安裝 tensorlfow-gpu 環境 - Tiac - 博客園 (cnblogs.com)
完。