pytorch_scatter: Compilation error on Windows 10 with VS2019

Compilation fails with the following error: ...\pytorch_scatter\csrc\cpu\scatter_cpu.cpp(81): error C2975: 'REDUCE': invalid template argument for 'Reducer', expected compile-time constant expression

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 30 (14 by maintainers)

Most upvoted comments

I identified the issue! The following lines are missing in all extensions:

#ifdef _WIN32
#include <Python.h>
PyMODINIT_FUNC PyInit__scatter(void) { return NULL; }
#endif

I will run some more tests and will release a new version soon! Sorry for all the trouble 😃

Windows installation indeed needs some fixes to Pytorch, see here. I am still unsure why the installation of the binaries does not work for some. Can you try to do:

pip install https://s3.eu-central-1.amazonaws.com/pytorch-geometric.com/whl/torch-1.4.0/torch_scatter-latest%2Bcu101-cp37-cp37m-win_amd64.whl

pip install torch-scatter==latest+cu101 -f http://pytorch-scatter.s3-website.eu-central-1.amazonaws.com/whl/torch-1.4.0.html --trusted-host pytorch-scatter.s3-website.eu-central-1.amazonaws.com

works for me using python 3.7, CUDA10.1, and pytorch 1.4.0. Tested the sample code in the README.md and it is working.

I’ll also mention that I was able to successfully install torch-geometric. To do this I:

  1. Installed torch-scatter pip install torch-scatter==latest+cu101 -f http://pytorch-scatter.s3-website.eu-central-1.amazonaws.com/whl/torch-1.4.0.html --trusted-host pytorch-scatter.s3-website.eu-central-1.amazonaws.com
  2. Installed torch-sparse pip install torch-sparse==latest+cu101 -f http://pytorch-sparse.s3-website.eu-central-1.amazonaws.com/whl/torch-1.4.0.html --trusted-host pytorch-sparse.s3-website.eu-central-1.amazonaws.com
  3. Installed torch-cluster pip install torch-cluster
  4. Installed torch-geometric pip install torch-geometric

You can now install using HTTPS:

pip install torch-scatter==latest+${CUDA} -f https://s3.eu-central-1.amazonaws.com/pytorch-geometric.com/whl/torch-1.4.0.html

I am also working on a conda package that should eliminate the need of -f installs.

I applied the potential fix changing “static constexpr size_t --> static const size_t” for all the affected lines in argument_spec.h and module.h as well as the pybind11 cast.h (1449) return *(this->value); --> return *((type*)this->value);

I no longer received the 5 errors earlier posted. However, I was getting link errors after that. I tried python setup.py install again and I didn’t get the link error from the previous build but a new one. After I executed “python setup.py install” three times it said it installed torch_scatter. The 3 link errors are related to the 3 binaries (_scatter.pyd, _segmetn_coo.pyd, and _segment_csr.pyd) that are produced from the build. E.g.

LINK : error LNK2001: unresolved external symbol PyInit__scatter build\temp.win-amd64-3.7\Release\Development\pytorch_scatter\csrc_scatter.lib : fatal error LNK1120: 1 unresolved externals error: command ‘C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\bin\HostX86\x64\link.exe’ failed with exit status 1120

After it installed I inspected these files, and all of them were 0 KB in size. So although it said it was successfully built, it did not.

I confirmed this by running the test on the README.md. When trying to import the scatter_max module 3 errors are produced: Failed to load ‘scatter’, ‘segment_csr’, and ‘segment_coo’ binaries.

Thank you, @rusty1s ! I’m not using pytorch_scatter, which means I’m probably in the wrong place, but your link for the Windows install fixed to Pytorch was exactly the solution I needed. I’m not sure how to get torch.sh to run automatically, using my local paths, but I was able to go through line by line and manually fix my files.

Should work again!