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

Getting undefined symbol error compiling python3-scipy #7

Open
lsorense opened this issue Oct 18, 2024 · 5 comments
Open

Getting undefined symbol error compiling python3-scipy #7

lsorense opened this issue Oct 18, 2024 · 5 comments

Comments

@lsorense
Copy link

lsorense commented Oct 18, 2024

I was trying to use this layer to get an updated scipy and pyarrow (I have an older recipe for scipy but some features don't work on it so I wanted to see if a newer and hopefully better recipe would fix that), but I am having no luck getting it to compile.

Initially I get the error that gfortran version is unknown from python3-scipy-native. I fixed that by adding gfortran to HOSTTOOLS and installing it on the build machine. I didn't see this in the README so I am not convinced this is supposed to be needed nor that the host gfortran is necessarily compatible with the yocto build.

So the error I see is:

 pybind11-config found: YES (/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/bin/pybind11-config) 2.12.0
| Run-time dependency pybind11 found: YES 2.12.0
| Program f2py found: YES (/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/bin/f2py)
|
| ../scipy-1.14.1/scipy/meson.build:156:15: ERROR: Command `/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/bin/f2py -v` failed with status 1.
|
| A full log can be found at /tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/build/meson-logs/meson-log.txt

And looking at the meson-log.txt I have:
Traceback (most recent call last):
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/bin/f2py", line 5, in <module>
    from numpy.f2py.f2py2e import main
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/numpy/f2py/__init__.py", line 14, in <module>
    import subprocess
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/subprocess.py", line 49, in <module>
    import signal
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/scipy-1.14.1/scipy/signal/__init__.py", line 327, in <module>
    from ._bsplines import *
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/scipy-1.14.1/scipy/signal/_bsplines.py", line 11, in <module>
    from ._signaltools import lfilter, sosfilt, lfiltic
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/scipy-1.14.1/scipy/signal/_signaltools.py", line 14, in <module>
    from scipy.spatial import cKDTree
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/spatial/__init__.py", line 110, in <module>
    from ._kdtree import *
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/spatial/_kdtree.py", line 4, in <module>
    from ._ckdtree import cKDTree, cKDTreeNode
  File "_ckdtree.pyx", line 11, in init scipy.spatial._ckdtree
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/__init__.py", line 307, in <module>
    from . import csgraph
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/csgraph/__init__.py", line 187, in <module>
    from ._laplacian import laplacian
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/csgraph/_laplacian.py", line 7, in <module>
    from scipy.sparse.linalg import LinearOperator
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/linalg/__init__.py", line 129, in <module>
    from ._isolve import *
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/linalg/_isolve/__init__.py", line 4, in <module>
    from .iterative import *
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/linalg/_isolve/iterative.py", line 5, in <module>
    from scipy.linalg import get_lapack_funcs
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/linalg/__init__.py", line 203, in <module>
    from ._misc import *
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/linalg/_misc.py", line 3, in <module>
    from .blas import get_blas_funcs
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/linalg/blas.py", line 213, in <module>
    from scipy.linalg import _fblas
ImportError: /tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/linalg/_fblas.cpython-312-x86_64-linux-gnu.so: undefined symbol: cspmv_

So my understanding is that it can't find one of the fortran symbols.

Switching from openblas to lapack (which is what I really would like since I am trying to get cvxpy working which seems to need scipy with lapack) I instead get this symbol missing:

Traceback (most recent call last):
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/bin/f2py", line 5, in <module>
    from numpy.f2py.f2py2e import main
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/numpy/f2py/__init__.py", line 14, in <module>
    import subprocess
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/subprocess.py", line 49, in <module>
    import signal
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/scipy-1.14.1/scipy/signal/__init__.py", line 327, in <module>
    from ._bsplines import *
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/scipy-1.14.1/scipy/signal/_bsplines.py", line 11, in <module>
    from ._signaltools import lfilter, sosfilt, lfiltic
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/scipy-1.14.1/scipy/signal/_signaltools.py", line 14, in <module>
    from scipy.spatial import cKDTree
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/spatial/__init__.py", line 110, in <module>
    from ._kdtree import *
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/spatial/_kdtree.py", line 4, in <module>
    from ._ckdtree import cKDTree, cKDTreeNode
  File "_ckdtree.pyx", line 11, in init scipy.spatial._ckdtree
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/__init__.py", line 307, in <module>
    from . import csgraph
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/csgraph/__init__.py", line 187, in <module>
    from ._laplacian import laplacian
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/csgraph/_laplacian.py", line 7, in <module>
    from scipy.sparse.linalg import LinearOperator
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/linalg/__init__.py", line 130, in <module>
    from ._dsolve import *
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/linalg/_dsolve/__init__.py", line 58, in <module>
    from .linsolve import *
  File "/tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/linalg/_dsolve/linsolve.py", line 11, in <module>
    from . import _superlu
ImportError: /tmp/extreme-core-5.0/poky/build/tmp/work/core2-64-core-linux/python3-scipy/1.14.1/recipe-sysroot-native/usr/lib/python3.12/site-packages/scipy/sparse/linalg/_dsolve/_superlu.cpython-312-x86_64-linux-gnu.so: undefined symbol: dtrsm_

I thought maybe it was a problem with the build host (using opensuse 15.3) so I tried on Debian 12 (bookworm) instead to have more up to date host tools, but exact same errors there.

Did I just miss a setting somewhere? It seems I only ever hit these undefined symbol errors when trying to deal with scipy and it's fortran dependencies and it is not exactly easy to find anyone with any clues about what it's problem is.

@zboszor
Copy link
Owner

zboszor commented Oct 19, 2024

Hi, thanks for the report. Welcome to the world of BLAS packages, which can and do conflict.

I have this in my private layer as openblas_%.bbappend:

BLAS_X86_ARCH = "NEHALEM"
PACKAGECONFIG = "lapack cblas affinity dynarch"

which avoids the build problem and allows using OpenBLAS in python3-scipy.

PACKAGECONFIG in the openblas recipe here in this layer is left empty by default, in order not to interfere with lapack which we don't use.

FYI, the symbols you mention are in this report which confirms that OpenBLAS needs to be built with supplying LAPACK compatibility.

Using scipy with lapack (as opposed to OpenBLAS) may also work if you use PACKAGECONFIG = "lapacke" in a lapack_%.bbappend file in your OS layer.

@lsorense
Copy link
Author

Excellent. That seems worthy of being in the readme file.

So with that openblas config, numpy suddenly detects lapack and blas correctly (it seemed confused and only half detecting it before), as does scs which makes cvxpy happy. Much better.

I still had to add gfortran to HOSTTOOLS to make python3-scipy-native compile. Is that normal?

I did have to patch openblas to fix the lib path since it breaks when using multilib (it assumes lib rather than lib64 for the install location), bit not a big deal and hopefully soon the last 32 bit code will be converted to 64 bit to get rid of this multilib mess.

At least now this builds and the code seems to run and happily use the openblas lapack functions and I can get rid of my scipy and openblas recipes that didn't fully work it seems.

@zboszor
Copy link
Owner

zboszor commented Oct 21, 2024

Hm. I don't remember since when but I also have HOSTTOOLS += "gfortran" in my local configuration.

(looking) I can see it now. It's in the original https://github.com/tuxable-ltd/meta-scikit-learn/ README.

I will update the README when I get to it, also for other reasons. FWIW, I also have that meta-clang-revival layer which brings back older CLANG versions for the intel-graphics-compiler recipe in meta-intel and for the python3-llvmlite / python3-numba recipes in this layer.

@zboszor
Copy link
Owner

zboszor commented Oct 21, 2024

Regarding multilib, can you share that patch in a PR?

I would like to support Yocto in more configurations than just mine without multilib.

@lsorense
Copy link
Author

lsorense commented Oct 21, 2024

Well my patch is too simple to be generic since it makes it only work for 64bit multilib case. So a better fix is needed.

What I did is patch Makefile.install to change OPENBLAS_LIBRARY_DIR from $(PREFIX)/lib to $(PREFIX)/lib64 which fixes it for this case. And then I do a SRC_URI:append:class-target for that patch. It would be better to figure out a way to make it actually use the environment where yocto tells it what the library path is. If it has a variable like $(PREFIX) it could use for lib instead of being hard coded that would clearly be the right solution but I didn't look into that yet.

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

No branches or pull requests

2 participants