Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect library name on Mac #102

Open
peastman opened this issue May 19, 2023 · 3 comments
Open

Incorrect library name on Mac #102

peastman opened this issue May 19, 2023 · 3 comments

Comments

@peastman
Copy link
Member

I'm trying to build NNPOps on a Mac. It builds correctly, but when I try to import NNPOps it fails with this error:

Traceback (most recent call last):
  File "/Users/peastman/miniconda3/envs/openmm/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/Users/peastman/miniconda3/envs/openmm/lib/python3.9/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/Users/peastman/miniconda3/envs/openmm/lib/python3.9/site-packages/NNPOps/__init__.py", line 7, in <module>
    torch.ops.load_library(os.path.join(os.path.dirname(__file__), 'libNNPOpsPyTorch.so'))
  File "/Users/peastman/miniconda3/envs/openmm/lib/python3.9/site-packages/torch/_ops.py", line 255, in load_library
    ctypes.CDLL(path)
  File "/Users/peastman/miniconda3/envs/openmm/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Users/peastman/miniconda3/envs/openmm/lib/python3.9/site-packages/NNPOps/libNNPOpsPyTorch.so, 0x0006): tried: '/Users/peastman/miniconda3/envs/openmm/lib/python3.9/site-packages/NNPOps/libNNPOpsPyTorch.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/peastman/miniconda3/envs/openmm/lib/python3.9/site-packages/NNPOps/libNNPOpsPyTorch.so' (no such file), '/Users/peastman/miniconda3/envs/openmm/lib/python3.9/site-packages/NNPOps/libNNPOpsPyTorch.so' (no such file)

The problem comes from this line:

torch.ops.load_library(os.path.join(os.path.dirname(__file__), 'libNNPOpsPyTorch.so'))

On Macs, shared libraries have the extension .dylib rather than .so. It also won't work on Windows where they have the extension .dll.

@xiki-tempula
Copy link

I want to add that I think it would be very nice if we could have a mac build of the nnops so testing could be done locally instead of spawn a Linux EC2 instance.

@RaulPPelaez
Copy link
Contributor

There is this variable from cpp_extension that we could use:

import torch
from torch.utils.cpp_extension import LIB_EXT
import os
lib_path = os.path.join(os.path.dirname(__file__), 'libNNPOpsPyTorch' + LIB_EXT)
torch.ops.load_library(lib_path)

@peastman
Copy link
Member Author

You also need to vary whether the name starts with "lib". It does on Linux and Mac, but not on Windows.

Linux: libNNPOpsPyTorch.so
Mac: libNNPOpsPyTorch.dylib
Windows: NNPOpsPyTorch.dll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants