dftd3 / simple-dftd3

reimplementation of the DFT-D3 program
https://dftd3.readthedocs.io
GNU Lesser General Public License v3.0
51 stars 24 forks source link

Error due to location of _libdftd3.cpython-xxx.so #25

Closed hebrewsnabla closed 1 year ago

hebrewsnabla commented 2 years ago

I'm compiling this project with python interface enabled by

meson setup _build -Dpython=true 
meson configure _build --prefix=/home/wsr/s-dftd3
meson install -C _build

The compilation is ok, but I got an error when import dftd3.pyscf

Traceback (most recent call last):
  File "/home/wsr/s-dftd3/lib/python3.10/site-packages/dftd3/library.py", line 25, in <module>
    from ._libdftd3 import ffi, lib
ModuleNotFoundError: No module named 'dftd3._libdftd3'

I check the location of _libdftd3 and find it's in lib64, so the library.py in lib cannot import it

wsr@yoga:~/simple-dftd3> ls ~/s-dftd3/lib64/python3.10/site-packages/dftd3/
_libdftd3.cpython-310-x86_64-linux-gnu.so
wsr@yoga:~/simple-dftd3> ls ~/s-dftd3/lib/python3.10/site-packages/dftd3/
ase.py       interface.py  parameters.py  pyscf.py     test_ase.py        test_library.py     test_pyscf.py
__init__.py  library.py    __pycache__    qcschema.py  test_interface.py  test_parameters.py  test_qcschema.py

Can this be fixed by some meson setting? I've tried change meson configure _build --prefix=/home/wsr/s-dftd3 to meson configure _build --prefix=/home/wsr/s-dftd3 --libdir=lib, but it doesn't work. Or, can we change the way importing _libdftd3 so that its location does not matter?

awvwgk commented 2 years ago

You can adjust the library directory using the --libdir=lib option. For Python in particular there are also additional options (see https://mesonbuild.com/Python-module.html#install_sources), -Dpython.purelibdir and -Dpython.platlibdir, for deciding where extension modules and where pure sources are installed.

See https://mesonbuild.com/Builtin-options.html#python-module for all available Python options during configuration.

hebrewsnabla commented 2 years ago

You can adjust the library directory using the --libdir=lib option. For Python in particular there are also additional options (see https://mesonbuild.com/Python-module.html#install_sources), -Dpython.purelibdir and -Dpython.platlibdir, for deciding where extension modules and where pure sources are installed.

See https://mesonbuild.com/Builtin-options.html#python-module for all available Python options during configuration.

Thanks! The additional options works for me.

eli-schwartz commented 2 years ago

https://github.com/dftd3/simple-dftd3/blob/84ba953a5e25ecb3011cdb54237f87d30cc9a967/python/dftd3/meson.build#L91-L94

This is installing into the purelibdir if you don't specify the pure: false kwarg. But compiled C extension modules install to the platlibdir instead. Some OSes and Linux distros don't distinguish between platlib and purelib, defining both as the same directory... but some define them differently, particularly Debianlike distros.

For projects that mix both *.py files and compiled extensions in the same importable package, pure python files need to use the same install schema as the compiled extensions. Otherwise, python's import system will notice __init__.py, say "this is not a namespace package", and only use the first location that it finds, so it will not find the compiled extensions.

I would suggest adding that pure: false kwarg.