torch-geometric的安装

torch-geometric 的安装。

torch-geometric的安装必须要求版本对应,否则会出现很多麻烦的问题。比如:

OSError: [WinError 127] 找不到指定的程序。

所以安装之前,仔细检查一下cuda版本,pytorch的版本等等。
此外,还要注意电脑安装的CUDA驱动和pytorch 中对CUDA支持包的版本是否对应,不对应同样会出错。

安装python环境

python的3.6版本很稳定,对很多包的依赖很好。conda对包的依赖处理的也很好,会减少很多报错。使用conda创建python的环境

# 创建环境 (3.6.13版本很好,没问题,推荐)
conda create -n my_hea python==3.6.13
# 进入环境
conda activate my_hea

我需要安装pymatgen软件。在这里一并记录下安装命令。后安装会产生库冲突的问题。

# 我选择了使用conda安装
conda install --channel conda-forge pymatgen

#此外,官方还给出了另外一种基于pip安装的方式。由于pip安装出了错误,尤其是安装spglib的时候。所以我还是用conda安装的。(在安装了torch等其他诸多包之后使用pip安装,出错。环境创建好了之后,新环境下直接安装依然出错。可能是pip没有相应依赖的包。)
# ERROR: Failed building wheel for spglib

conda install --yes numpy scipy matplotlib
pip install pymatgen

安装pytorch

官网目前更新到稳定的1.10版本了。根据需要选择conda或者pip,选择cuda的版本,提示下面的安装。

# 安装torch 
pip3 install torch==1.10.0+cu102 torchvision==0.11.1+cu102 torchaudio===0.10.0+cu102 -f https://download.pytorch.org/whl/cu102/torch_stable.html

# 但是由于版本太高了,导致了找不到
#Looking in links: https://download.pytorch.org/whl/cu102/torch_stable.html
#ERROR: Could not find a version that satisfies the requirement torch==1.10.0+cu102 (from versions: none)
#ERROR: No matching distribution found for torch==1.10.0+cu102

# 找到之前版本的torch
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=10.2 -c pytorch

安装torch_geometric

# cuda是否可用,不必要。
python -c "import torch; print(torch.cuda.is_available())"
# 添加cuda的路径到系统的路径中。

# 至少需要1.4版本之上。
python -c "import torch; print(torch.__version__)"

python -c "import torch; print(torch.version.cuda)"

我这边显示的为:

(hea) D:\GitProjects\HEA_project>python -c "import torch; print(torch.version.cuda)"
10.2

(hea) D:\GitProjects\HEA_project>python -c "import torch; print(torch.__version__)"
# 不成功:
>> 1.10.0
# 成功
>> 1.10.0+cu102


安装相应的包:

```python
pip install torch-scatter -f https://data.pyg.org/whl/torch-1.10.0+cu102.html
pip install torch-sparse -f https://data.pyg.org/whl/torch-1.10.0+cu102.html
pip install torch-geometric
此外还需要安装补充包(可选的),我也一并装了。

```python
pip install torch-cluster -f https://data.pyg.org/whl/torch-1.10.0+cu102.html
pip install torch-spline-conv -f https://data.pyg.org/whl/torch-1.10.0+cu102.html

安装完成

检查

查看gpu是否能使用,查看torch-geometric是否还缺少什么包

# cuda
python -c "import torch; print(torch.cuda.is_available())"

# geometric
python -c "import torch_geometric; print(torch_geometric.__version__)"

补充

最近更新了新设备,用上了3090,目前pytorch版本太低,提示我不支持。因此重新安装环境。
目前3090需要11版本的CUDA 工具包,因此重新下载安装。
cuda包的文档库在下面的链接中。
https://developer.nvidia.com/cuda-toolkit-archive
一路使用默认选项直接安装。

在这里我使用了两个版本的cuda。一个是cuda11.1,另一个是cuda11.3。11.1在安装torch-geometric的时候出现了问题,暂时还没有找到原因,目前猜测就是莫名其妙的版本不匹配问题,因为我第二次安装11.3的cuda,python=3.8,torch = 1.10.0时,就很顺利,没有出现问题。
安装之后查询cuda版本

nvcc -V

创建python环境,安装torch

# 创建3.8版本的python
conda create -n hea python=3.8

# cuda 11.3的下载
pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

# cuda 11.1的下载
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
# 查看文档库,找到1.10.0 https://data.pyg.org/whl/

###同样的,安装完成后进行测试
python -c "import torch; print(torch.cuda.is_available())"

python -c "import torch; print(torch.__version__)"

python -c "import torch; print(torch.version.cuda)"

安装torch-geometric相应的包,把cuda版本修改成对应的简称即可。
例如,对于cuda11.3+torch1.10.0版本的安装。

pip install torch-scatter -f https://data.pyg.org/whl/torch-1.10.0+cu113.html
pip install torch-sparse -f https://data.pyg.org/whl/torch-1.10.0+cu113.html
pip install torch-geometric

安装完成,检查版本是否匹配

python -c "import torch; print(torch.version.cuda)"
>>> 11.3

nvcc --version
>>> 11.3

对于cuda11.1+torch1.8.0版本的安装。

pip install torch-scatter -f https://data.pyg.org/whl/torch-1.8.0+cu111.html
pip install torch-sparse -f https://data.pyg.org/whl/torch-1.8.0+cu111.html
pip install torch-geometric
此外还需要安装补充包(可选的)。

```python
pip install torch-cluster -f https://data.pyg.org/whl/torch-1.10.0+cu102.html
pip install torch-spline-conv -f https://data.pyg.org/whl/torch-1.10.0+cu102.html
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值