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.01
及 cuda 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
相关文章:

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的依赖库,这些依赖库需要对应上pyth…...

新型开发语言的试用感受-仓颉语言发布之际
经常听一些媒体介绍一些新型的开发语言,所以最近心血来潮,安装了几种感受了一些。 先看名气,如ziglang,网址为:Home ⚡Zig Programming Language 号称是可以取代C语言的一门新语言,其实我主要是受下面这篇…...

基于字典学习的地震数据降噪(MATLAB R2021B)
稀疏表示基于研究者们提出了许多变换基函数的方法逐渐成型,比如小波域,曲波域,dreamlet 域等,其原理是利用地震信号在变换域内的稀疏性和可分离性以去除噪声。继 Donoho发表非线性去噪方法-小波阈值萎缩方法,在后续的研…...

【Web】
1、配仓库 [rootlocalhost yum.repos.d]# vi rpm.repo ##本地仓库标准写法 [baseos] namemiaoshubaseos baseurl/mnt/BaseOS gpgcheck0 [appstream] namemiaoshuappstream baseurlfile:///mnt/AppStream gpgcheck0 2、挂载 [rootlocalhost ~]mount /dev/sr0 /mnt mount: /m…...

kafka-3
Kafka 消费组 consumer-offsets-N 稀疏索引 Kafka集群 集群搭建 集群启动和验证 Topic的意义 Topic和Partition 分区 副本 集群操作指令 多分区&多副本 多分区消费组 Rebalance机制 Rebalance机制处理流程 Rebalance机制-Range Rebalance机制-RoudRobin Rebalance机制-St…...

MySQL性能优化 二、表结构设计优化
1.设计中间表 设计中间表,一般针对于统计分析功能,或者实时性不高的需求。 2.设计冗余字段 为减少关联查询,创建合理的冗余字段(创建冗余字段还需要注意数据一致性问题) 3.折表 对于字段太多的大表,考…...

用HttpURLConnection复现http响应码405
目录 使用GET方法,访问GET接口,服务端返回405使用GET方法,访问POST接口,服务端返回405使用POST方法,访问GET接口,服务端返回405 使用GET方法,访问GET接口,服务端返回405 发生场景&a…...

2-27 基于matlab的一种混凝土骨料三维随机投放模型
基于matlab的一种混凝土骨料三维随机投放模型,为混凝土细观力学研究提供一种快捷的三维建模源代码。可设置骨料数量,边界距离、骨料大小等参数。程序已调通,可直接运行。 2-27 matlab 混凝土骨料三维随机投放模型 - 小红书 (xiaohongshu.com)…...

ISA95-Part4-业务流程的解析与设计思路
MES/MOM系统实现ISA-95标准的业务流程通常遵循以下思路,并包含一系列内容。 一、功能模块: 1. 需求分析与规划: - 确定业务流程需求,包括订单管理、生产调度、库存控制等,并规划如何将这些流程与MES/MOM系统集成。 2. 系统集成架构设计: - 设计一个系统集成架构,确保M…...

【Spring Cloud】一个例程快速了解网关Gateway的使用
Spring Cloud Gateway提供了一个在Spring生态系统之上构建的API网关,包括:Spring 5,Spring Boot 2和Project Reactor。Spring Cloud Gateway旨在提供一种简单而有效的路由方式,并为它们提供一些网关基本功能,例如&…...

仿哔哩哔哩视频app小程序模板源码
仿哔哩哔哩视频app小程序模板源码 粉色的哔哩哔哩手机视频网页,多媒体视频类微信小程序ui前端模板下载。包含:视频主页和播放详情页。 仿哔哩哔哩视频app小程序模板源码...

数据库存储引擎
MySQL体系结构 存储引擎 -- 查询建表语句 show create table account; -- 查询引擎 show engines; InnoDB 特点 DML操作遵循ACID模型,支持事务 行级锁,提高并发访问性能支持外键约束 文件 xxx.ibd:xxx代表的是表名,innoDB引擎的每张表都会对应这样…...

【单片机毕业设计选题24049】-基于STM32单片机的智能手表设计
系统功能: 显示时间,温湿度,体温信息,播放音乐及控制红外小夜灯,通过蓝牙模块连接手机APP。 系统上电后OLED显示“欢迎使用智能手表系统请稍后”,两秒后进入正常页面显示 第一行显示获取到的当前时间 第二行显示获…...

利用面向AWS的Thales Sovereign解决方案保护AI之旅
亚马逊网络服务(AWS)是全球最大的云服务提供商。众所周知,他们致力于提供工具、解决方案和最佳实践,使其客户能够安全地利用AWS上的生成式人工智能 (GenAI) 工作负载。组织正在迅速使用GenAI为企业带来更高的生产力和创造力。在GenAI的几乎所有用途中&am…...

学习笔记——交通安全分析13
目录 前言 当天学习笔记整理 5城市主干道交通安全分析 结束语 前言 #随着上一轮SPSS学习完成之后,本人又开始了新教材《交通安全分析》的学习 #整理过程不易,喜欢UP就点个免费的关注趴 #本期内容接上一期12笔记 当天学习笔记整理 5城市主干道交…...

