pytorch_sparse: AttributeError: 'NoneType' object has no attribute 'origin'

I am using torch-sparse version 0.6.8 as a dependency for a project I am working on.

However, I get the following error inside the torch_sparse/__init__.py file: torch.ops.load_library(importlib.machinery.PathFinder().find_spec( AttributeError: 'NoneType' object has no attribute 'origin'

It seems that the find_spec() call returns None.

I am running on CUDA on Ubuntu and using torch version 1.7.1 and torch-scatter version 2.0.5 Do you know how I can resolve this error?

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 5
  • Comments: 22 (6 by maintainers)

Most upvoted comments

Did you install the CUDA package, e.g. via https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html? Otherwise, you may try to install with the --no-index option, i.e.

pip install --no-index torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.0+{CUDA}.html

I will leave my 50 cents here, I tried other methods to solve this problem but then but just got other issues 😅 I solved them by updating to PyTorch 1.8.1 and CUDA to 11.1 (using Ubuntu 20.04). Here are the steps:

  1. Update CUDA to the latest version. NOTE: if you encounter problems with the CUDA installation, follow this solution (basically purge the Nvidia drivers and reinstall them so to avoid problems with dependencies)
  2. Install latest version of torch with cuda by running this (from PyTorch webpage)
pip3 install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
  1. Install torch-geometric and its dependencies this in your terminal (from the PyTorch Geometric installation guide):
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html
pip install torch-geometric

This issue has not been solved.

Thanks for your reply. I have now resolved the issue. The *.so files were getting created in the torch_sparse folder. The problem was that the cuda .so files weren’t getting created. I had to change the torch_sparse and torch_cluster versions. I don’t believe I had multiple torch_sparse versions.

I met the same problem and fixed it by installing cuda package. Check if ‘/usr/local/cuda-11.x’ is existing. If you only install ‘cuda toolkit’ in conda virtual env, you can’t find it. (refer to below explanation)

image

My solution is:

  1. install ‘cuda’ (not in conda virtual env)
  2. install torch_geometric in conda virtual env using below commands conda create -n XXX python=3.8 conda activate XXX conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge conda install pytorch-geometric -c rusty1s -c conda-forge

Please install via --no-index option for later PyTorch versions:

pip install --no-index torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html
pip install --no-index torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html
pip install --no-index torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html
pip install --no-index torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html

Hi all, currently experiencing this issue only when I run torch on GPU, but everything works fine. I usually use torch==1.12.1+cu116, but had to downgrade to torch==1.8.1+cu111 to be able to import torch_geometric on just CPU. This is the error I get when I try and import torch_geometric on GPU:

Python 3.8.2 (default, Jun 2 2020, 16:34:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux Type “help”, “copyright”, “credits” or “license” for more information.

import torch torch.version ‘1.8.1+cu111’ import torch_geometric Traceback (most recent call last): File “<stdin>”, line 1, in <module> File “/home/widatall/cuda111/lib/python3.8/site-packages/torch_geometric/init.py”, line 5, in <module> import torch_geometric.data File “/home/widatall/cuda111/lib/python3.8/site-packages/torch_geometric/data/init.py”, line 1, in <module> from .data import Data File “/home/widatall/cuda111/lib/python3.8/site-packages/torch_geometric/data/data.py”, line 8, in <module> from torch_sparse import coalesce, SparseTensor File “/home/widatall/cuda111/lib/python3.8/site-packages/torch_sparse/init.py”, line 14, in <module> torch.ops.load_library(importlib.machinery.PathFinder().find_spec( AttributeError: ‘NoneType’ object has no attribute ‘origin’

I installed all packages as per PyTorch guidelines:

pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html pip install torch-geometric

In regard to the .so files, I am having the issue of only having *_cpu.so files and no *_cuda.so files in my torch_sparse, torch_scatter etc. directories in the site-packages/ directory of my venv. Any help on this would be greatly appreciated as I am currently trying to train a transformer+GCNN on just cpu… which will be done when I’m 90 years old.

There is also a PyTorch conda package in conda-forge which is picked up (rather than the one from the -c pytorch channel). Swapping the order of channels, i.e., putting pytorch before conda-forge, should fix this.