Install tensorflow and cuda in conda environment


The compiled whl files officially provided by different
The method I chose is to create a new environment in conda and install the required tensorflow and cudatoolkit in the environment.
It is assumed here that anaconda has been installed.

  1. Determine the python and cuda versions corresponding to the required tensorflow version.
    What I want to install here is tensorflow2.6. The following instructions are based on tensorflow2.6, python3.9, and cuda11.2.
    The corresponding relationship between tensorflow, python and cuda can be queried on the official website: ​​​​​​https://www.tensorflow.org/install/source?hl=zh-cn

  2. Create a new conda environment

conda create -n tf26 python=3.9

After the installation is complete, enter the newly created environment

conda activate tf26
  1. Install tensorflow in the environment
pip install tensorflow-gpu==2.6
  1. Install the corresponding version of cuda for tensorflow in the environment
conda install cudatoolkit=11.2 cudnn -c conda-forge
  1. Check if tensorflow can successfully use GPU
import tensorflow as tf
tf.config.list_physical_devices('GPU')

As shown in the figure below, tensorflow can successfully use the GPU
Insert image description here

Guess you like

Origin blog.csdn.net/icylling/article/details/131231768