PHP-实例-文件上传
1 需求 2 basename 在 PHP 中,basename() 函数用于返回路径中的文件名部分。如果路径中包含了文件扩展名,则该函数也会返回它。如果路径的结尾有斜杠(/)或反斜杠(\),则 basename() 函数会返回空…...

LeetCode刷题之HOT100之完全平方数
2024 7/7 转眼间就到周日啦!昨天下午开组会,开了三个半小时。如坐针毡,会后跑了个步、洗了个澡、洗了衣服、躺床上看了会《罪与罚》,睡着了。早上起来,去拿我昨晚充电的车,当我看到车没有停在昨天的位置&am…...

【SpringCloud应用框架】Nacos集群架构说明
第六章 Spring Cloud Alibaba Nacos之集群架构说明 文章目录 前言一、Nacos支持三种部署模式二、集群部署说明三、预备环境 前言 到目前为止,已经完成了对Nacos的一些基本使用和配置,接下来还需要了解一个非常重要的点,就是Nacos的集群相关的…...

JS进阶-作用域
学习目标: 掌握作用域 学习内容: 作用域局部作用域全局作用域作用域链JS垃圾回收机制拓展-JS垃圾回收机制-算法说明闭包变量提升 作用域: 作用域规定了变量能够被访问的"范围",离开了这个"范围"变量便不能被…...

stm32 使用GPIO模拟串口发送
在STM32微控制器上实现模拟串口输出(也称为软件串口或比特邦定(Bit-Banging)串口),主要是因为硬件上的UART资源有限或者为了特定需求而需要更多的串口通信接口。模拟串口意味着使用GPIO引脚模拟UART的TX(发…...

数据的统计探针:SKlearn中的统计分析方法
数据的统计探针:SKlearn中的统计分析方法 在数据科学领域,统计分析是理解和解释数据的关键工具。Scikit-learn(简称sklearn),作为Python中一个功能强大的机器学习库,提供了多种方法来进行数据的统计分析。…...

实例演示Kafka-Stream消息流式处理流程及原理
以下结合案例:统计消息中单词出现次数,来测试并说明kafka消息流式处理的执行流程 Maven依赖 <dependencies><dependency><groupId>org.apache.kafka</groupId><artifactId>kafka-streams</artifactId><exclusio…...

【博士每天一篇文献-综述】Threats, Attacks, and Defenses in Machine Unlearning A Survey
1 介绍 年份:2024 作者:刘子耀,陈晨,南洋理工大学 期刊: 未发表 引用量:6 Liu Z, Ye H, Chen C, et al. Threats, attacks, and defenses in machine unlearning: A survey[J]. arXiv preprint arXiv:2403…...

Python数据分析实战,运输车辆驾驶行为分析,案例教程编程实例课程详解
引言 运输车辆的安全驾驶行为分析是确保道路安全、提高运输效率的重要环节。随着数据采集技术的发展和数据分析工具的普及,利用Python进行数据分析已成为这一领域的重要工具。本文将详细介绍如何使用Python进行运输车辆驾驶行为分析,涵盖数据采集、数据预处理、数据分析及结果…...

网络安全法对等级保护中的权利和义务有何规范?
在数字时代的交响乐章中,网络安全法与等级保护共同编织了一曲关于权利与义务的和谐旋律。《中华人民共和国网络安全法》作为我国网络安全领域的基本法,对等级保护提出了明确的规范,旨在构建一个安全、有序的网络空间。本文将深入解析网络安全…...

苹果清理软件:让你的设备焕然一新
随着时间的推移,无论是Mac电脑还是iOS设备,都可能会因为积累的垃圾文件、缓存、未使用的应用和其他冗余数据而开始表现出性能下降。这不仅会占用宝贵的存储空间,还可能影响设备的响应速度和电池寿命。幸运的是,有多种苹果清理软件…...

vue前端通过sessionStorage缓存字典
正常来说,一个vue项目前端需要用到的一些翻译字典对象保存方式一般有多重, 新建js文件方式保存通过vuex方式保存通过sessionStorage保存通过localStorage保存 正常以上几点的保存方式是够用了。 但是,当有字典不能以文件方式保存并且字典量…...

React Redux使用@reduxjs/toolkit的hooks
关于redux的学习过程需要几个官网,有redux官网,React Redux官网和Redux Toolkit的官网。 其中后者的中文没有找到,不过其中的使用在React Redux官网的快速入门中有介绍。 现在一般不使用connect借接口了。 对于借助Redux Toolkit的React Redu…...

Rejetto HFS 服务器存在严重漏洞受到攻击
AhnLab 报告称 ,黑客正在针对旧版本的 Rejetto HTTP 文件服务器 (HFS) 注入恶意软件和加密货币挖矿程序。 然而,由于存在错误, Rejetto 警告用户不要使用 2.3 至 2.4 版本。 2.3m 版本在个人、小型团队、教育机构和测试网络文件共享的开发…...

Electron开发 - 如何在主进程Main中让node-fetch使用系统代理
背景 开发过程中,用户设置的系统代理是不同的,比如公司内的服务器,所以就要动态地使用系统代理来访问,但是主进程默认为控制台级别的请求,不走系统代理,除非你指定系统代理配置,这个就就有了这…...