ubuntu22.04+pytorch2.3安装PyG图神经网络库

news2024/9/24 1:19:11

ubuntu下安装torch-geometric库,图神经网络

开发环境
ubuntu22.04
conda 24.5.0
python 3.9
pytorch 2.0.1
cuda 11.8

pyg的安装网上教程流传着许多安装方式,这些安装方式主要是:预先安装好pyg的依赖库,这些依赖库需要对应上python、pytorch、cuda的版本,需要小心对应,很容易出错;而且这些依赖库的安装,推荐采用的是预先编译好的库安装。

一、采用已编译好的包进行安装

即,先按python、pytorch、cuda版本,选择对应的pyg_lib、torch_cluster、torch_scatter、torch_sparse、torch_spline_conv 版本下载到本地,然后pip安装,最后安装pip install torch-geometric

1、首先我们安装pyg的

https://github.com/pyg-team/pytorch_geometric
在这里插入图片描述
点击here,进入https://data.pyg.org/whl/
在这里插入图片描述
点击你对应的torch版本及cuda版本,这里选择的是torch 2.01cuda 11.8

然后,进入https://data.pyg.org/whl/torch-2.0.1%2Bcu118.html 如下页面

pyg_lib-0.2.0+pt20cu118-cp310-cp310-linux_x86_64.whl
pyg_lib-0.2.0+pt20cu118-cp311-cp311-linux_x86_64.whl
pyg_lib-0.2.0+pt20cu118-cp38-cp38-linux_x86_64.whl
pyg_lib-0.2.0+pt20cu118-cp39-cp39-linux_x86_64.whl
pyg_lib-0.3.0+pt20cu118-cp310-cp310-linux_x86_64.whl
pyg_lib-0.3.0+pt20cu118-cp311-cp311-linux_x86_64.whl
pyg_lib-0.3.0+pt20cu118-cp38-cp38-linux_x86_64.whl
pyg_lib-0.3.0+pt20cu118-cp39-cp39-linux_x86_64.whl
pyg_lib-0.3.1+pt20cu118-cp310-cp310-linux_x86_64.whl
pyg_lib-0.3.1+pt20cu118-cp311-cp311-linux_x86_64.whl
pyg_lib-0.3.1+pt20cu118-cp38-cp38-linux_x86_64.whl
pyg_lib-0.3.1+pt20cu118-cp39-cp39-linux_x86_64.whl
pyg_lib-0.4.0+pt20cu118-cp310-cp310-linux_x86_64.whl
pyg_lib-0.4.0+pt20cu118-cp311-cp311-linux_x86_64.whl
pyg_lib-0.4.0+pt20cu118-cp38-cp38-linux_x86_64.whl
pyg_lib-0.4.0+pt20cu118-cp39-cp39-linux_x86_64.whl
torch_cluster-1.6.1+pt20cu118-cp310-cp310-linux_x86_64.whl
torch_cluster-1.6.1+pt20cu118-cp310-cp310-win_amd64.whl
torch_cluster-1.6.1+pt20cu118-cp311-cp311-linux_x86_64.whl
torch_cluster-1.6.1+pt20cu118-cp311-cp311-win_amd64.whl
torch_cluster-1.6.1+pt20cu118-cp38-cp38-linux_x86_64.whl
torch_cluster-1.6.1+pt20cu118-cp38-cp38-win_amd64.whl
torch_cluster-1.6.1+pt20cu118-cp39-cp39-linux_x86_64.whl
torch_cluster-1.6.1+pt20cu118-cp39-cp39-win_amd64.whl
torch_cluster-1.6.2+pt20cu118-cp310-cp310-linux_x86_64.whl
torch_cluster-1.6.2+pt20cu118-cp310-cp310-win_amd64.whl
torch_cluster-1.6.2+pt20cu118-cp311-cp311-linux_x86_64.whl
torch_cluster-1.6.2+pt20cu118-cp311-cp311-win_amd64.whl
torch_cluster-1.6.2+pt20cu118-cp38-cp38-linux_x86_64.whl
torch_cluster-1.6.2+pt20cu118-cp38-cp38-win_amd64.whl
torch_cluster-1.6.2+pt20cu118-cp39-cp39-linux_x86_64.whl
torch_cluster-1.6.2+pt20cu118-cp39-cp39-win_amd64.whl
torch_cluster-1.6.3+pt20cu118-cp310-cp310-linux_x86_64.whl
torch_cluster-1.6.3+pt20cu118-cp310-cp310-win_amd64.whl
torch_cluster-1.6.3+pt20cu118-cp311-cp311-linux_x86_64.whl
torch_cluster-1.6.3+pt20cu118-cp311-cp311-win_amd64.whl
torch_cluster-1.6.3+pt20cu118-cp38-cp38-linux_x86_64.whl
torch_cluster-1.6.3+pt20cu118-cp38-cp38-win_amd64.whl
torch_cluster-1.6.3+pt20cu118-cp39-cp39-linux_x86_64.whl
torch_cluster-1.6.3+pt20cu118-cp39-cp39-win_amd64.whl
torch_scatter-2.1.1+pt20cu118-cp310-cp310-linux_x86_64.whl
torch_scatter-2.1.1+pt20cu118-cp310-cp310-win_amd64.whl
torch_scatter-2.1.1+pt20cu118-cp311-cp311-linux_x86_64.whl
torch_scatter-2.1.1+pt20cu118-cp311-cp311-win_amd64.whl
torch_scatter-2.1.1+pt20cu118-cp38-cp38-linux_x86_64.whl
torch_scatter-2.1.1+pt20cu118-cp38-cp38-win_amd64.whl
torch_scatter-2.1.1+pt20cu118-cp39-cp39-linux_x86_64.whl
torch_scatter-2.1.1+pt20cu118-cp39-cp39-win_amd64.whl
torch_scatter-2.1.2+pt20cu118-cp310-cp310-linux_x86_64.whl
torch_scatter-2.1.2+pt20cu118-cp310-cp310-win_amd64.whl
torch_scatter-2.1.2+pt20cu118-cp311-cp311-linux_x86_64.whl
torch_scatter-2.1.2+pt20cu118-cp311-cp311-win_amd64.whl
torch_scatter-2.1.2+pt20cu118-cp38-cp38-linux_x86_64.whl
torch_scatter-2.1.2+pt20cu118-cp38-cp38-win_amd64.whl
torch_scatter-2.1.2+pt20cu118-cp39-cp39-linux_x86_64.whl
torch_scatter-2.1.2+pt20cu118-cp39-cp39-win_amd64.whl
torch_sparse-0.6.17+pt20cu118-cp310-cp310-linux_x86_64.whl
torch_sparse-0.6.17+pt20cu118-cp310-cp310-win_amd64.whl
torch_sparse-0.6.17+pt20cu118-cp311-cp311-linux_x86_64.whl
torch_sparse-0.6.17+pt20cu118-cp311-cp311-win_amd64.whl
torch_sparse-0.6.17+pt20cu118-cp38-cp38-linux_x86_64.whl
torch_sparse-0.6.17+pt20cu118-cp38-cp38-win_amd64.whl
torch_sparse-0.6.17+pt20cu118-cp39-cp39-linux_x86_64.whl
torch_sparse-0.6.17+pt20cu118-cp39-cp39-win_amd64.whl
torch_sparse-0.6.18+pt20cu118-cp310-cp310-linux_x86_64.whl
torch_sparse-0.6.18+pt20cu118-cp310-cp310-win_amd64.whl
torch_sparse-0.6.18+pt20cu118-cp311-cp311-linux_x86_64.whl
torch_sparse-0.6.18+pt20cu118-cp311-cp311-win_amd64.whl
torch_sparse-0.6.18+pt20cu118-cp38-cp38-linux_x86_64.whl
torch_sparse-0.6.18+pt20cu118-cp38-cp38-win_amd64.whl
torch_sparse-0.6.18+pt20cu118-cp39-cp39-linux_x86_64.whl
torch_sparse-0.6.18+pt20cu118-cp39-cp39-win_amd64.whl
torch_spline_conv-1.2.2+pt20cu118-cp310-cp310-linux_x86_64.whl
torch_spline_conv-1.2.2+pt20cu118-cp310-cp310-win_amd64.whl
torch_spline_conv-1.2.2+pt20cu118-cp311-cp311-linux_x86_64.whl
torch_spline_conv-1.2.2+pt20cu118-cp311-cp311-win_amd64.whl
torch_spline_conv-1.2.2+pt20cu118-cp38-cp38-linux_x86_64.whl
torch_spline_conv-1.2.2+pt20cu118-cp38-cp38-win_amd64.whl
torch_spline_conv-1.2.2+pt20cu118-cp39-cp39-linux_x86_64.whl
torch_spline_conv-1.2.2+pt20cu118-cp39-cp39-win_amd64.whl

