Repository navigation
undefined symbol: Py_SET_TYPE #193
Description
Activity
Hi @grisuthedragon, thanks for the report.
The error message is interesting and would imply that the compilation step during
pip installwould have found the wrong python headers. Could you run and post the output of a verbose compilation please?pip wheel -v slycotI can reproduce this (also Ubuntu 20.04).
Output of
(rm -rf env/ && virtualenv env && source ./env/bin/activate && pip wheel -v slycot) |& tee slycot-build-v.txtattached.This looks fine to me:
/tmp/pip-build-env-_qcqcl1f/overlay/lib/python3.8/site-packages/cmake/data/bin/cmake /tmp/pip-wheel-rr0bha7n/slycot -G Ninja --no-warn-unused-cli -DCMAKE_INSTALL_PREFIX:PATH=/tmp/pip-wheel-rr0bha7n/slycot/_skbuild/linux-x86_64-3.8/cmake-install -DPYTHON_VERSION_STRING:STRING=3.8.10 -DSKBUILD:INTERNAL=TRUE -DCMAKE_MODULE_PATH:PATH=/tmp/pip-build-env-_qcqcl1f/overlay/lib/python3.8/site-packages/skbuild/resources/cmake -DPYTHON_EXECUTABLE:PATH=/home/rory/tmp/env/bin/python -DPYTHON_INCLUDE_DIR:PATH=/usr/include/python3.8 -DPYTHON_LIBRARY:PATH=/usr/lib/x86_64-linux-gnu/libpython3.8.so -DPython_EXECUTABLE:PATH=/home/rory/tmp/env/bin/python -DPython_ROOT_DIR:PATH=/home/rory/tmp/env -DPython_FIND_REGISTRY:STRING=NEVER -DPython_INCLUDE_DIR:PATH=/usr/include/python3.8 -DPython_NumPy_INCLUDE_DIRS:PATH=/tmp/pip-build-env-_qcqcl1f/overlay/lib/python3.8/site-packages/numpy/core/include -DPython3_EXECUTABLE:PATH=/home/rory/tmp/env/bin/python -DPython3_ROOT_DIR:PATH=/home/rory/tmp/env -DPython3_FIND_REGISTRY:STRING=NEVER -DPython3_INCLUDE_DIR:PATH=/usr/include/python3.8 -DPython3_NumPy_INCLUDE_DIRS:PATH=/tmp/pip-build-env-_qcqcl1f/overlay/lib/python3.8/site-packages/numpy/core/include -DCMAKE_BUILD_TYPE:STRING=Releasespecifically
-DPython_NumPy_INCLUDE_DIRS:PATH=/tmp/pip-build-env-_qcqcl1f/overlay/lib/python3.8/site-packages/numpy/core/includeand
-DPython3_NumPy_INCLUDE_DIRS:PATH=/tmp/pip-build-env-_qcqcl1f/overlay/lib/python3.8/site-packages/numpy/core/includefollowed by CMake reporting:
-- Found NumPy: /tmp/pip-build-env-_qcqcl1f/overlay/lib/python3.8/site-packages/numpy/core/include (found version "1.24.3") -- Found F2PY: /tmp/pip-build-env-_qcqcl1f/overlay/bin/f2py3 (found version "1.24.3")This compiler warning, however, suggests wrong Numpy (and Python?) headers are used (I have numpy installed in base system via apt)
[684/1236] Building C object slycot/CMakeFiles/_wrapper.dir/_wrappermodule.c.o /tmp/pip-wheel-rr0bha7n/slycot/_skbuild/linux-x86_64-3.8/cmake-build/slycot/_wrappermodule.c: In function ‘int_from_pyobj’: /tmp/pip-wheel-rr0bha7n/slycot/_skbuild/linux-x86_64-3.8/cmake-build/slycot/_wrappermodule.c:271:14: warning: implicit declaration of function ‘Npy__PyLong_AsInt’ [-Wimplicit-function-declaration] 271 | *v = Npy__PyLong_AsInt(obj); | ^~~~~~~~~~~~~~~~~ /tmp/pip-wheel-rr0bha7n/slycot/_skbuild/linux-x86_64-3.8/cmake-build/slycot/_wrappermodule.c: In function ‘PyInit__wrapper’: /tmp/pip-wheel-rr0bha7n/slycot/_skbuild/linux-x86_64-3.8/cmake-build/slycot/_wrappermodule.c:26712:5: warning: implicit declaration of function ‘Py_SET_TYPE’; did you mean ‘Py_TYPE’? [-Wimplicit-function-declaration] 26712 | Py_SET_TYPE(&PyFortran_Type, &PyType_Type); | ^~~~~~~~~~~ | Py_TYPEI'm going to uninstall system numpy and python3-dev, and try again.
My comment about Python headers doesn't make sense: we're using the system Python in a venv, so we must use system headers in some way. Having said that I did uninstall those apt packages (and python3.8-dev), and I could successfully build. This makes sense i.t.o. numpy (see also below), but not, I think, python3-dev. I'm a bit confused about this.
I reinstalled python3-dev and numpy via apt, and did a build from git working tree branch from v0.5.4. The command
python setup.py build -- -- -vgives this:[680/1236] /usr/bin/cc -D_wrapper_EXPORTS -I/usr/include/python3.8 -I/home/rory/projects/slycot/gh193-buildbug/venv/lib/python3.8/site-packages/numpy/core/include -I/home/rory/projects/slycot/gh193-buildbug/venv/lib/python3.8/site-packages/numpy/f2py/src -O3 -DNDEBUG -fPIC -MD -MT slycot/CMakeFiles/_wrapper.dir/_wrappermodule.c.o -MF slycot/CMakeFiles/_wrapper.dir/_wrappermodule.c.o.d -o slycot/CMakeFiles/_wrapper.dir/_wrappermodule.c.o -c /home/rory/src/slycot/_skbuild/linux-x86_64-3.8/cmake-build/slycot/_wrappermodule.c /home/rory/src/slycot/_skbuild/linux-x86_64-3.8/cmake-build/slycot/_wrappermodule.c: In function ‘int_from_pyobj’: /home/rory/src/slycot/_skbuild/linux-x86_64-3.8/cmake-build/slycot/_wrappermodule.c:271:14: warning: implicit declaration of function ‘Npy__PyLong_AsInt’ [-Wimplicit-function-declaration] 271 | *v = Npy__PyLong_AsInt(obj); | ^~~~~~~~~~~~~~~~~ /home/rory/src/slycot/_skbuild/linux-x86_64-3.8/cmake-build/slycot/_wrappermodule.c: In function ‘PyInit__wrapper’: /home/rory/src/slycot/_skbuild/linux-x86_64-3.8/cmake-build/slycot/_wrappermodule.c:26712:5: warning: implicit declaration of function ‘Py_SET_TYPE’; did you mean ‘Py_TYPE’? [-Wimplicit-function-declaration] 26712 | Py_SET_TYPE(&PyFortran_Type, &PyType_Type); | ^~~~~~~~~~~ | Py_TYPEIf I look in /usr/include/python3.8:
$ ls -l /usr/include/python3.8|grep numpy lrwxrwxrwx 1 root root 56 Dec 5 2022 numpy -> ../../lib/python3/dist-packages/numpy/core/include/numpyMy guess is gcc's include ordering gives preference to the system Numpy, since
-I/usr/include/python3.8is first in the arguments relative to the venv Numpy dirs. I think we rely on scikit-build to make that command-line, I don't know if we can affect the order of output.So, I don't know how to fix this, but a workaround is to uninstall system numpy (
apt remove python3-numpy), do the venv setup, then reinstall system numpy.FWIW, the Ubuntu package for development is
libpython3.8-dev; removing this prevents a successful build.- added a commit that references this issue
on Jun 25, 2023 Nice digging @roryyorke. I am very surprised that this is an issue. We are certainly not the only package compiling stuff with both numpy and python headers, using the scikit-build cmake chain. What do we do different to other packages?
- added a commit that references this issue
on Aug 25, 2023 I have problem to build actual slycot GIT mainline on Debian due this check
ls -l /usr/include/python3.11/numpy lrwxrwxrwx 1 root root 56 Feb 9 2023 /usr/include/python3.11/numpy -> ../../lib/python3/dist-packages/numpy/core/include/numpy ls -ld /usr/lib/python3/dist-packages/numpy/core/include/numpy drwxr-xr-x 1 root root 842 Jul 17 20:40 /usr/lib/python3/dist-packages/numpy/core/include/numpyThis is the same directory mapped by symlink so this seems to be error to prevent build of the package.
When I remove check the Slycot builds and works with python-control and pysimCoder on my computer.
I can no longer reproduce this; testing with on Debian 13 with Slycot 6.9.1 (scikit-build) and Slycot 0.7.0 (scikit-build-core), the build passes with and without Debian package python3-numpy (and dependency python3-numpy-dev) installed.
Debian 13 has numpy 2.2.4. I changed Slycot's pyproject.toml to require numpy < 2, and it built with numpy 1.26. Again passed with and with Debian package python3-numpy installed.
Since the bug can no longer be reproduced, and Slycot has changed build backends since it was reported, I'm going to close this.
After installing slycot using pip I got the following error, when I am trying to import it:
I am using Ubuntu 20.04 with Python 3.8.10 and created a new virtual environment for it: