DIPlib / diplib

Quantitative Image Analysis in C++, MATLAB and Python
https://diplib.org
Apache License 2.0
222 stars 49 forks source link

pydip built from source fails to import #126

Closed anntzer closed 11 months ago

anntzer commented 1 year ago

Component pydip

Describe the bug Building pydip from source results in a library that fails to import

To Reproduce

$ mkdir build && cd build && cmake .. && make && make pip_install && python -c 'import diplib'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/some/prefix/lib/python3.10/site-packages/diplib/__init__.py", line 52, in <module>
    from .PyDIP_bin import *
ImportError: dynamic module does not define module export function (PyInit_PyDIP_bin)

Dumping the exported symbols from PyDIP_bin (nm -gD PyDIP_bin.cpython-310-x86_64-linux-gnu.so) shows that that symbol is indeed absent.

System information:

crisluengo commented 1 year ago

Thanks. Yes, I need to improve the documentation here.

You need to do make install before you do make pip_install. Otherwise the DIPlib libraries will not be found by the Python module.

Alternatively, you could set DIP_PYDIP_WHEEL_INCLUDE_LIBS to On in the CMake configuration step. In this case, the DIPlib libraries will be copied over into the installed wheel.

anntzer commented 1 year ago

I tried with cmake -DDIP_PYDIP_WHEEL_INCLUDE_LIBS=On .. and things fail with the same error. Haven't tried with make install as I'd rather not move stuff into /usr; is it possible to install into a prefix? Note, though, that the error ("ImportError: dynamic module does not define module export function (PyInit_PyDIP_bin)") suggests that the problem is not with finding diplib(?)

crisluengo commented 1 year ago

Yes, you can install into any prefix.

My working hypothesis is that the error message is inaccurate, that it cannot load the PyInit_PyDIP_bin module because some of its dependencies are missing.

It not working with the libraries included in the wheel is strange though. That might indicate some other issue. Check the Python version in thr CMake configuration output, and make sure it’s identical to the version of Python you’re trying to run this in. If not, configure in the CMake call the Python executable.

anntzer commented 1 year ago

CMakeCache.txt says e.g. that

//Path to a program.
PYTHON_EXECUTABLE:FILEPATH=/home/antony/miniconda3/envs/default/bin/python

//Path to a library.
PYTHON_LIBRARY:FILEPATH=/home/antony/miniconda3/envs/default/lib/libpython3.10.so

which is correct.

I'll continue investigating...


Followup: I get the same failure using both conda-python (eveything in a conda env) or distro(fedora)-python (everything out of conda) on linux. OTOH I did manage to get things to work on Windows, which is better than nothing and at least I can move on and investigate whether I can e.g. improve the situation wrt #125.

crisluengo commented 11 months ago

Closing this because it's been inactive for long. Please reopen if you ever learn more!