安装与cuda版本对应的torch-geometric文件的shell

import logging
import subprocess
 
from setuptools import setup
 
import torch
 
cuda_v = f"cu{torch.version.cuda.replace('.', '')}"
torch_v = torch.__version__.split('.')
torch_v = '.'.join(torch_v[:-1] + ['0'])
 
 
def system(command: str):
    output = subprocess.check_output(command, shell=True)
    logging.info(output)
 
 
system(f'pip install scipy')
system(f'pip install --no-index torch-scatter -f https://pytorch-geometric.com/whl/torch-{torch_v}+{cuda_v}.html')
system(f'pip install --no-index torch-sparse -f https://pytorch-geometric.com/whl/torch-{torch_v}+{cuda_v}.html')
system(f'pip install --no-index torch-cluster -f https://pytorch-geometric.com/whl/torch-{torch_v}+{cuda_v}.html')
system(f'pip install --no-index torch-spline-conv -f https://pytorch-geometric.com/whl/torch-{torch_v}+{cuda_v}.html')
system(f'pip install torch-geometric')
 

### torch-geometricPyTorch版本之间的兼容性 为了确保`torch-geometric`及其依赖项(如`torch-scatter`, `torch-sparse`等)能够正常工作,这些库所基于的CUDA版本应当匹配PyTorch使用的CUDA版本。当遇到错误提示关于不同编译器下的CUDA版本差异时,意味着当前环境中安装的不同组件是由不同的CUDA环境构建而来[^1]。 对于特定版本的`torch-geometric`来说,存在一系列被支持并测试过的PyTorch版本范围。例如,在较新版本中,如果使用的是`torch_geometric 2.6.1`,则建议搭配相对应的新版PyTorch来获得最佳性能和支持[^3]。然而,具体到每一个`torch-geometric`版本所能适配的最佳PyTorch版本可能有所不同;通常情况下,官方会提供针对多个主要版本的支持,比如从PyTorch 1.4.0一直到更近期的一些版本都有预编译二进制文件可供选择[^2]。 为了避免因CUDA版本不一致引发的问题,推荐的做法是在安装之前先确认好目标平台上的Python解释器、PyTorch以及所需CUDA工具链的具体配置情况,并据此挑选相适应的`torch-geometric`及相关扩展包版本进行部署。这可以通过查阅官方文档中的安装指南获取最准确的信息指导[^5]。 ```bash pip install --no-index torch_scatter -f https://data.pyg.org/whl/torch-${TORCH_VERSION}+${CUDA_VERSION}.html pip install --no-index torch_sparse -f https://data.pyg.org/whl/torch-${TORCH_VERSION}+${CUDA_VERSION}.html pip install --no-index torch_cluster -f https://data.pyg.org/whl/torch-${TORCH_VERSION}+${CUDA_VERSION}.html pip install --no-index torch_spline_conv -f https://data.pyg.org/whl/torch-${TORCH_VERSION}+${CUDA_VERSION}.html pip install torch_geometric ``` 上述命令展示了如何通过指定URL参数`${TORCH_VERSION}`和`${CUDA_VERSION}`的方式精确控制要安装的各个软件包版本组合,从而实现版本间的良好协同工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值