1. 起因, 目的:
- 重新安装 tensorflow gpu, 因为之前的项目都删掉了。遇到一点问题,记录一下。
- 来回折腾,本质是 我的 python3.11 版本太高了。换成 python3.9 就行了。
- 坚决不使用 AI 扩写。垃圾而恶心。
2. 先看效果
无。
3. 过程:
代码
import platform
import sys
import os
import subprocess
import shutildef 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 = Falsefor path in possible_paths:if os.path.exists(path):print(f"已检测到 CUDA Toolkit 安装路径: {path}")found = Truebreakif 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
系统架构: AMD64Python 版本: 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
- 繁琐是难免的。容易吗,不容易!
希望对大家有帮助。