pyg_lib、torch_cluster、torch_scatter、torch_sparse、torch_spline_conv 都逐一选择一个版本下载

注意选择对python的版本(cp310即python 3.10版本)即操作系统(linux or win)

下载完成如下所示
在这里插入图片描述
开始本地安装依赖库,如下

# 激活对应的conda环境
$ conda acitvate pyt2.0
# pip 安装上面5个库
$ pip install pyg_lib-0.4.0+pt20cu118-cp39-cp39-linux_x86_64.whl 
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing ./pyg_lib-0.4.0+pt20cu118-cp39-cp39-linux_x86_64.whl
Installing collected packages: pyg-lib
Successfully installed pyg-lib-0.4.0+pt20cu118

$ pip install torch_cluster-1.6.3+pt20cu118-cp39-cp39-linux_x86_64.whl 
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing ./torch_cluster-1.6.3+pt20cu118-cp39-cp39-linux_x86_64.whl
Requirement already satisfied: scipy in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from torch-cluster==1.6.3+pt20cu118) (1.13.1)
Requirement already satisfied: numpy<2.3,>=1.22.4 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from scipy->torch-cluster==1.6.3+pt20cu118) (1.23.5)
Installing collected packages: torch-cluster
Successfully installed torch-cluster-1.6.3+pt20cu118

