pytorch_sparse
pytorch_sparse copied to clipboard
Issues installing pytorch-sparse on macOS (with METIS)
Hello, I'm having some issues correctly installing pytorch sparse with METIS support on a Mac with apple silicon. I'm trying to install for pytorch 2.1.0, without any CUDA support.
Initially, I installed as follows:
CUDA=cpu
pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-2.1.0+${CUDA}.html
However, I was running into following issues when eventually trying to import
$ python
>>> from torch_sparse import SparseTensor, set_diag
...
...
OSError: dlopen(~/miniconda3/envs/gnnc/lib/python3.11/site-packages/torch_sparse/_metis_cpu.so, 0x0006): symbol not found in flat namespace '_METIS_PartGraphKway'
I continued by installing METIS as suggested in the docs. Here is the history of commands I used:
# Remove existing installations, and clear cache so pip doesn't reuse downloaded ones.
pip uninstall torch-scatter torch-sparse
pip cache remove torch-scatter
pip cache remove torhc-sparse
# METIS
gunzip metis-5.1.0.tar.gz
tar -xvf metis-5.1.0.tar
cd metis-5.1.0/
# ... make sure IDXTYPEWIDTH=64 in `include/metis.h`
make config shared=1 prefix=~/.local
make install
export WITH_METIS=1
export CPLUS_INCLUDE_PATH=~/.local/include
export LIBRARY_PATH=~/.local/lib
export LD_LIBRARY_PATH=~/.local/lib
pip install torch-scatter torch-sparse
However, a similar error still appears.
$ python
>>> from torch_sparse import SparseTensor, set_diag
...
...
OSError: dlopen(~/miniconda3/envs/gnn-pip/lib/python3.11/site-packages/torch_sparse/_version_cpu.so, 0x0006): Library not loaded: libmetis.dylib
Referenced from: <BA2B5C47-7378-35F1-B4B8-A6F3CFFCBCFC> ~/miniconda3/envs/gnn-pip/lib/python3.11/site-packages/torch_sparse/_version_cpu.so
Reason: tried: 'libmetis.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibmetis.dylib' (no such file), 'libmetis.dylib' (no such file), '~/scratch-code/metis-5.1.0/libmetis.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/<path-to-metis-download>/metis-5.1.0/libmetis.dylib' (no such file), '<path-to-metis-download>/metis-5.1.0/libmetis.dylib' (no such file)
If needed, here is the GCC version I currently have:
$ gcc --version
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin23.0.0
Ideally, things would work without manually building METIS, but I understand this may be difficult to support for apple silicon. I tried also to build without shared=1, but similar errors happened. I'm happy to try different versions of python or pytorch, if that is potentially the issue, and also I can share any additional details if needed.
Thank you for help looking into this!
Hi, I have the same issue. Did you manage to find a solution? Thanks! EDIT: In case someone, checks here, the only thing that worked for me (Apple M3 pro macbook pro) was to install the torch version 2.0.0. (it didn't work with 2.2 nor 2.1)
- Make sure you pip3 uninstall "all torch related packages"
- pip3 install torch==2.0.0
- pip3 install torch-geometric #that was (v.2.5.2)
- pip3 install torch_scatter torch_sparse -f https://data.pyg.org/whl/torch-2.0.0+cpu.html #these were 2.1.2 and 0.6.18 versions, respectively.
Things work fine now!