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-geometricDownloading 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: _ZNK5torch8autograd4Node4nameEvwarnings.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: _ZN5torch3jit17parseSchemaOrNameERKSswarnings.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: _ZN5torch3jit17parseSchemaOrNameERKSswarnings.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: _ZN5torch3jit17parseSchemaOrNameERKSswarnings.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: _ZN5torch3jit17parseSchemaOrNameERKSswarnings.warn(f"An issue occurred while importing 'torch-sparse'. "
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In[1], line 1
----> 1 import torch_geometric.datasetsFile ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/__init__.py:1311 import torch_geometric.loader12 import torch_geometric.transforms
---> 13 import torch_geometric.datasets14 import torch_geometric.nn15 import torch_geometric.explainFile ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/datasets/__init__.py:10199 from .sbm_dataset import RandomPartitionGraphDataset100 from .mixhop_synthetic_dataset import MixHopSyntheticDataset
--> 101 from .explainer_dataset import ExplainerDataset102 from .infection_dataset import InfectionDataset103 from .ba2motif_dataset import BA2MotifDatasetFile ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/datasets/explainer_dataset.py:97 from torch_geometric.datasets.graph_generator import GraphGenerator8 from torch_geometric.datasets.motif_generator import MotifGenerator
----> 9 from torch_geometric.explain import Explanation12 class ExplainerDataset(InMemoryDataset):13     r"""Generates a synthetic dataset for evaluating explainabilty algorithms,14     as described in the `"GNNExplainer: Generating Explanations for Graph15     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:31 from .config import ExplainerConfig, ModelConfig, ThresholdConfig2 from .explanation import Explanation, HeteroExplanation
----> 3 from .algorithm import *  # noqa4 from .explainer import Explainer5 from .metric import *  # noqaFile ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/explain/algorithm/__init__.py:1
----> 1 from .base import ExplainerAlgorithm2 from .dummy_explainer import DummyExplainer3 from .gnn_explainer import GNNExplainerFile ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/explain/algorithm/base.py:148 from torch_geometric.explain import Explanation, HeteroExplanation9 from torch_geometric.explain.config import (10     ExplainerConfig,11     ModelConfig,12     ModelReturnType,13 )
---> 14 from torch_geometric.nn import MessagePassing15 from torch_geometric.typing import EdgeType, NodeType16 from torch_geometric.utils import k_hop_subgraphFile ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/nn/__init__.py:53 from .data_parallel import DataParallel4 from .to_hetero_transformer import to_hetero
----> 5 from .to_hetero_with_bases_transformer import to_hetero_with_bases6 from .to_fixed_size_transformer import to_fixed_size7 from .encoding import PositionalEncoding, TemporalEncodingFile ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/nn/to_hetero_with_bases_transformer.py:96 from torch import Tensor7 from torch.nn import Module, Parameter
----> 9 from torch_geometric.nn.conv import MessagePassing10 from torch_geometric.nn.dense import Linear11 from torch_geometric.nn.fx import TransformerFile ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/nn/conv/__init__.py:86 from .cugraph.sage_conv import CuGraphSAGEConv7 from .graph_conv import GraphConv
----> 8 from .gravnet_conv import GravNetConv9 from .gated_graph_conv import GatedGraphConv10 from .res_gated_graph_conv import ResGatedGraphConvFile ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_geometric/nn/conv/gravnet_conv.py:1310 from torch_geometric.typing import OptTensor, PairOptTensor, PairTensor12 try:
---> 13     from torch_cluster import knn14 except ImportError:15     knn = NoneFile ~/miniconda3/envs/pyt-gpu-2.0/lib/python3.9/site-packages/torch_cluster/__init__.py:1816 spec = cuda_spec or cpu_spec17 if spec is not None:
---> 18     torch.ops.load_library(spec.origin)19 else:  # pragma: no cover20     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 its641     # static (global) initialization code in order to register custom642     # 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 = _FuncPtr381 if handle is None:
--> 382     self._handle = _dlopen(self._name, mode)383 else:384     self._handle = handleOSError: /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_geometricA 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_ipythonreturn 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_instanceapp.start()File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/terminal/ipapp.py", line 317, in startself.shell.mainloop()File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 917, in mainloopself.interact()File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 910, in interactself.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_cellresult = self._run_cell(File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3130, in _run_cellresult = runner(coro)File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/core/async_helpers.py", line 129, in _pseudo_sync_runnercoro.send(None)File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3334, in run_cell_asynchas_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_nodesif 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_codeexec(code_obj, self.user_global_ns, self.user_ns)File "<ipython-input-1-c36e13293883>", line 1, in <module>import torch_geometricFile "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch_geometric/__init__.py", line 5, in <module>from .isinstance import is_torch_instanceFile "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch_geometric/isinstance.py", line 8, in <module>import torch._dynamoFile "/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 disablereturn 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 checkreturn check_verbose(obj, is_inlined_call).skippedFile "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/_dynamo/trace_rules.py", line 3361, in check_verboserule = 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_innerrule = 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_mapobj = load_object(k)File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/site-packages/torch/_dynamo/trace_rules.py", line 2811, in load_objectval = _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_strreturn getattr(importlib.import_module(module), obj_name)File "/home/myPC/miniconda3/envs/pyg/lib/python3.10/importlib/__init__.py", line 126, in import_modulereturn _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.pswp.cn/diannao/42761.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/42761.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/42761.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

貝葉斯優化包的基礎介紹

以下為該學習地址的學習筆記 學習地址&#xff1a;Basic tour of the Bayesian Optimization package — Bayesian Optimization documentation 貝葉斯優化簡介 貝葉斯優化是一種基于貝葉斯推斷和高斯過程的全局優化方法&#xff0c;它試圖在盡可能少的迭代次數內找到一個未…

【Dison夏令營 Day 12】如何用 Python 構建數獨游戲

通過本綜合教程&#xff0c;學習如何使用 Pygame 在 Python 中創建自己的數獨游戲。本指南涵蓋安裝、游戲邏輯、用戶界面和計時器功能&#xff0c;是希望創建功能性和可擴展性數獨益智游戲的愛好者的理想之選。 數獨是一種經典的數字謎題&#xff0c;多年來一直吸引著謎題愛好…

實例方法與靜態方法的區別與使用場景

實例方法與靜態方法的區別與使用場景 大家好&#xff0c;我是免費搭建查券返利機器人省錢賺傭金就用微賺淘客系統3.0的小編&#xff0c;也是冬天不穿秋褲&#xff0c;天冷也要風度的程序猿&#xff01; 實例方法與靜態方法的區別 在面向對象編程中&#xff0c;方法可以分為實…

昇思MindSpore25天學習Day19:CycleGAN圖像風格遷移互換

(TOC)[CycleGAN圖像風格遷移呼喚] 模型介紹 模型簡介 CycleGAN(Cycle Generative Adversaial Network)即循環對抗生成網絡&#xff0c;來自論文Link:Unpaired lmage-to-mage Translation using Cycle-Consistent AdvesairalNetworks該模型實現了—種在沒有配對示例的情況下學…

從nginx返回404來看http1.0和http1.1的區別

序言 什么樣的人可以稱之為有智慧的人呢&#xff1f;如果下一個定義&#xff0c;你會如何來定義&#xff1f; 所謂智慧&#xff0c;就是能區分自己能改變的部分&#xff0c;自己無法改變的部分&#xff0c;努力去做自己能改變的&#xff0c;而不要天天想著那些無法改變的東西&a…

解析Java中的反射機制及其應用場景

解析Java中的反射機制及其應用場景 大家好&#xff0c;我是微賺淘客系統3.0的小編&#xff0c;也是冬天不穿秋褲&#xff0c;天冷也要風度的程序猿&#xff01; Java的反射機制是指在運行時可以動態地獲取類的信息&#xff08;如類名、方法、字段等&#xff09;&#xff0c;并…

麒麟桌面操作系統上網絡設置界面消失的解決方法

原文鏈接&#xff1a;麒麟桌面操作系統上網絡設置界面消失的解決方法 Hello&#xff0c;大家好啊&#xff01;今天給大家帶來一篇關于麒麟桌面操作系統上網絡設置界面消失解決方法的文章。在使用麒麟桌面操作系統時&#xff0c;可能會遇到網絡設置界面突然消失的情況&#xff…

斯坦福CS224n深度學習培訓營課程

自然語言處理領域的經典課程涵蓋了從基礎知識到最新研究的全面內容。本培訓營將精選課程內容&#xff0c;結合實際案例和項目實踐&#xff0c;帶領學員深入探索自然語言處理的前沿&#xff0c;學習最先進的深度學習技術。 課程大小&#xff1a;2.6G 課程下載&#xff1a;http…

Softmax函數的意義

來自GPT&#xff0c;后期會再整理。。。 Softmax函數在深度學習中&#xff0c;特別是在多分類任務中&#xff0c;被廣泛用作輸出層的激活函數。它將模型的原始輸出&#xff08;logits&#xff09;轉化為概率分布&#xff0c;使得每個類別的概率總和為1。相比于簡單地使用“單個…

四自由度SCARA機器人的運動學和動力學matlab建模與仿真

目錄 1.課題概述 2.系統仿真結果 3.核心程序與模型 4.系統原理簡介 5.完整工程文件 1.課題概述 針對SCARA 機器人系統進行了深入研究與探討&#xff0c;提出SCARA機器人的動力學模型和運動學模型&#xff0c;并以MATLAB軟件為仿真平臺&#xff0c;通過MATLAB Robotics Too…

java核心-泛型

目錄 概述什么是泛型分類泛型類泛型接口泛型方法 泛型通配符分類 泛型類型擦除分類無限制類型擦除有限制類型擦除 問題需求第一種第二種 概述 了解泛型有利于學習 jdk 、中間件的源碼&#xff0c;提升代碼抽象能力&#xff0c;封裝通用性更強的組件。 什么是泛型 在定義類、接…

二手閑置平臺小程序的設計

管理員賬戶功能包括&#xff1a;系統首頁&#xff0c;個人中心&#xff0c;用戶管理&#xff0c;賣家管理&#xff0c;商品分類管理&#xff0c;商品信息管理&#xff0c;商品購買管理&#xff0c;商品配送管理 微信端賬號功能包括&#xff1a;系統首頁&#xff0c;商品信息&a…

qt中connect函數的使用方法

bool QObject::connect(const QObject *sender, const char *signal,const QObject *receiver, const char *method,Qt::ConnectionType type Qt::AutoConnection);1.sender: 一個指向信號發送者的QObject指針。這是發出信號的對象&#xff0c;可以是任何繼承自QObject的類的實…

【linux服務器】大語言模型實戰教程:LLMS大模型部署到個人服務器或嵌入式開發板(保姆級教學)

&#x1f3ac; 鴿芷咕&#xff1a;個人主頁 &#x1f525; 個人專欄: 《C干貨基地》《粉絲福利》 ??生活的理想&#xff0c;就是為了理想的生活! 引言 說到大語言模型相信大家都不會陌生&#xff0c;大型語言模型(LLMs)是人工智能文本處理的主要類型,也現在最流行的人工智能…

基于Java+SpringMvc+Vue技術智慧校園系統設計與實現--60頁及以上論文參考

博主介紹&#xff1a;碩士研究生&#xff0c;專注于信息化技術領域開發與管理&#xff0c;會使用java、標準c/c等開發語言&#xff0c;以及畢業項目實戰? 從事基于java BS架構、CS架構、c/c 編程工作近16年&#xff0c;擁有近12年的管理工作經驗&#xff0c;擁有較豐富的技術架…

網絡基礎:園區網絡架構

園區網絡 園區網絡&#xff08;Campus Network&#xff09;是指在一個相對較大的區域內&#xff0c;如大學校園、企業園區或政府機關等&#xff0c;建立的計算機網絡系統。園區網絡根據規模的不同&#xff0c;可以分為以下幾種類型&#xff1a; ①小型園區網絡&#xff1a;通常…

WebKit中Websockets的全面支持:實現高效實時通信

WebKit中Websockets的全面支持&#xff1a;實現高效實時通信 Websockets是一種網絡通信協議&#xff0c;它允許在單個TCP連接上進行全雙工通信&#xff0c;從而實現服務器與客戶端之間的實時數據交換。WebKit作為許多流行瀏覽器的底層引擎&#xff0c;對Websockets提供了全面的…

Java 多線程工具類 Semaphore

引言 在多線程編程中&#xff0c;控制對共享資源的訪問是一個關鍵問題。Java 提供了多種同步機制來解決這個問題&#xff0c;其中 Semaphore 是一種常用的工具類&#xff0c;用于限制可以同時訪問某個資源的線程數。本文將詳細介紹 Semaphore 的概念、使用方法和實際應用場景。…

ARM GEC6818 LCD繪圖 實心圓 三角形 五角星 任意區域矩形以及旗幟

要在ARM上實現LCD繪圖,可以按照以下步驟進行: 硬件初始化:初始化LCD控制器和相關引腳,配置時鐘、分辨率和顏色深度等。 內存映射:將LCD顯示區域映射到ARM的內存地址空間中,可以通過ARM的內存映射機制來實現。 繪圖函數:實現繪制基本圖形的函數,如點、線、矩形、圓等。可…

【系統架構設計師】八、系統工程基礎知識(系統工程|系統性能)

目錄 一、系統工程 1.1 系統工程的方法 1.1.1 霍爾的三維結構 1.1.2 切克蘭德方法 1.1.3 并行工程方法 1.1.4 綜合集成法 1.1.5.WSR 系統方法。 二、系統工程生命周期 2.1 系統工程生命周期7階段 2.2 生命周期方法 三、基于模型的系統工程(MBSE) 四、系統性能 4.1…