$ pip install torch_scatter-2.1.2+pt20cu118-cp39-cp39-linux_x86_64.whl 
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing ./torch_scatter-2.1.2+pt20cu118-cp39-cp39-linux_x86_64.whl
Installing collected packages: torch-scatter
Successfully installed torch-scatter-2.1.2+pt20cu118

$ pip install torch_sparse-0.6.18+pt20cu118-cp39-cp39-linux_x86_64.whl 
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing ./torch_sparse-0.6.18+pt20cu118-cp39-cp39-linux_x86_64.whl
Requirement already satisfied: scipy in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from torch-sparse==0.6.18+pt20cu118) (1.13.1)
Requirement already satisfied: numpy<2.3,>=1.22.4 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from scipy->torch-sparse==0.6.18+pt20cu118) (1.23.5)
Installing collected packages: torch-sparse
Successfully installed torch-sparse-0.6.18+pt20cu118

$ pip install torch_spline_conv-1.2.2+pt20cu118-cp39-cp39-linux_x86_64.whl 
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing ./torch_spline_conv-1.2.2+pt20cu118-cp39-cp39-linux_x86_64.whl
Installing collected packages: torch-spline-conv
Successfully installed torch-spline-conv-1.2.2+pt20cu118

然后安装pyg

pip install torch-geometric

