fusion-engineering / inline-python

Inline Python code directly in your Rust code
https://docs.rs/inline-python
BSD 2-Clause "Simplified" License
1.15k stars 37 forks source link

Could not compile—error: dlopen: Library not loaded #46

Closed SichangHe closed 2 years ago

SichangHe commented 2 years ago

The error

I was trying out this crate and pasted in the example code. It failed to build:

 cargo run                                                                                                                                                                              (base) 
   Compiling pyo3-build-config v0.15.1
   Compiling libc v0.2.112
   Compiling parking_lot_core v0.8.5
   Compiling cfg-if v1.0.0
   Compiling once_cell v1.9.0
   Compiling smallvec v1.8.0
   Compiling scopeguard v1.1.0
   Compiling proc-macro2 v1.0.36
   Compiling unicode-xid v0.2.2
   Compiling instant v0.1.12
   Compiling lock_api v0.4.5
   Compiling quote v1.0.14
   Compiling parking_lot v0.11.2
   Compiling pyo3 v0.15.1
   Compiling inline-python-macros v0.8.0
   Compiling inline-python v0.8.0
error: dlopen(/Users/sichanghe/Documents/Rust/pyo3/inline_pythons/target/debug/deps/libinline_python_macros-6fdb391dcfb9a5ea.dylib, 0x0005): Library not loaded: @rpath/libpython3.8.dylib
         Referenced from: /Users/sichanghe/Documents/Rust/pyo3/inline_pythons/target/debug/deps/libinline_python_macros-6fdb391dcfb9a5ea.dylib
         Reason: tried: '/Users/sichanghe/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/../lib/libpython3.8.dylib' (no such file), '/Users/sichanghe/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/../lib/libpython3.8.dylib' (no such file), '/Users/sichanghe/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/libpython3.8.dylib' (no such file), '/Users/sichanghe/Documents/Rust/pyo3/inline_pythons/target/debug/deps/libpython3.8.dylib' (no such file), '/Users/sichanghe/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/libpython3.8.dylib' (no such file), '/Users/sichanghe/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/libpython3.8.dylib' (no such file), '/Users/sichanghe/lib/libpython3.8.dylib' (no such file), '/usr/local/lib/libpython3.8.dylib' (no such file), '/usr/lib/libpython3.8.dylib' (no such file)
   --> /Users/sichanghe/.cargo/registry/src/github.com-1ecc6299db9ec823/inline-python-0.8.0/src/lib.rs:135:9
    |
135 | pub use inline_python_macros::python;
    |         ^^^^^^^^^^^^^^^^^^^^

error: could not compile `inline-python` due to previous error

It seems like inline-python is the library that failed to compile, and the reason is that rustc cannot find a libpython3.8.dylib file.

my python3

 which python                                                                                                                                                                           (base) 
/Users/sichanghe/miniconda3/bin/python
 python3 --version                                                                                                                                                                      (base) 
Python 3.8.11

Btw

I am using nightly because rust stable refused to compile:

 cargo run                                                                                                                                                                                 (base) 
   Compiling inline-python-macros v0.8.0
error[E0554]: `#![feature]` may not be used on the stable release channel
 --> /Users/sichanghe/.cargo/registry/src/github.com-1ecc6299db9ec823/inline-python-macros-0.8.0/src/lib.rs:3:12
  |
3 | #![feature(proc_macro_span)]
  |            ^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0554`.
error: could not compile `inline-python-macros` due to previous error

Does this crate require nightly? I see it specified nightly in documentations of some previous versions, but not in 0.8.0.

SichangHe commented 2 years ago

The libpython3.8.dylib file is here:

 fd libpython3.8.dylib                                                                                                                                                     (base) 
miniconda3/lib/libpython3.8.dylib
miniconda3/pkgs/python-3.8.11-hbdb9e5c_5/lib/libpython3.8.dylib
miniconda3/pkgs/python-3.8.11-h35b60ff_4_cpython/lib/libpython3.8.dylib
m-ou-se commented 2 years ago

It seems like inline-python is the library that failed to compile, and the reason is that rustc cannot find a libpython3.8.dylib file.

Finding and linking the Python dynamic library is done by PyO3. If it can't find Python on your computer even though you have installed it, that's a problem with that library: https://github.com/PyO3/pyo3

Does this crate require nightly? I see it specified nightly in documentations of some previous versions, but not in 0.8.0.

Yes. Looks like we accidentally removed the notice about needing nightly when we removed the notice about the no longer needed proc_macro_hygiene feature.

SichangHe commented 2 years ago

Solved

Solution I used is to remove Conda. See the post on PyO3 for details.