Importing torchsparse (PyTorch) on Windows 10 not working
On Windows 10. I am testing someone's code which has the following imports:
import torch.nn as nn
import torchsparse.nn as spnn
from torchsparse.point_tensor import PointTensor

So on my machine I successfully installed via
pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-1.9.0+cu111.html

As I have CUDA 11.1. However, there seems to be a syntax difference, as the above imports give:
    import torchsparse.nn as spnn
ModuleNotFoundError: No module named 'torchsparse'

I found that when I am in Python I can do the following:
&gt;&gt;&gt; import torchsparse
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
ModuleNotFoundError: No module named 'torchsparse'
&gt;&gt;&gt; import torchsparse.nn
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
ModuleNotFoundError: No module named 'torchsparse'
&gt;&gt;&gt; import torch_sparse
&gt;&gt;&gt; import torch_sparse.nn
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
ModuleNotFoundError: No module named 'torch_sparse.nn'
&gt;&gt;&gt;

So I can only import torch_sparse. Does anyone know how I can get the equivalent imports to test my buddy's code? Much appreciated.
---- EDIT ----
Trying Ivan's answer, I got the following:
pip install --upgrade git+https://github.com/mit-han-lab/torchsparse.git@v1.4.0
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
Collecting git+https://github.com/mit-han-lab/torchsparse.git@v1.4.0
  Cloning https://github.com/mit-han-lab/torchsparse.git (to revision v1.4.0) to c:\users\iijds\appdata\local\temp\pip-req-build-gvmcjx1m
  Running command git clone -q https://github.com/mit-han-lab/torchsparse.git 'C:\Users\iiJDS\AppData\Local\Temp\pip-req-build-gvmcjx1m'
  Running command git checkout -q 74099d10a51c71c14318bce63d6421f698b24f24
  Resolved https://github.com/mit-han-lab/torchsparse.git to commit 74099d10a51c71c14318bce63d6421f698b24f24
