python310 安装 tensorflow-gpu2.10

python310 安装 tensorflow-gpu2.10

工具 miniconda

环境准备

  1. 升级依赖库

    bash 复制代码
    conda update --all
  2. 创建目录

    bash 复制代码
    mkdir gpu-tf
  3. 进入目录

    bash 复制代码
    cd gpu-tf
  4. 创建虚拟环境

    bash 复制代码
    conda create -p tf210-310 python==3.10.16
  5. 激活虚拟环境

    bash 复制代码
    conda activate D:\gpu-tf\tf210-310
  6. 重新安装pip

    bash 复制代码
    python -m pip uninstall pip
    python -m ensurepip --upgrade
  7. 升级 setuptools wheel

    bash 复制代码
    python -m pip install --upgrade pip setuptools wheel

安装cudacudnn

bash 复制代码
conda install cudatoolkit==11.3.1 cudnn==8.2.1

安装 numpy

解决版本兼容

bash 复制代码
pip install numpy==1.26.4

安装 tensorflow-gpu

bash 复制代码
pip install tensorflow-gpu==2.10.1

测试

  1. 控制台输入 python 进入 python 环境后输入以下内容:

    python 复制代码
    import tensorflow as tf
    
    # 打印TensorFlow版本信息
    print("TensorFlow version:", tf.__version__)
    
    # 检查GPU是否可用
    print("GPU is available:", end='\t' )
    print(tf.config.list_physical_devices('GPU'))
  2. 编写 python 文件,代码如下:

    python 复制代码
    import tensorflow as tf
    
    # 打印TensorFlow版本信息
    print("TensorFlow version:", tf.__version__)
    
    # 检查GPU是否可用
    if tf.config.list_physical_devices('GPU'):
        print("GPU is available")
    else:
        print("GPU is not available")
    
    # 使用tf.function装饰器自动将操作分配到GPU(如果可用)
    @tf.function
    def test_gpu():
        a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
        b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
        c = tf.matmul(a, b)
        return c
    
    # 调用函数并打印结果
    result = test_gpu()
    print(result)
  3. 运行刚刚编写的 python 文件,输入内容如下:

相关推荐
MediaTea5 分钟前
AI 术语通俗词典:C4.5 算法
人工智能·算法
callJJ23 分钟前
Spring Data Redis 两种编程模型详解:同步 vs 响应式
java·spring boot·redis·python·spring
小郑加油26 分钟前
python学习Day12:pandas安装与实际运用
开发语言·python·学习
AC赳赳老秦27 分钟前
投标合规提效:用 OpenClaw 实现标书 / 合同自动审核、关键词校验、格式优化,降低废标风险
开发语言·前端·python·eclipse·emacs·deepseek·openclaw
海兰31 分钟前
【第27篇】Micrometer + Zipkin
人工智能·spring boot·alibaba·spring ai
.柒宇.34 分钟前
AI掘金头条项目-K8s部署实战教程
python·云原生·容器·kubernetes·fastapi
DeepReinforce1 小时前
四、AI量化投资:使用akshare获取A股主板20260430筛选后的涨停股票
人工智能
qcx231 小时前
【AI Agent通识九课】02 · Agent 的“思考回路“长啥样?
人工智能·ai·llm·agent
观北海1 小时前
从 Sim2Sim 到 Sim2Real:以 ONNX 为核心的机器人策略实机落地全指南
python·机器人
FL16238631291 小时前
电力设备红外图像与可见光图像配准数据集227对共454张无标注
深度学习