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

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

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

C++11|包装器

目录 引入 一、function包装器 1.1包装器使用 1.2包装器解决类型复杂 二、bind包装器 引入 在我们学过的回调中&#xff0c;函数指针&#xff0c;仿函数&#xff0c;lambda都可以完成&#xff0c;但他们都有一个缺点&#xff0c;就是类型的推导复杂性&#xff0c;从而会…

详解Amivest 流动性比率

详解Amivest 流动性比率 Claude-3.5-Sonnet Poe Amivest流动性比率是一个衡量证券市场流动性的重要指标。这个比率主要用于评估在不对价格造成重大影响的情况下,市场能够吸收多少交易量。以下是对Amivest流动性比率的详细解释: 定义: Amivest流动性比率是交易额与绝对收益率的…

一.2.(1)双极型晶体三极管的结构、工作原理、特性曲线及主要参数

1.双极型晶体三极管的结构 学会区分P管和N管&#xff0c;会绘制符号 2.工作原理 无论是PNP 还是NPN&#xff0c;本质上放大时&#xff0c;都是发射结正偏&#xff0c;集电极反偏。&#xff08;可以简单理解为pn为二极管&#xff0c;每个三极管都有两个二极管&#xff09; 其中电…

行内元素、块级元素居中

行内元素居中 水平居中 {text-align&#xff1a;center;}垂直居中 单行——行高等于盒子高度 <head><style>.father {width: 400px;height: 200px;/* 行高等于盒子高度&#xff1a;line-height: 200px; */line-height: 200px;background-color: pink;}.son {}&…

深入刨析Redis存储技术设计艺术(二)

三、Redis主存储 3.1、存储相关结构体 redisServer:服务器 server.h struct redisServer { /* General */ pid_t pid; /* Main process pid. */ pthread_t main_thread_id; /* Main thread id */ char *configfile; /* Absolut…

js获取当前浏览器地址,ip,端口号等等

前言&#xff1a; js获取当前浏览器地址&#xff0c;ip&#xff0c;端口号等等 window.location属性查询 具体属性&#xff1a; 1、获取他的ip地址 window.location.hostname 2、获取他的端口号 window.location.port 3、获取他的全路径 window.location.origin 4、获取…

EtherCAT转Profinet网关配置说明第一讲:配置软件安装及介绍

网关XD-ECPNS20为EtherCAT转Profinet协议网关&#xff0c;使EtherCAT协议和Profinet协议两种工业实时以太网网络之间双向传输 IO 数据。适用于具有EtherCAT协议网络与Profinet协议网络跨越网络界限进行数据交换的解决方案。 本网关通过上位机来进行配置。 首先安装上位机软件 一…

【日志信息管理】管理日志信息的类

日志用于记录程序的执行记录包括程序的出错记录&#xff0c;程序致命退出原因&#xff0c;程序的正常执行记录。这样我们就可以很快的察觉程序的错误原因、执行状况等等&#xff0c;因此管理日志信息是非常重要的。 日志一般由以下部分组合&#xff1a; 日志时间、日志等级、…

数据库可视化管理工具dbeaver试用及问题处理。

本文记录了在内网离线安装数据库可视化管理工具dbeaver的过程和相关问题处理方法。 一、下载dbeaver https://dbeaver.io/download/ 笔者测试时Windows平台最新版本为&#xff1a;dbeaver-ce-24.1.1-x86_64-setup.exe 二、安装方法 一路“下一步”即可 三、问题处理 1、问…

06浅谈大语言模型可调节参数TopP和TopK

浅谈大模型参数TopP和TopK 大语言模型中的temperature、top_p和top_k参数是用来控制模型生成文本时的随机性和创造性的。下面分享一下topP和topK两个参数的意义及逻辑&#xff1b; top K&#xff08;Top-K Sampling&#xff09; 作用&#xff1a;只从模型认为最可能的k个词中选…

排序-java(插入排序和选择排序)

一&#xff0c;分类 主要的排序大致分为以下几类&#xff1a; 1&#xff0c;插入排序&#xff0c;又分为直接插入排序和希尔排序 2&#xff0c;选择排序&#xff0c;又分为选择排序和堆排序 3&#xff0c;交换排序&#xff0c;又分为冒泡排序和快速排序 4&#xff0c;归并…

Python中异步事件触发

1、问题背景 在Python中&#xff0c;我想创建一个由事件生成控制流程的类结构。为此&#xff0c;我做了以下工作&#xff1a; class MyEvent: EventName_FunctionName {}classmethoddef setup(cls, notificationname, functionname):if notificationname in MyEvent.EventN…

如何借助AI在20分钟内写一个springboot单表的增删改查

目录 1. AI工具介绍2. 写代码的正确顺序2.1 编写 Entity 类&#xff1a;2.2 编写 Mapper 接口&#xff1a;2.3 编写 Mapper XML 文件&#xff08;如果使用 MyBatis&#xff09;&#xff1a;2.4 编写 Service 接口&#xff1a;2.5 编写 Service 实现类&#xff08;ServiceImpl&a…

【全面讲解如何安装Jupyter Notebook!】

&#x1f308;个人主页: 程序员不想敲代码啊 &#x1f3c6;CSDN优质创作者&#xff0c;CSDN实力新星&#xff0c;CSDN博客专家 &#x1f44d;点赞⭐评论⭐收藏 &#x1f91d;希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出指正&#xff0c;让我们共…

智慧校园综合解决方案PPT(41页)

1. 方案背景 智慧校园综合解决方案响应《教育信息化2.0行动计划》等政策&#xff0c;旨在加快智慧校园建设&#xff0c;推动信息化与学习生活的深度融合。目前教育信息化配套设施建设存在“孤岛架构”&#xff0c;学生安全问题频发&#xff0c;技术发展迅速&#xff0c;家长对…

IT高手修炼手册(3)程序员命令

一、前言 程序员在日常工作中&#xff0c;掌握一些高效的快捷键可以大大提高编码和开发效率。 二、通用快捷键 文本操作Ctrl A&#xff1a;全选当前页面内容 Ctrl C&#xff1a;复制当前选中内容 Ctrl V&#xff1a;粘贴当前剪贴板内的内容 Ctrl X&#xff1a;剪切当前选中…

[图解]SysML和EA建模住宅安全系统-11-接口块

1 00:00:00,660 --> 00:00:04,480 接下来的步骤是定义系统上下文 2 00:00:04,960 --> 00:00:07,750 首先是图17.17 3 00:00:09,000 --> 00:00:10,510 系统上下文展示了 4 00:00:10,520 --> 00:00:12,510 ESS和外部系统、用户 5 00:00:12,520 --> 00:00:14,1…

C++初学者指南-4.诊断---地址检测器

C初学者指南-4.诊断—地址检测器 幻灯片 地址检测器&#xff08;ASan&#xff09; 适用编译器g,clang检测内存错误 内存泄露访问已经释放的内存访问不正确的堆栈区域 用额外的指令检测代码 运行时间增加约70%内存使用量大约增加了3倍 示例&#xff1a;检测空指针 使用地址…

leetcode力扣_双指针问题

141. 环形链表 思路&#xff1a;判断链表中是否有环是经典的算法问题之一。常见的解决方案有多种&#xff0c;其中最经典、有效的一种方法是使用 快慢指针&#xff08;Floyd’s Cycle-Finding Algorithm&#xff09;。 初始化两个指针&#xff1a;一个快指针&#xff08;fast&…

100+大屏模板,基于Vue 国产开源 IoT 物联网 Web 组态可视化 BI 数据分析工具

项目源码&#xff0c;文末联系小编 01 DataEase 可视化大屏 DataEase 是一个国产开源的数据可视化分析工具(BI工具)&#xff0c;旨在帮助用户快速分析数据并洞察业务趋势&#xff0c;以实现业务的改进与优化。它支持丰富的数据源连接&#xff0c;包括OLTP和OLAP数据库、数据仓库…