question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not find `.pyd` module while import torch_sparse

See original GitHub issue

📚 Installation

I want to have a taste of pytorch_geometric, so I installed the CPU-only version. No errors appeared while pip install. I encountered the FileNotFoundError while from torch_geometric.data import Data. I ensured that the .pyd file is placed exacty at the location I tried:

  • ❌ use virtualenv to install dependencies separately
  • find a similar issue. But I already adopted the similar way to install.
  • ☑️ use WSL2 to use Linux version, everything works

The problem can be reproduced on my laptop and desktop. I left the command i used to pip install the library at the Environment section. I did not used Anaconda or Miniconda

The check.py is quite naive, here it is

import torch
from torch_geometric.data import Data

edge_index = torch.tensor([[0, 1, 1, 2],
                           [1, 0, 2, 1]], dtype=torch.long)
x = torch.tensor([[-1], [0], [1]], dtype=torch.float)

data = Data(x=x, edge_index=edge_index

Here is the log where I first encountered the error.

PS E:\study\py-dev\torch-geo> python .\check.py
Traceback (most recent call last):
  File ".\check.py", line 2, in <module>
    from torch_geometric.data import Data
  File "C:\Users\scarl\AppData\Local\Programs\Python\Python38\lib\site-packages\torch_geometric\__init__.py", line 5, in <module>
    import torch_geometric.data
  File "C:\Users\scarl\AppData\Local\Programs\Python\Python38\lib\site-packages\torch_geometric\data\__init__.py", line 1, in <module>
    from .data import Data
  File "C:\Users\scarl\AppData\Local\Programs\Python\Python38\lib\site-packages\torch_geometric\data\data.py", line 8, in <module>
    from torch_sparse import coalesce, SparseTensor
  File "C:\Users\scarl\AppData\Local\Programs\Python\Python38\lib\site-packages\torch_sparse\__init__.py", line 14, in <module>
    torch.ops.load_library(importlib.machinery.PathFinder().find_spec(
  File "C:\Users\scarl\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\_ops.py", line 104, in load_library
    ctypes.CDLL(path)
  File "C:\Users\scarl\AppData\Local\Programs\Python\Python38\lib\ctypes\__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\scarl\AppData\Local\Programs\Python\Python38\Lib\site-packages\torch_sparse\_convert_cpu.pyd' (or one of its dependencies). Try using the full path with constructor syntax.

And here is the virtualenv error log (alike)

(venv) PS E:\study\py-dev\torch-geo> python .\check.py
Traceback (most recent call last):
  File ".\check.py", line 2, in <module>
    from torch_geometric.data import Data
  File "E:\study\py-dev\torch-geo\venv\lib\site-packages\torch_geometric\__init__.py", line 5, in <module>
    import torch_geometric.data
  File "E:\study\py-dev\torch-geo\venv\lib\site-packages\torch_geometric\data\__init__.py", line 1, in <module>
    from .data import Data
  File "E:\study\py-dev\torch-geo\venv\lib\site-packages\torch_geometric\data\data.py", line 8, in <module>
    from torch_sparse import coalesce, SparseTensor
  File "E:\study\py-dev\torch-geo\venv\lib\site-packages\torch_sparse\__init__.py", line 14, in <module>
    torch.ops.load_library(importlib.machinery.PathFinder().find_spec(
  File "E:\study\py-dev\torch-geo\venv\lib\site-packages\torch\_ops.py", line 104, in load_library
    ctypes.CDLL(path)
  File "c:\users\scarl\appdata\local\programs\python\python38\lib\ctypes\__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'E:\study\py-dev\torch-geo\venv\Lib\site-packages\torch_sparse\_convert_cpu.pyd' (or one of its dependencies). Try using the full path with constructor syntax

Environment

  • OS: Windows 10
  • Python version: Python 3.8.x
  • PyTorch version: 1.9.0
  • CUDA/cuDNN version: None
  • GCC version: None
  • How did you try to install PyTorch Geometric and its extensions (wheel, source): wheel
  • Any other relevant information:

Here is how I install Torch and PyTorch Geometric

pip3 install torch torchvision torchaudio
pip3 install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://pytorch-geometric.com/whl/torch-1.9.0+cpu.html

Checklist

  • I followed the installation guide.
  • I cannot find my error message in the FAQ.
  • ~I set up CUDA correctly and can compile CUDA code via nvcc.~
  • ~I do have multiple CUDA versions on my machine.~

Additional context

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
scarletfrankcommented, Jul 15, 2021

torch-scatter works fine

PS E:\study\py-dev\torch-geo> python 
Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch_scatter
>>> import torch_sparse
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\scarl\AppData\Local\Programs\Python\Python38\lib\site-packages\torch_sparse\__init__.py", line 14, in <module>
    torch.ops.load_library(importlib.machinery.PathFinder().find_spec(
  File "C:\Users\scarl\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\_ops.py", line 104, in load_library
    ctypes.CDLL(path)
  File "C:\Users\scarl\AppData\Local\Programs\Python\Python38\lib\ctypes\__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\scarl\AppData\Local\Programs\Python\Python38\Lib\site-packages\torch_sparse\_convert_cpu.pyd' (or one of its dependencies). Try using the full path with constructor syntax.
>>>

I will test it on another desktop and try to use the GPU version in a few days. I would comment more if I find any solutions.

0reactions
bobseboycommented, Sep 14, 2022

I solved my problem with this error. I simply had an old version of Torch and installed torch-scatter and torch-sparse pointing to a wheel with a newer PyTorch version with the -f pip flag (pip install -v torch-scatter -f https://pytorch-geometric.com/whl/torch-1.12.1+cu116.html).

Creating a new environment, installing the newest PyTorch version, and pointing to the correct wheel worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

install question · Issue #1994 · pyg-team/pytorch_geometric
FileNotFoundError : Could not find module 'D:\360Downloads\anaconda\Lib\site-packages\torch_sparse_convert.pyd' (or one of its dependencies). Try ...
Read more >
torch geometric error: FileNotFound: Could not find module ...
I solved my problem with this error. I simply had an old version of Torch and installed torch-scatter and torch-sparse pointing to a...
Read more >
Cannot import dynamic python libraries provided via .pyd and ...
I tried to import a module that is provided as a .pyd and a .dll file. Using CPython I can just run the...
Read more >
[pytorch] No module named torch-sparse error while using ...
After I've installed torch-geometric package which is an extended package of torch, it showed that “No module named torch-sparse”. 2.
Read more >
Issue 43105: [Windows] Can't import extension modules ...
If I attempt to import an extension module via something like this: from pkg import extmodule and it happens that "pkg" is found...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found