安装 tensorflow-2.10.0 支持 gpu

1. 起因, 目的:

  • 重新安装 tensorflow gpu, 因为之前的项目都删掉了。遇到一点问题,记录一下。
  • 来回折腾,本质是 我的 python3.11 版本太高了。换成 python3.9 就行了。
  • 坚决不使用 AI 扩写。垃圾而恶心。

2. 先看效果

无。

3. 过程:

代码
import platform
import sys
import os
import subprocess
import shutil


def check_os():
    os_type = platform.system()
    arch = platform.machine()
    print(f"操作系统: {os_type}")
    print(f"系统架构: {arch}")


def check_python():
    print(f"Python 版本: {platform.python_version()}")
    print(f"Python 位数: {platform.architecture()[0]}")


def check_cuda_toolkit():
    possible_paths = [
        "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA",
        "/usr/local/cuda",
    ]
    found = False
    for path in possible_paths:
        if os.path.exists(path):
            print(f"已检测到 CUDA Toolkit 安装路径: {path}")
            found = True
            break
    if not found:
        print("未检测到 CUDA Toolkit 安装路径")


def check_nvidia_smi():
    try:
        result = subprocess.run(["nvidia-smi"], capture_output=True, text=True)
        if result.returncode == 0:
            print("✅ 已检测到 NVIDIA GPU:")
            print(result.stdout.split("\n")[0])  # 打印首行信息
        else:
            print("⚠️ 未检测到 NVIDIA GPU 或未安装驱动")
    except FileNotFoundError:
        print("⚠️ 未安装 NVIDIA 驱动(nvidia-smi 命令不可用)")


def main():
    print("=== 系统信息检测 ===")
    check_os()
    print()
    check_python()
    print()
    check_cuda_toolkit()
    print()
    check_nvidia_smi()
    print("====================")


if __name__ == "__main__":
    main()

"""
输出:

=== 系统信息检测 ===
操作系统: Windows
系统架构: AMD64

Python 版本: 3.11.1
Python 位数: 64bit

已检测到 CUDA Toolkit 安装路径: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA

✅ 已检测到 NVIDIA GPU:
Fri May 23 05:02:23 2025       
====================


而且:

(venv) C:\Users\Administrator\Code\python_nlp>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver                  
Copyright (c) 2005-2022 NVIDIA Corporation             
Built on Tue_Mar__8_18:36:24_Pacific_Standard_Time_2022
Cuda compilation tools, release 11.6, V11.6.124        
Build cuda_11.6.r11.6/compiler.31057947_0              

(venv) C:\Users\Administrator\Code\python_nlp>         

(venv) C:\Users\Administrator\Code\python_nlp>nvidia-smi
Fri May 23 05:07:25 2025                                                                   
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 572.70                 Driver Version: 572.70         CUDA Version: 12.8     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                  Driver-Model | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A            2300    C+G   ...ram Files\Tencent\QQNT\QQ.exe      N/A      |
|    0   N/A  N/A            8288    C+G   ...h_cw5n1h2txyewy\SearchApp.exe      N/A      |
|    0   N/A  N/A            9224    C+G   ...xyewy\ShellExperienceHost.exe      N/A      |
|    0   N/A  N/A           10644    C+G   C:\Windows\explorer.exe               N/A      |
|    0   N/A  N/A           11168    C+G   ...1.1.1\jbr\bin\jcef_helper.exe      N/A      |
|    0   N/A  N/A           12428    C+G   ...5n1h2txyewy\TextInputHost.exe      N/A      |
|    0   N/A  N/A           13452    C+G   ...Chrome\Application\chrome.exe      N/A      |
|    0   N/A  N/A           14156    C+G   ...acted\runtime\WeChatAppEx.exe      N/A      |
|    0   N/A  N/A           14396    C+G   ...Chrome\Application\chrome.exe      N/A      |
|    0   N/A  N/A           16664    C+G   ....0.3240.76\msedgewebview2.exe      N/A      |
+-----------------------------------------------------------------------------------------+

(venv) C:\Users\Administrator\Code\python_nlp>
(venv) C:\Users\Administrator\Code\python_nlp>



请根据我的系统信息,帮我配置 tensorflow gpu , 如何安装,请给出具体步骤。

# 我的 python3.11, 版本太高了, 不行。换成 python3.9 可以的!
pip install tensorflow==2.10.0 -i https://pypi.org/simple

"""


4. 结论 + todo

  • 繁琐是难免的。容易吗,不容易!

希望对大家有帮助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

waterHBO

老哥,支持一下啊

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值