pytorch (cpu only) on osx fails with symbol not found

4.9k views Asked by At

I am trying to get started with PyTorch - on a mac osx computer. However, basic steps fail:

from torch_sparse import coalesce, SparseTensor

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-1-dad8246d5249> in <module>
----> 1 from torch_sparse import coalesce, SparseTensor

/usr/local/Caskroom/miniconda/base/envs/my_conda_env/lib/python3.8/site-packages/torch_sparse/__init__.py in <module>
     10         '_saint', '_padding'
     11 ]:
---> 12     torch.ops.load_library(importlib.machinery.PathFinder().find_spec(
     13         library, [osp.dirname(__file__)]).origin)
     14 

/usr/local/Caskroom/miniconda/base/envs/my_conda_env/lib/python3.8/site-packages/torch/_ops.py in load_library(self, path)
    102             # static (global) initialization code in order to register custom
    103             # operators with the JIT.
--> 104             ctypes.CDLL(path)
    105         self.loaded_libraries.add(path)
    106 

/usr/local/Caskroom/miniconda/base/envs/my_conda_env/lib/python3.8/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    371 
    372         if handle is None:
--> 373             self._handle = _dlopen(self._name, mode)
    374         else:
    375             self._handle = handle

OSError: dlopen(/usr/local/Caskroom/miniconda/base/envs/my_conda_env/lib/python3.8/site-packages/torch_sparse/_version.so, 6): Symbol not found: __ZN3c105ErrorC1ENS_14SourceLocationERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE
  Referenced from: /usr/local/Caskroom/miniconda/base/envs/my_conda_env/lib/python3.8/site-packages/torch_sparse/_version.so
  Expected in: flat namespace
 in /usr/local/Caskroom/miniconda/base/envs/my_conda_env/lib/python3.8/site-packages/torch_sparse/_version.so

I am using a conda environment of:

name: my_conda_env
channels:
  - pytorch
  - conda-forge
  - defaults
dependencies:
  - python>=3.8
  - pytorch
  - pytorch_geometric

and instantiated it using:

conda env create --force -f environment.yml
2

There are 2 answers

0
Georg Heiler On BEST ANSWER

https://github.com/rusty1s/pytorch_sparse/issues/135

Indeed, https://github.com/conda-forge/pytorch_sparse-feedstock/issues/13 is the problem The manual installation of pytorch geometric and its dependencies such as pytorch sparse using pip https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html is a currently suitable workaround

0
Maria On

I was having the same issue when importing torch_geometric datasets: from torch_geometric.datasets import TUDataset

My setup: torch version 1.11.0 on Windows in Anaconda environment. I installed torch-geometric with pip

I resolved it by uninstalling torch-geometric and all its dependencies with: pip uninstall torch-geometric torch-scatter torch-sparse torch-cluster torch-spline-conv

Making sure that torch-geometric is actually uninstalled by checking the packages installed in my anaconda env with: conda list

Turned out that I had multiple versions of these packages installed in my anaconda environment. The problem was, that I installed torch-geometric with cuda but I later when did not have a gpu connected, I needed to install the cpu version. pip install cpu version did not remove the already present gpu version, hence creating a conflict.

So, after removing torch-geometric and all its dependencies, I used the PyG documentation to know compatible versions of torch-geometric and its dependencies:

enter image description here

Finally, according to docs, I used this command:

pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.11.0+cpu.html

The versions of dependencies installed for torch==1.11.0 were:

torch-geometric==2.0.4

torch-cluster==1.6.0

torch-scatter==2.0.9

torch-sparse==0.6.13

torch-spline-conv==1.2.1