成功解决 OSError: libcusparse.so.11: cannot open shared object file: No such file or directory

2022-10-25 18:30:56 浏览数 (3)


新建一个干净的虚拟环境,安装配置 BIONIC

代码语言:javascript复制
conda create -n BIONIC python=3.8
conda activate BIONIC


pip install torch-scatter==2.0.9 -f https://pytorch-geometric.com/whl/torch-1.9.0 cu111.html
pip install torch-cluster==1.5.9 -f https://pytorch-geometric.com/whl/torch-1.9.0 cu111.html
pip install torch-sparse==0.6.12 -f https://pytorch-geometric.com/whl/torch-1.9.0 cu111.html
pip install torch-spline-conv==1.2.1 -f https://pytorch-geometric.com/whl/torch-1.9.0 cu111.html
pip install torch-geometric==1.7.2 -f https://pytorch-geometric.com/whl/torch-1.9.0 cu111.html

pip install torch==1.9.0 cu111 torchvision==0.10.0 cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

pip install https://github.com/bowang-lab/BIONIC/releases/download/v0.2.4/bionic_model-0.2.4 cu111-cp38-cp38-linux_x86_64.whl

然后执行 bionic --help 指令发生报错:

代码语言:javascript复制
bionic --help
代码语言:javascript复制
Traceback (most recent call last):
  File "/home/cenghaolong/anaconda3/envs/BIONIC/bin/bionic", line 5, in <module>
    from bionic.cli import main
  File "/home/cenghaolong/anaconda3/envs/BIONIC/lib/python3.8/site-packages/bionic/cli.py", line 4, in <module>
    from .train import Trainer
  File "/home/cenghaolong/anaconda3/envs/BIONIC/lib/python3.8/site-packages/bionic/train.py", line 18, in <module>
    from .utils.preprocessor import Preprocessor
  File "/home/cenghaolong/anaconda3/envs/BIONIC/lib/python3.8/site-packages/bionic/utils/preprocessor.py", line 17, in <module>
    from torch_geometric.transforms import ToSparseTensor
  File "/home/cenghaolong/anaconda3/envs/BIONIC/lib/python3.8/site-packages/torch_geometric/__init__.py", line 5, in <module>
    import torch_geometric.data
  File "/home/cenghaolong/anaconda3/envs/BIONIC/lib/python3.8/site-packages/torch_geometric/data/__init__.py", line 1, in <module>
    from .data import Data
  File "/home/cenghaolong/anaconda3/envs/BIONIC/lib/python3.8/site-packages/torch_geometric/data/data.py", line 8, in <module>
    from torch_sparse import coalesce, SparseTensor
  File "/home/cenghaolong/anaconda3/envs/BIONIC/lib/python3.8/site-packages/torch_sparse/__init__.py", line 15, in <module>
    torch.ops.load_library(importlib.machinery.PathFinder().find_spec(
  File "/home/cenghaolong/anaconda3/envs/BIONIC/lib/python3.8/site-packages/torch/_ops.py", line 104, in load_library
    ctypes.CDLL(path)
  File "/home/cenghaolong/anaconda3/envs/BIONIC/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libcusparse.so.11: cannot open shared object file: No such file or directory

具体情况是:安装了 torch-geometric 和 torch-sparse(官网安装说明:PyG Documentation — pytorch_geometric documentation)后,导入 torch-sparse 时却报错。

谷歌搜索啥的也没找到啥简洁有效解决方案,都是说 CUDA 版本啥的,得改改配置,重新装东西,很麻烦。最快解决方案如下:

  • 在 /home/cenghaolong/anaconda3/envs/BIONIC/lib(你建的虚拟环境的 lib 文件夹) 中放入缺少的 libcusparse.so.11 文件。
  • 如果仍然报错,则在 /home/user/.bashrc 文件最下面,加入下述一行。注意,此路径下需包含 libcusparse.so.11 文件。

具体操作如下:

代码语言:javascript复制
vi  ~/.bashrc      # 打开.bashrc 文件     i 键进入编辑模式
export LD_LIBRARY_PATH="/home/cenghaolong/anaconda3/envs/BIONIC/lib"
加入上面的指令后,esc 退出编辑模式   :wq 保存并退出   然后 source 激活一下
source ~/.bashrc

成功解决问题,没有报错了:


  • BIONIC | Biological Network Integration using Convolutions
  • 【最快解决方案】安装torch-geometric报错 libcusparse.so.11: cannot open shared object file: No such file or dir
  • Ubuntu ——打开.bashrc文件编辑并保存退出

0 人点赞