Building wheels for collected packages: torchsparse
  Building wheel for torchsparse (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\python39\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '&quot;'&quot;'C:\\Users\\iiJDS\\AppData\\Local\\Temp\\pip-req-build-gvmcjx1m\\setup.py'&quot;'&quot;'; __file__='&quot;'&quot;'C:\\Users\\iiJDS\\AppData\\Local\\Temp\\pip-req-build-gvmcjx1m\\setup.py'&quot;'&quot;';f = getattr(tokenize, '&quot;'&quot;'open'&quot;'&quot;', open)(__file__) if os.path.exists(__file__) else io.StringIO('&quot;'&quot;'from setuptools import setup; setup()'&quot;'&quot;');code = f.read().replace('&quot;'&quot;'\r\n'&quot;'&quot;', '&quot;'&quot;'\n'&quot;'&quot;');f.close();exec(compile(code, __file__, '&quot;'&quot;'exec'&quot;'&quot;'))' bdist_wheel -d 'C:\Users\iiJDS\AppData\Local\Temp\pip-wheel-rz9wo9lc'
       cwd: C:\Users\iiJDS\AppData\Local\Temp\pip-req-build-gvmcjx1m\
  Complete output (53 lines):
  running bdist_wheel
  c:\python39\lib\site-packages\torch\utils\cpp_extension.py:370: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend.
    warnings.warn(msg.format('we could not find ninja.'))
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.9
  creating build\lib.win-amd64-3.9\torchsparse
  copying torchsparse\operators.py -&gt; build\lib.win-amd64-3.9\torchsparse
  copying torchsparse\tensor.py -&gt; build\lib.win-amd64-3.9\torchsparse
  copying torchsparse\version.py -&gt; build\lib.win-amd64-3.9\torchsparse
  copying torchsparse\__init__.py -&gt; build\lib.win-amd64-3.9\torchsparse
  creating build\lib.win-amd64-3.9\torchsparse\nn
  copying torchsparse\nn\__init__.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn
  creating build\lib.win-amd64-3.9\torchsparse\utils
  copying torchsparse\utils\collate.py -&gt; build\lib.win-amd64-3.9\torchsparse\utils
  copying torchsparse\utils\quantize.py -&gt; build\lib.win-amd64-3.9\torchsparse\utils
  copying torchsparse\utils\utils.py -&gt; build\lib.win-amd64-3.9\torchsparse\utils
  copying torchsparse\utils\__init__.py -&gt; build\lib.win-amd64-3.9\torchsparse\utils
  creating build\lib.win-amd64-3.9\torchsparse\nn\functional
  copying torchsparse\nn\functional\activation.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
  copying torchsparse\nn\functional\conv.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
  copying torchsparse\nn\functional\count.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
  copying torchsparse\nn\functional\crop.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
  copying torchsparse\nn\functional\devoxelize.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
  copying torchsparse\nn\functional\downsample.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
  copying torchsparse\nn\functional\hash.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
  copying torchsparse\nn\functional\pooling.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
  copying torchsparse\nn\functional\query.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
  copying torchsparse\nn\functional\voxelize.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
  copying torchsparse\nn\functional\__init__.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
  creating build\lib.win-amd64-3.9\torchsparse\nn\modules
  copying torchsparse\nn\modules\activation.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
  copying torchsparse\nn\modules\bev.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
  copying torchsparse\nn\modules\conv.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
  copying torchsparse\nn\modules\crop.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
  copying torchsparse\nn\modules\norm.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
  copying torchsparse\nn\modules\pooling.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
  copying torchsparse\nn\modules\__init__.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
  creating build\lib.win-amd64-3.9\torchsparse\nn\utils
  copying torchsparse\nn\utils\apply.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\utils
  copying torchsparse\nn\utils\kernel.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\utils
  copying torchsparse\nn\utils\__init__.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\utils
  running build_ext
  c:\python39\lib\site-packages\torch\utils\cpp_extension.py:305: UserWarning: Error checking compiler version for cl: [WinError 2] The system cannot find the file specified
    warnings.warn(f'Error checking compiler version for {compiler}: {error}')
  building 'torchsparse.backend' extension
  error: Microsoft Visual C++ 14.0 is required. Get it with &quot;Build Tools for Visual Studio&quot;: https://visualstudio.microsoft.com/downloads/
  Error in atexit._run_exitfuncs:
  Traceback (most recent call last):
    File &quot;c:\python39\lib\site-packages\colorama\ansitowin32.py&quot;, line 59, in closed
      return stream.closed
  ValueError: underlying buffer has been detached
  ----------------------------------------
  ERROR: Failed building wheel for torchsparse
  Running setup.py clean for torchsparse
Failed to build torchsparse
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
Installing collected packages: torchsparse
    Running setup.py install for torchsparse ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\python39\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '&quot;'&quot;'C:\\Users\\iiJDS\\AppData\\Local\\Temp\\pip-req-build-gvmcjx1m\\setup.py'&quot;'&quot;'; __file__='&quot;'&quot;'C:\\Users\\iiJDS\\AppData\\Local\\Temp\\pip-req-build-gvmcjx1m\\setup.py'&quot;'&quot;';f = getattr(tokenize, '&quot;'&quot;'open'&quot;'&quot;', open)(__file__) if os.path.exists(__file__) else io.StringIO('&quot;'&quot;'from setuptools import setup; setup()'&quot;'&quot;');code = f.read().replace('&quot;'&quot;'\r\n'&quot;'&quot;', '&quot;'&quot;'\n'&quot;'&quot;');f.close();exec(compile(code, __file__, '&quot;'&quot;'exec'&quot;'&quot;'))' install --record 'C:\Users\iiJDS\AppData\Local\Temp\pip-record-p7zn1m6h\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\python39\Include\torchsparse'
         cwd: C:\Users\iiJDS\AppData\Local\Temp\pip-req-build-gvmcjx1m\
    Complete output (53 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.9
    creating build\lib.win-amd64-3.9\torchsparse
    copying torchsparse\operators.py -&gt; build\lib.win-amd64-3.9\torchsparse
    copying torchsparse\tensor.py -&gt; build\lib.win-amd64-3.9\torchsparse
    copying torchsparse\version.py -&gt; build\lib.win-amd64-3.9\torchsparse
    copying torchsparse\__init__.py -&gt; build\lib.win-amd64-3.9\torchsparse
    creating build\lib.win-amd64-3.9\torchsparse\nn
    copying torchsparse\nn\__init__.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn
    creating build\lib.win-amd64-3.9\torchsparse\utils
    copying torchsparse\utils\collate.py -&gt; build\lib.win-amd64-3.9\torchsparse\utils
    copying torchsparse\utils\quantize.py -&gt; build\lib.win-amd64-3.9\torchsparse\utils
    copying torchsparse\utils\utils.py -&gt; build\lib.win-amd64-3.9\torchsparse\utils
    copying torchsparse\utils\__init__.py -&gt; build\lib.win-amd64-3.9\torchsparse\utils
    creating build\lib.win-amd64-3.9\torchsparse\nn\functional
    copying torchsparse\nn\functional\activation.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
    copying torchsparse\nn\functional\conv.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
    copying torchsparse\nn\functional\count.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
    copying torchsparse\nn\functional\crop.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
    copying torchsparse\nn\functional\devoxelize.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
    copying torchsparse\nn\functional\downsample.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
    copying torchsparse\nn\functional\hash.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
    copying torchsparse\nn\functional\pooling.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
    copying torchsparse\nn\functional\query.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
    copying torchsparse\nn\functional\voxelize.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
    copying torchsparse\nn\functional\__init__.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\functional
    creating build\lib.win-amd64-3.9\torchsparse\nn\modules
    copying torchsparse\nn\modules\activation.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
    copying torchsparse\nn\modules\bev.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
    copying torchsparse\nn\modules\conv.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
    copying torchsparse\nn\modules\crop.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
    copying torchsparse\nn\modules\norm.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
    copying torchsparse\nn\modules\pooling.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
    copying torchsparse\nn\modules\__init__.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\modules
    creating build\lib.win-amd64-3.9\torchsparse\nn\utils
    copying torchsparse\nn\utils\apply.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\utils
    copying torchsparse\nn\utils\kernel.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\utils
    copying torchsparse\nn\utils\__init__.py -&gt; build\lib.win-amd64-3.9\torchsparse\nn\utils
    running build_ext
    c:\python39\lib\site-packages\torch\utils\cpp_extension.py:370: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend.
      warnings.warn(msg.format('we could not find ninja.'))
    c:\python39\lib\site-packages\torch\utils\cpp_extension.py:305: UserWarning: Error checking compiler version for cl: [WinError 2] The system cannot find the file specified
      warnings.warn(f'Error checking compiler version for {compiler}: {error}')
    building 'torchsparse.backend' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with &quot;Build Tools for Visual Studio&quot;: https://visualstudio.microsoft.com/downloads/
    Error in atexit._run_exitfuncs:
    Traceback (most recent call last):
      File &quot;c:\python39\lib\site-packages\colorama\ansitowin32.py&quot;, line 59, in closed
        return stream.closed
    ValueError: underlying buffer has been detached
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\python39\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '&quot;'&quot;'C:\\Users\\iiJDS\\AppData\\Local\\Temp\\pip-req-build-gvmcjx1m\\setup.py'&quot;'&quot;'; __file__='&quot;'&quot;'C:\\Users\\iiJDS\\AppData\\Local\\Temp\\pip-req-build-gvmcjx1m\\setup.py'&quot;'&quot;';f = getattr(tokenize, '&quot;'&quot;'open'&quot;'&quot;', open)(__file__) if os.path.exists(__file__) else io.StringIO('&quot;'&quot;'from setuptools import setup; setup()'&quot;'&quot;');code = f.read().replace('&quot;'&quot;'\r\n'&quot;'&quot;', '&quot;'&quot;'\n'&quot;'&quot;');f.close();exec(compile(code, __file__, '&quot;'&quot;'exec'&quot;'&quot;'))' install --record 'C:\Users\iiJDS\AppData\Local\Temp\pip-record-p7zn1m6h\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\python39\Include\torchsparse' Check the logs for full command output.


It appears the package you are trying to import comes from this Github repo, which is different to the package you installed: torch-sparse you tried using. You should try with this instead:
pip install --upgrade git+https://github.com/mit-han-lab/torchsparse.git@v1.4.0

Also, you can uninstall the other one with:
pip uninstall torch-sparse