$ pip install torch-geometric
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting torch-geometric
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/97/f0/66ad3a5263aa16efb534aaf4e7da23ffc28c84efbbd720b0c5ec174f6242/torch_geometric-2.5.3-py3-none-any.whl (1.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 1.3 MB/s eta 0:00:00
Collecting tqdm (from torch-geometric)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/18/eb/fdb7eb9e48b7b02554e1664afd3bd3f117f6b6d6c5881438a0b055554f9b/tqdm-4.66.4-py3-none-any.whl (78 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.3/78.3 kB 5.5 MB/s eta 0:00:00
Requirement already satisfied: numpy in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from torch-geometric) (1.23.5)
Requirement already satisfied: scipy in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from torch-geometric) (1.13.1)
Collecting fsspec (from torch-geometric)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5e/44/73bea497ac69bafde2ee4269292fa3b41f1198f4bb7bbaaabde30ad29d4a/fsspec-2024.6.1-py3-none-any.whl (177 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 177.6/177.6 kB 1.8 MB/s eta 0:00:00
Requirement already satisfied: jinja2 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from torch-geometric) (3.1.3)
Requirement already satisfied: aiohttp in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from torch-geometric) (3.9.5)
Requirement already satisfied: requests in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from torch-geometric) (2.31.0)
Requirement already satisfied: pyparsing in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from torch-geometric) (3.0.9)
Requirement already satisfied: scikit-learn in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from torch-geometric) (1.4.2)
Requirement already satisfied: psutil>=5.8.0 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from torch-geometric) (5.9.0)
Requirement already satisfied: aiosignal>=1.1.2 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from aiohttp->torch-geometric) (1.2.0)
Requirement already satisfied: attrs>=17.3.0 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from aiohttp->torch-geometric) (23.1.0)
Requirement already satisfied: frozenlist>=1.1.1 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from aiohttp->torch-geometric) (1.4.0)
Requirement already satisfied: multidict<7.0,>=4.5 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from aiohttp->torch-geometric) (6.0.4)
Requirement already satisfied: yarl<2.0,>=1.0 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from aiohttp->torch-geometric) (1.9.3)
Requirement already satisfied: async-timeout<5.0,>=4.0 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from aiohttp->torch-geometric) (4.0.3)
Requirement already satisfied: MarkupSafe>=2.0 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from jinja2->torch-geometric) (2.1.3)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from requests->torch-geometric) (2.0.4)
Requirement already satisfied: idna<4,>=2.5 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from requests->torch-geometric) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from requests->torch-geometric) (2.1.0)
Requirement already satisfied: certifi>=2017.4.17 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from requests->torch-geometric) (2024.6.2)
Requirement already satisfied: joblib>=1.2.0 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from scikit-learn->torch-geometric) (1.4.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages (from scikit-learn->torch-geometric) (2.2.0)
Installing collected packages: tqdm, fsspec, torch-geometric
Successfully installed fsspec-2024.6.1 torch-geometric-2.5.3 tqdm-4.66.4

安装完成后,查看一下版本

$ conda list torch
# packages in environment at /home/myPC/miniconda3/envs/pyt-gpu-2.0:
#
# Name                    Version                   Build  Channel
pytorch                   2.0.1           gpu_cuda118py39he342708_0    defaults
torch-cluster             1.6.3+pt20cu118          pypi_0    pypi
torch-geometric           2.5.3                    pypi_0    pypi
torch-scatter             2.1.2+pt20cu118          pypi_0    pypi
torch-sparse              0.6.18+pt20cu118          pypi_0    pypi
torch-spline-conv         1.2.2+pt20cu118          pypi_0    pypi

$ conda list pyg-lib
# packages in environment at /home/myPC/miniconda3/envs/pyt-gpu-2.0:
#
# Name                    Version                   Build  Channel
pyg-lib                   0.4.0+pt20cu118          pypi_0    pypi

下载的几个离线包已正常安装!

,导入一下,验证一下,出现如下报错

OSError: /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_cluster/_version_cuda.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs
$ ipython
Python 3.9.18 (main, Sep 11 2023, 13:41:44) 
Type 'copyright', 'credits' or 'license' for more information
IPython 8.15.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import torch_geometric.datasets
/home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/typing.py:54: UserWarning: An issue occurred while importing 'pyg-lib'. Disabling its usage. Stacktrace: /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/libpyg.so: undefined symbol: _ZNK5torch8autograd4Node4nameEv
  warnings.warn(f"An issue occurred while importing 'pyg-lib'. "
/home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/typing.py:72: UserWarning: An issue occurred while importing 'torch-scatter'. Disabling its usage. Stacktrace: /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_scatter/_version_cuda.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs
  warnings.warn(f"An issue occurred while importing 'torch-scatter'. "
/home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/typing.py:83: UserWarning: An issue occurred while importing 'torch-cluster'. Disabling its usage. Stacktrace: /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_cluster/_version_cuda.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs
  warnings.warn(f"An issue occurred while importing 'torch-cluster'. "
/home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/typing.py:99: UserWarning: An issue occurred while importing 'torch-spline-conv'. Disabling its usage. Stacktrace: /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_spline_conv/_version_cuda.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs
  warnings.warn(
/home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/typing.py:110: UserWarning: An issue occurred while importing 'torch-sparse'. Disabling its usage. Stacktrace: /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_sparse/_version_cuda.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs
  warnings.warn(f"An issue occurred while importing 'torch-sparse'. "
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In[1], line 1
----> 1 import torch_geometric.datasets

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/__init__.py:13
     11 import torch_geometric.loader
     12 import torch_geometric.transforms
---> 13 import torch_geometric.datasets
     14 import torch_geometric.nn
     15 import torch_geometric.explain

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/datasets/__init__.py:101
     99 from .sbm_dataset import RandomPartitionGraphDataset
    100 from .mixhop_synthetic_dataset import MixHopSyntheticDataset
--> 101 from .explainer_dataset import ExplainerDataset
    102 from .infection_dataset import InfectionDataset
    103 from .ba2motif_dataset import BA2MotifDataset

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/datasets/explainer_dataset.py:9
      7 from torch_geometric.datasets.graph_generator import GraphGenerator
      8 from torch_geometric.datasets.motif_generator import MotifGenerator
----> 9 from torch_geometric.explain import Explanation
     12 class ExplainerDataset(InMemoryDataset):
     13     r"""Generates a synthetic dataset for evaluating explainabilty algorithms,
     14     as described in the `"GNNExplainer: Generating Explanations for Graph
     15     Neural Networks" <https://arxiv.org/abs/1903.03894>`__ paper.
   (...)
     66             (default: :obj:`None`)
     67     """

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/explain/__init__.py:3
      1 from .config import ExplainerConfig, ModelConfig, ThresholdConfig
      2 from .explanation import Explanation, HeteroExplanation
----> 3 from .algorithm import *  # noqa
      4 from .explainer import Explainer
      5 from .metric import *  # noqa

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/explain/algorithm/__init__.py:1
----> 1 from .base import ExplainerAlgorithm
      2 from .dummy_explainer import DummyExplainer
      3 from .gnn_explainer import GNNExplainer

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/explain/algorithm/base.py:14
      8 from torch_geometric.explain import Explanation, HeteroExplanation
      9 from torch_geometric.explain.config import (
     10     ExplainerConfig,
     11     ModelConfig,
     12     ModelReturnType,
     13 )
---> 14 from torch_geometric.nn import MessagePassing
     15 from torch_geometric.typing import EdgeType, NodeType
     16 from torch_geometric.utils import k_hop_subgraph

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/nn/__init__.py:5
      3 from .data_parallel import DataParallel
      4 from .to_hetero_transformer import to_hetero
----> 5 from .to_hetero_with_bases_transformer import to_hetero_with_bases
      6 from .to_fixed_size_transformer import to_fixed_size
      7 from .encoding import PositionalEncoding, TemporalEncoding

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/nn/to_hetero_with_bases_transformer.py:9
      6 from torch import Tensor
      7 from torch.nn import Module, Parameter
----> 9 from torch_geometric.nn.conv import MessagePassing
     10 from torch_geometric.nn.dense import Linear
     11 from torch_geometric.nn.fx import Transformer

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/nn/conv/__init__.py:8
      6 from .cugraph.sage_conv import CuGraphSAGEConv
      7 from .graph_conv import GraphConv
----> 8 from .gravnet_conv import GravNetConv
      9 from .gated_graph_conv import GatedGraphConv
     10 from .res_gated_graph_conv import ResGatedGraphConv

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/nn/conv/gravnet_conv.py:13
     10 from torch_geometric.typing import OptTensor, PairOptTensor, PairTensor
     12 try:
---> 13     from torch_cluster import knn
     14 except ImportError:
     15     knn = None

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_cluster/__init__.py:18
     16 spec = cuda_spec or cpu_spec
     17 if spec is not None:
---> 18     torch.ops.load_library(spec.origin)
     19 else:  # pragma: no cover
     20     raise ImportError(f"Could not find module '{library}_cpu' in "
     21                       f"{osp.dirname(__file__)}")

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch/_ops.py:643, in _Ops.load_library(self, path)
    638 path = _utils_internal.resolve_library_path(path)
    639 with dl_open_guard():
    640     # Import the shared library into the process, thus running its
    641     # static (global) initialization code in order to register custom
    642     # operators with the JIT.
--> 643     ctypes.CDLL(path)
    644 self.loaded_libraries.add(path)

File ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/ctypes/__init__.py:382, in CDLL.__init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    379 self._FuncPtr = _FuncPtr
    381 if handle is None:
--> 382     self._handle = _dlopen(self._name, mode)
    383 else:
    384     self._handle = handle

OSError: /home/myPC/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_cluster/_version_cuda.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs

上面的问题经过各种尝试,又是切换pytroch的版本,又是切换cuda的版本、python的版本,重复下载pyg_lib、torch_cluster、torch_scatter、torch_sparse、torch_spline_conv 的其他版本,还是失败!逐一import torch_cluster或者import torch_scatter等,发现没一个库可以用,猜测可能是在conda下,使用pip安装的原因,燃鹅,conda环境下pip安装的包又能正常使用conda list查看到,pip安装的包,也确实安装到了conda对应的环境目录下;

各种尝试验证下,都失败了,几乎绝望放弃了,官网上的conda install -c pyg pyg又无法使用,pip逐一安装的方式又无法使用,绝望!

二、pip一步安装

正确的姿势,只需要一步就能安装了上,我们看看git官网以及pyg的官网的原文

https://github.com/pyg-team/pytorch_geometric
在这里插入图片描述
https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html#
在这里插入图片描述
原来PyG 2.3版本以后,不需要任何其他库即可安装

赶紧把其他之前安装的依赖卸载

# 之前未安装过这些依赖的,可跳过这步
pip uninstall torch-geometric torch-scatter torch-sparse torch-spline-conv pyg-lib torch_cluster

我们再看看当前的环境

运行环境如下:
ubuntu 22.04
python 3.10
pytorch 2.3.0
cuda 11.8

执行安装

pip install torch_geometric

查看一下版本

conda list torch-geometric
# packages in environment at /home/myPC/miniconda3/envs/pyg:
#
# Name                    Version                   Build  Channel
torch-geometric           2.5.3                    pypi_0    pypi

验证一下,无限报错

$ ipython
Python 3.10.14 (main, May  6 2024, 19:42:50) [GCC 11.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.25.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import torch_geometric

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "/home/myPC/miniconda3/envs/pyg/bin/ipython", line 11, in <module>
    sys.exit(start_ipython())
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/__init__.py", line 130, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/traitlets/config/application.py", line 1075, in launch_instance
    app.start()
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/terminal/ipapp.py", line 317, in start
    self.shell.mainloop()
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 917, in mainloop
    self.interact()
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 910, in interact
    self.run_cell(code, store_history=True)
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3075, in run_cell
    result = self._run_cell(
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3130, in _run_cell
    result = runner(coro)
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/core/async_helpers.py", line 129, in _pseudo_sync_runner
    coro.send(None)
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3334, in run_cell_async
    has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3517, in run_ast_nodes
    if await self.run_code(code, result, async_=asy):
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3577, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-c36e13293883>", line 1, in <module>
    import torch_geometric
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch_geometric/__init__.py", line 5, in <module>
    from .isinstance import is_torch_instance
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch_geometric/isinstance.py", line 8, in <module>
    import torch._dynamo
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/_dynamo/__init__.py", line 64, in <module>
    torch.manual_seed = disable(torch.manual_seed)
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/_dynamo/decorators.py", line 50, in disable
    return DisableContext()(fn)
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 410, in __call__
    (filename is None or trace_rules.check(fn))
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/_dynamo/trace_rules.py", line 3378, in check
    return check_verbose(obj, is_inlined_call).skipped
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/_dynamo/trace_rules.py", line 3361, in check_verbose
    rule = torch._dynamo.trace_rules.lookup_inner(
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/_dynamo/trace_rules.py", line 3442, in lookup_inner
    rule = get_torch_obj_rule_map().get(obj, None)
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/_dynamo/trace_rules.py", line 2782, in get_torch_obj_rule_map
    obj = load_object(k)
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/_dynamo/trace_rules.py", line 2811, in load_object
    val = _load_obj_from_str(x[0])
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/_dynamo/trace_rules.py", line 2795, in _load_obj_from_str
    return getattr(importlib.import_module(module), obj_name)
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/nested/_internal/nested_tensor.py", line 417, in <module>
    values=torch.randn(3, 3, device="meta"),
/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/nested/_internal/nested_tensor.py:417: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at /home/conda/feedstock_root/build_artifacts/libtorch_1715556200933/work/torch/csrc/utils/tensor_numpy.cpp:84.)
  values=torch.randn(3, 3, device="meta"),

numpy库又有问题,不对了;尝试更新一下numpy到2.0版本

conda install -c conda-forge numpy==2.0

再次测试

ipython
Python 3.10.14 (main, May  6 2024, 19:42:50) [GCC 11.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.25.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import torch_geometric

这次没报任何错误,完美

总结torch-geometric版本组合

可行的组合版本(亲测):python 3.10 + pytroch2.3 + cuda11.8 + torch-geometric 2.5.3 + numpy 2.0

另外一种版本组合(亲测):python3.12 + pytroch2.3 + cuda11.8 + torch-geometric 2.5.3 + numpy 1.26

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1915388.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

双栈实现一个队列

两个栈可实现将列表倒序&#xff1a;设有含三个元素的栈 A [1,2,3] 和空栈 B [] 。若循环执行 A 元素出栈并添加入栈 B &#xff0c;直到栈 A 为空&#xff0c;则 A [] , B [3,2,1] &#xff0c;即栈 B 元素为栈 A 元素倒序。 利用栈 B 删除队首元素&#xff1a;倒序后&am…

系统服务综合作业

首先配置自动挂载 服务器的/rhce 自动挂载在客服端的/nfs/rhce 首先在服务器进行配置 dnf install nfs-utils -y [rootlocalhost ~]# vim /etc/exports [rootlocalhost ~]# firewall-cmd --permanent --add-servicenfs success [rootlocalhost ~]# firewall-cmd --permanen…

【ARM】MDK-解决Flexnet服务的error:-13.66

【更多软件使用问题请点击亿道电子官方网站】 1、 文档目标 记录MDK网络版部署服务器error &#xff1a;-13.66的问题解决方案&#xff0c;后续有相关发现持续更新。 2、 问题场景 在客户的服务器上部署Flexnet服务&#xff0c;将license文件检查过后&#xff0c;确认MAC地址…

基于KV Cache构建流式帧级别Transformer实现自回归解码

在自然语言处理和序列建模中&#xff0c;Transformer模型因其在处理长距离依赖关系上的卓越性能而被广泛使用。传统的Transformer模型在处理长序列时&#xff0c;计算和存储的开销较大&#xff0c;而流式帧级别Transformer通过引入KV Cache&#xff08;键值缓存&#xff09;来有…

AMD X3D CPU 史诗级进化,锐龙7 9800X3D默秒全

6 月份刚刚结束&#xff0c;这有关下半年新一代 PC 硬件消息便愈发蠢蠢欲动起来。 上个月初台北国际电脑展上&#xff0c;AMD 正式公布了下一代 Zen 5 架构 Ryzen 9000 系列桌面处理器。 AMD 前脚刚大吹特吹性能吊锤 Intel i9 14900K 云云&#xff0c;没想到反手又来了一波被自…

【两大3D转换SDK对比】HOOPS Exchange VS. CAD Exchanger

在现代工业和工程设计领域&#xff0c;CAD数据转换工具是确保不同软件系统间数据互通的关键环节。HOOPS Exchange和CAD Exchanger是两款备受关注的工具&#xff0c;它们在功能、支持格式、性能和应用场景等方面有着显著差异。 本文将从背景、支持格式、功能和性能、应用场景等…

小程序内容管理系统设计

设计一个小程序内容管理系统&#xff08;CMS&#xff09;时&#xff0c;需要考虑以下几个关键方面来确保其功能完善、用户友好且高效&#xff1a; 1. 需求分析 目标用户&#xff1a;明确你的目标用户群体&#xff0c;比如企业、媒体、个人博主等&#xff0c;这将决定系统的功…

本地部署,图片细节处理大模型Tile Controlnet

目录 什么是 Tile ControlNet&#xff1f; 工作原理 应用场景 优势与挑战 优势 挑战 本地部署 运行结果 未来展望 结论 Tip&#xff1a; 在近年来的深度学习和计算机视觉领域&#xff0c;生成对抗网络&#xff08;GAN&#xff09;和扩散模型等技术取得了显著的进展。…

NI 5G大规模MIMO测试台:将理论变为现实

目录 概览引言MIMO原型验证系统MIMO原型验证系统硬件LabVIEW通信系统设计套件&#xff08;简称LabVIEW Communications&#xff09;CPU开发代码FPGA代码开发硬件和软件紧密集成 LabVIEW Communications MIMO应用框架MIMO应用框架特性单用户MIMO和多用户MIMO基站和移动站天线数量…

LINUX命令行curl指令与python内置urllib模块

urllib是python御用的易用的轻便模块&#xff0c;curl是Linux功能强大的命令行工具&#xff0c;都是参与Web的利器。 (笔记模板由python脚本于2024年07月10日 18:41:12创建&#xff0c;本篇笔记适合喜欢Python和Linux的coder翻阅) 【学习的细节是欢悦的历程】 Python 官网&…

【最强八股文 -- 计算机网络】【快速版】WWW 构建技术 (3 项)

1.HTML(HyperText Markup Language):作为页面的文本标记语言 2.HTTP(HyperTextTransfer Protocol):文档传递协议 3.URL(Uniform Resource Locator):指定文档所在地址 HTTPS 和 HTTP 的区别: HTTP: 以明文的方式在网络中传输数据&#xff0c;HTTPS 解决了HTTP 不安全的缺陷&…

芋道源码 yudao-cloud 文档,视频,开发指南如何看全部

进入官网后可以看到相关内容 但是后端手册开始就看不了了 必须加入知识知识星球才行&#xff0c;很烦 闲**鱼搜索用户 水城打坐的藤壶 找到这个链接 这下大家都懂了吧 现在就可以看到看不到的内容了 在线文档的弹窗可技术去除&#xff0c;很简单 直接起飞哈 包括更新sq…

DELTA: DEGRADATION-FREE FULLY TEST-TIME ADAPTATION--论文笔记

论文笔记 资料 1.代码地址 2.论文地址 https://arxiv.org/abs/2301.13018 3.数据集地址 https://github.com/bwbwzhao/DELTA 论文摘要的翻译 完全测试时间自适应旨在使预训练模型在实时推理过程中适应测试数据流&#xff0c;当测试数据分布与训练数据分布不同时&#x…

前端面试题40(浅谈MVVM双向数据绑定)

MVVM&#xff08;Model-View-ViewModel&#xff09;架构模式是一种用于简化用户界面&#xff08;UI&#xff09;开发的软件架构设计模式&#xff0c;尤其在现代前端开发中非常流行&#xff0c;例如在使用Angular、React、Vue.js等框架时。MVVM模式源于经典的MVC&#xff08;Mod…

【C++修行之道】string类练习题

目录 387. 字符串中的第一个唯一字符 125. 验证回文串 917. 仅仅反转字母 415. 字符串相加&#xff08;重点&#xff09; 541. 反转字符串 II 387. 字符串中的第一个唯一字符 字符串中的第一个唯一字符 - 力扣&#xff08;LeetCode&#xff09; 给定一个字符串 s &#…

【UE5.3】笔记10-时间轴的使用

时间轴 右键--Add Timeline(在最下面) --> 双击进入时间轴的编辑界面&#xff1a; 左上角可以添加不同类型的轨道&#xff0c;可以自定义轨道的长度&#xff0c;单位秒&#xff0c;一次可以添加多个 可以通过右键添加关键帧&#xff0c;快捷键&#xff1a;shift鼠标左键按…

ssrf结合redis未授权getshell

目录 漏洞介绍 SSRF Redis未授权 利用原理 环境搭建 利用过程 rockylinux cron计划任务反弹shell 写公钥免密登录 ubuntu 写公钥免密登录 漏洞介绍 SSRF SSRF&#xff08;server side request forgrey&#xff09;服务端请求伪造&#xff0c;因后端未过滤用户输入&…

LeetCode(2)合并链表、环形链表的约瑟夫问题、链表分割

一、合并链表 . - 力扣&#xff08;LeetCode&#xff09; 题目描述&#xff1a; /*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/ typedef struct ListNode ListNode; struct ListNode* mergeTwoLists(struct …

skywalking-1-服务端安装

skywalking很优秀。 安装服务端 skywalking的服务端主要是aop服务&#xff0c;为了方便查看使用还需要安装ui。另外采集的数据我们肯定要存起来&#xff0c;这个数据库就直接用官方的banyandb。也就是aop、ui、banyandb都使用官方包。 我们的目的是快速使用和体验&#xff0c…

stm32按键设置闹钟数进退位不正常?如何解决

&#x1f3c6;本文收录于《CSDN问答解惑-专业版》专栏&#xff0c;主要记录项目实战过程中的Bug之前因后果及提供真实有效的解决方案&#xff0c;希望能够助你一臂之力&#xff0c;帮你早日登顶实现财富自由&#x1f680;&#xff1b;同时&#xff0c;欢迎大家关注&&收…