使用pip3安装PyTorch和PyG

使用python3的pip3命令安装python依赖库。

shell 复制代码
# python3 -V
Python 3.12.3
# 
# pip3 -V 
pip 25.0.1 from /root/.pyenv/versions/3.12.3/lib/python3.12/site-packages/pip (python 3.12)
ini 复制代码
Usage:   
  pip3 install [options] <package> ...
  pip3 install [options] -r <requirements file> ... 
  
  pip3 uninstall [options] <package> ...
  pip3 uninstall [options] -r <requirements file> ... 

GPU驱动和Cuda工具

GPU规格:NVIDIA TU104GL [Tesla T4] 驱动和Cuda版本:NVIDIA-SMI 550.127.08 Driver Version: 550.127.08 CUDA Version: 12.4

shell 复制代码
# lspci | grep -i nvidia
00:07.0 3D controller: NVIDIA Corporation TU104GL [Tesla T4] (rev a1)
# 
# nvidia-smi
Thu Apr 10 12:13:49 2025       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.127.08             Driver Version: 550.127.08     CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  Tesla T4                       On  |   00000000:00:07.0 Off |                    0 |
| N/A   29C    P8              9W /   70W |       1MiB /  15360MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+
# 
# nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0
# 
# nvidia-smi --query-gpu=name,memory.total,utilization.gpu,temperature.gpu --format=csv
name, memory.total [MiB], utilization.gpu [%], temperature.gpu
Tesla T4, 15360 MiB, 0 %, 29

PyTorch安装

PyTorch , Tensors and Dynamic neural networks in Python with strong GPU acceleration

shell 复制代码
pip3 install torch torchvision 
torch-2.6.0

pip3 install -r pytorch/requirements.txt 
pip3 install scikit-learn tqdm gpytorch skorch 

PyG安装

PyG is the ultimate library for Graph Neural Networks Build graph learning pipelines with ease

shell 复制代码
pip3 install torch_geometric 
torch_geometric-2.6.1

# python3 -c "import torch; print(torch.__version__)" 
2.6.0+cu124
# python3 -c "import torch; print(torch.version.cuda)" 
12.4
# python3 -c "import torch; print(torch.cuda.device_count())" 
1

pip3 install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.6.0+cu124.html 

Python示例代码依赖

shell 复制代码
pip3 install -r pyg-examples/requirements.txt 

如何导出Python项目的库依赖文件requirements.txt,自行搜索DeepSeek、ChatGPT或Google/谷歌。

相关推荐
全栈弄潮儿12 小时前
一次真实失败:AI 代码看起来没问题,为什么还是翻车了?
aigc·openai·ai编程
Zguigo13 小时前
【CUDA6】CUDA Stream 是什么,为什么 CUDA 是异步执行,如何正确测量 GPU 时间以及多个任务如何重叠执行
人工智能·pytorch·深度学习
用户6859398353817 小时前
Codex CLI 接入 OpenAI 兼容接口:config.toml 逐行讲解与常见报错排查(2026)
openai
9i编程18 小时前
1. 教 AI 上班:带出我的数字同事 —— 把开发习惯交给 Qoder,从零搭脚手架
人工智能·openai·ai编程
论文复现现场1 天前
RTX 3090 24GB 适合科研吗?单卡论文复现、PyTorch 显存检查与 OOM 排错
人工智能·pytorch·python·深度学习·cuda·rtx3090
AI日报派送佬1 天前
2026年10月3日AI行业日报|系统权限安全全面收紧,AI算力与模型工程化落地提速
人工智能·openai·英伟达·ai日报·智能体技术·ai安全管控·ai开源生态
论文复现现场1 天前
AutoDL、算家云与公有云 GPU 怎么选?环境复现、计费与断点恢复对比
pytorch·深度学习·云计算·gpu
盘古开天16662 天前
PPO算法代码实战(三):PyTorch从零实现PPO求解CartPole
人工智能·pytorch·算法
全栈弄潮儿2 天前
小项目实战 4:代码审查、重构与提交前检查
aigc·openai·ai编程
AI日报派送佬2 天前
2026年9月30日AI行业日报|OpenAI DevDay连发25项更新,GPT-6.1 Sol&Dots智能体落地,全球AI监管收紧
人工智能·gpt·openai·ai智能体·大模型技术·人工智能前沿·ai监管