numpy的版本必须是1.x,不能大于2,实测numpy 1.26.4可用,其也是最后一个1.x版本
TensorFlow 2 的CPU 和 GPU 软件包是一起的
以下是使用conda进行安装的演示
安装步骤分解
步骤1:创建名为tf_gpu专用虚拟环境
conda create -n tf_gpu python=3.10 -y
conda activate tf_gpu
步骤2:安装CUDA工具包和cuDNN库
conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0
步骤3:安装numpy 1.26.4
pip install numpy==1.26.4
步骤4:安装TensorFlow
python -m pip install "tensorflow<2.11"
确保numpy版本小于2,不然使用TensorFlow时会报错
验证安装
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
预期输出:
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
正文完