karannb
karannb

Reputation: 1

import error with pyg-lib and torch-sparse

I have been facing an issue with importing torch_geometric, every-time I run, from torch_geometric.nn import MessagePassing I get a stack trace as follows -

/Users/karan_bania/anaconda3/envs/PyGtut/lib/python3.10/site-packages/torch_geometric/typing.py:18: UserWarning: An issue occurred while importing 'pyg-lib'. Disabling its usage. Stacktrace: dlopen(/Users/karan_bania/anaconda3/envs/PyGtut/lib/python3.10/site-packages/libpyg.so, 0x0006): Library not loaded: /Users/runner/hostedtoolcache/Python/3.10.8/x64/lib/libpython3.10.dylib Referenced from: <17EC4CAB-AF50-3E98-8969-F2498B67D840> /Users/karan_bania/anaconda3/envs/PyGtut/lib/python3.10/site-packages/libpyg.so Reason: tried: '/Users/runner/hostedtoolcache/Python/3.10.8/x64/lib/libpython3.10.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/hostedtoolcache/Python/3.10.8/x64/lib/libpython3.10.dylib' (no such file), '/Users/runner/hostedtoolcache/Python/3.10.8/x64/lib/libpython3.10.dylib' (no such file), '/usr/local/lib/libpython3.10.dylib' (no such file), '/usr/lib/libpython3.10.dylib' (no such file, not in dyld cache) warnings.warn(f"An issue occurred while importing 'pyg-lib'. " /Users/karan_bania/anaconda3/envs/PyGtut/lib/python3.10/site-packages/torch_geometric/typing.py:42: UserWarning: An issue occurred while importing 'torch-sparse'. Disabling its usage. Stacktrace: dlopen(/Users/karan_bania/anaconda3/envs/PyGtut/lib/python3.10/site-packages/libpyg.so, 0x0006): Library not loaded: /Users/runner/hostedtoolcache/Python/3.10.8/x64/lib/libpython3.10.dylib Referenced from: <17EC4CAB-AF50-3E98-8969-F2498B67D840> /Users/karan_bania/anaconda3/envs/PyGtut/lib/python3.10/site-packages/libpyg.so Reason: tried: '/Users/runner/hostedtoolcache/Python/3.10.8/x64/lib/libpython3.10.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/hostedtoolcache/Python/3.10.8/x64/lib/libpython3.10.dylib' (no such file), '/Users/runner/hostedtoolcache/Python/3.10.8/x64/lib/libpython3.10.dylib' (no such file), '/usr/local/lib/libpython3.10.dylib' (no such file), '/usr/lib/libpython3.10.dylib' (no such file, not in dyld cache) warnings.warn(f"An issue occurred while importing 'torch-sparse'. "

I have tried multiple installations using anaconda and pip both, I always run into this issue. I checked other posts and some claim this is a multiple-python-versions issue, but when I run conda list python -n PyGtut I get the following output -

packages in environment at /Users/karan_bania/anaconda3/envs/PyGtut:
Name Version Build Channel
ipython 8.12.0 py310hecd8cb5_0
ipython_genutils 0.2.0 pyhd3eb1b0_1
python 3.10.8 h218abb5_1
python-dateutil 2.8.2 pyhd3eb1b0_0
python-fastjsonschema 2.16.2 py310hecd8cb5_0
python-json-logger 2.0.7 py310hecd8cb5_0
python-lsp-black 1.2.1 py310hecd8cb5_0
python-lsp-jsonrpc 1.0.0 pyhd3eb1b0_0
python-lsp-server 1.7.2 py310hecd8cb5_0
python-slugify 5.0.2 pyhd3eb1b0_0
python.app 3 py310hca72f7f_0

Which clearly shows I have just one version of Python. Also earlier I had 3.11.1 which I downgraded to 3.10.8 because the error showed the message. I think there is some issue with where the packages get installed but I am not able to figure out how to solve it.

I am using a macOS with torch==2.0.0.

Upvotes: 0

Views: 4114

Answers (2)

Beepbo0p
Beepbo0p

Reputation: 26

Hopefully you managed to solve it by now, however I encountered the same problem and managed to get around it.

I am running an m2 Macbook Air and MacOS 14.5

I got it running on a clean Conda environment using torch==2.3.0 by omitting pyg-lib from the optional dependencies. This worked for me and a friend using an m1 max Macbook Pro.

So the install command becomes: pip install torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.3.0+cpu.html

Although I can't explain why, there does seem to be a reoccurring problem with pyg-lib installation for Mac users. There are several discussion threads about it on the pytorch_geometric repo: https://github.com/pyg-team/pytorch_geometric/discussions/6848

Upvotes: 0

P. Rick
P. Rick

Reputation: 3

So I don't have a full answer for you yet, but my current analysis tells me there is something wrong with the installer of PyTorch Geometric, as I had the same issue with a different dependency (Torch_Spline_Conv). Importing torch and the dependency gave me the same error, solved it by installing directly from Binarys, see Rusty's Github page. Maybe this helps others too.

Upvotes: 0

Related Questions