解决PyG (PyTorch Geometric)库安装以及import时sklearn报错等问题

解决PyG (PyTorch Geometric)库安装以及import时sklearn报错等问题

2021-3-26 By Junwu Chen at CAS IPE, Beijing

1.安装pytorch

由于我们组服务器的linux系统版本太老,glibc版本低于2.17且没有root权限,所以我通过conda的方法安装pytorch(安装PyG前需要先安装torch)。conda安装pytorch的方法可以见我的博文。

2. 安装PyG

安装方法可见官方手册。
如我输入的安装命令为:

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.6.0+cpu.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.6.0+cpu.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.6.0+cpu.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.6.0+cpu.html
pip install torch-geometric

但是在最后一步(安装torch-geometric)时会报错,原因是其所依赖的numba库安装不上,我的解决方法是采用conda安装numba:

conda install numba

但是安装好后,在import torch_geometric时会报错:

Traceback (most recent call last):
  File "/home/jwchen/software/miniconda3/envs/pyg/lib/python3.6/site-packages/sklearn/__check_build/__init__.py", line 44, in 
    from ._check_build import check_build  # noqa
ImportError: dlopen: cannot load any more object with static TLS

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 1, in 
  File "/home/jwchen/software/miniconda3/envs/pyg/lib/python3.6/site-packages/torch_geometric/__init__.py", line 2, in 
    import torch_geometric.nn
  File "/home/jwchen/software/miniconda3/envs/pyg/lib/python3.6/site-packages/torch_geometric/nn/__init__.py", line 10, in 
    from .models import *  # noqa
  File "/home/jwchen/software/miniconda3/envs/pyg/lib/python3.6/site-packages/torch_geometric/nn/models/__init__.py", line 2, in 
    from .node2vec import Node2Vec
  File "/home/jwchen/software/miniconda3/envs/pyg/lib/python3.6/site-packages/torch_geometric/nn/models/node2vec.py", line 5, in 
    from sklearn.linear_model import LogisticRegression
  File "/home/jwchen/software/miniconda3/envs/pyg/lib/python3.6/site-packages/sklearn/__init__.py", line 81, in 
    from . import __check_build  # noqa: F401
  File "/home/jwchen/software/miniconda3/envs/pyg/lib/python3.6/site-packages/sklearn/__check_build/__init__.py", line 46, in 
    raise_build_error(e)
  File "/home/jwchen/software/miniconda3/envs/pyg/lib/python3.6/site-packages/sklearn/__check_build/__init__.py", line 41, in raise_build_error
    %s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
ImportError: dlopen: cannot load any more object with static TLS
___________________________________________________________________________
Contents of /home/jwchen/software/miniconda3/envs/pyg/lib/python3.6/site-packages/sklearn/__check_build:
__init__.py               __pycache__               _check_build.cpython-36m-x86_64-linux-gnu.so
setup.py
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.

这原因主要来自sklearn库的问题。

解决方法1:

安装低版本的sklearn

pip uninstall scikit-learn torch-geometric
pip install scikit-learn==0.20.3
pip install torch-geometric

解决方法2:

conda安装sklearn

pip uninstall scikit-learn torch-geometric
conda install scikit-learn
pip install torch-geometric

你可能感兴趣的:(deep,learning,linux,python,pytorch,深度学习)