uber/neuropod

Python native bindings cannot recognize non-system Python versions

tgaddair opened this issue · 3 comments

Bug

Attempting to load a neuropod using a Python version managed by pyenv results in the following error:

>       from neuropod.neuropod_native import Neuropod as NeuropodNative
E       ImportError: dlopen(/Users/taddair/repos/ludwig/py37/lib/python3.7/site-packages/neuropod/neuropod_native.so, 2): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.7/Python
E         Referenced from: /Users/taddair/repos/ludwig/py37/lib/python3.7/site-packages/neuropod/neuropod_native.so
E         Reason: image not found

py37/lib/python3.7/site-packages/neuropod/loader.py:114: ImportError

Because this version of Python was installed via pyenv, /Library/Frameworks/Python.framework/Versions/3.7/Python does not exist.

When I set _always_use_native=False, everything works as expected.

To Reproduce

On Mac, use pyenv to download a version of Python you don't have on your system, then attempt to load a neuropod Python model.

Expected behavior

Same behavior as _always_use_native=False.

Environment

  • Neuropod Version (e.g., 0.2.0): 0.2.0
  • OS (Linux, macOS): macOS
  • Language (Python, C++, Go bindings): Python
  • Python version: 3.7
  • Using OPE: yes (default)

If this bug report is about running a specific model:

  • Neuropod backend (e.g. TensorFlow, PyTorch, Keras, TorchScript, Python): Python
  • Framework version (e.g. 1.3.0): N/A

I'm also seeing a similar but slight different issue when using native bindings with Python 3.6 on a Linux machine:

        self.model = NeuropodNative(
>           neuropod_path, _REGISTERED_BACKENDS, use_ope=True, **kwargs
        )
E       RuntimeError: Neuropod Error: Got an exception when loading the model at neuropod: Neuropod Error: Loading the default backend for type 'python' failed. Error from dlopen: libneuropod_pythonbridge_backend.so: cannot open shared object file: No such file or directory

Thanks for the issue!

The first part of this issue should be fixed on master (see #387 and #389).

Unfortunately, that doesn't fix the entire problem because the python backend in the worker process will still try to load python from the default path (on macOS). New issue coming soon with more details.

RE your second comment, did you try installing the python backend? https://neuropod.ai/installing/#python

See #383 (comment) for more details

Lots of things have changed since this issue was created.

Neuropod now ships an isolated python environment as part of the python backends (see #420 which landed in November 2020). This means it won't attempt to load your system's python binaries (although you can still use virtualenvs if you would like).

This also enables models to specify their python dependencies at packaging time (https://neuropod.ai/docs/master/packagers/pytorch/#requirements) and Neuropod will ensure they're available in the isolated environment before loading the model.

Take a look at the installation instructions for any of the v0.3.0 RCs (https://neuropod.ai/docs/master/installing/) if you would like to try it out.

@tgaddair let me know if you want to test this in Ludwig or if I should just go ahead and close this issue. Thanks!