Repository navigation
Closed
Description
After installing slycot using pip I got the following error, when I am trying to import it:
Python 3.8.10 (default, Nov 14 2022, 12:59:47)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import slycot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/env/lib/python3.8/site-packages/slycot/__init__.py", line 16, in <module>
from .analysis import ab01nd, ab05md, ab05nd, ab07nd, ab08nd, ab08nz
File "/home/user/env/lib/python3.8/site-packages/slycot/analysis.py", line 22, in <module>
from . import _wrapper
ImportError: /home/user/env/lib/python3.8/site-packages/slycot/_wrapper.cpython-38-x86_64-linux-gnu.so: undefined symbol: Py_SET_TYPEI am using Ubuntu 20.04 with Python 3.8.10 and created a new virtual environment for it:
$ virtualenv env
$ source ./env/bin/activate
$ pip install --no-cache-dir slycot
Collecting slycot
Downloading slycot-0.5.3.tar.gz (3.0 MB)
|████████████████████████████████| 3.0 MB 6.3 MB/s
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Collecting numpy
Downloading numpy-1.24.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
|████████████████████████████████| 17.3 MB 100.9 MB/s
Building wheels for collected packages: slycot
Building wheel for slycot (PEP 517) ... done
Created wheel for slycot: filename=slycot-0.5.3-cp38-cp38-linux_x86_64.whl size=1987476 sha256=53f161973476b615f3a07211877910eb89ad85d66428fc31d8b6e980a21a766a
Stored in directory: /tmp/pip-ephem-wheel-cache-e2j324rb/wheels/f7/b1/ef/08bc53cdb0fe98fa3c4067f1e674ebc4fd32a965544b558450
Successfully built slycot
Installing collected packages: numpy, slycot
Successfully installed numpy-1.24.2 slycot-0.5.3
$ python -c 'import slycot'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/env/lib/python3.8/site-packages/slycot/__init__.py", line 16, in <module>
from .analysis import ab01nd, ab05md, ab05nd, ab07nd, ab08nd, ab08nz
File "/home/user/env/lib/python3.8/site-packages/slycot/analysis.py", line 22, in <module>
from . import _wrapper
ImportError: /home/user/env/lib/python3.8/site-packages/slycot/_wrapper.cpython-38-x86_64-linux-gnu.so: undefined symbol: Py_SET_TYPEMetadata
Metadata
Assignees
Labels
No labels
Activity
bnavigator commentedon Mar 3, 2023
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?roryyorke commentedon Jun 25, 2023
I 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:
specifically
and
followed by CMake reporting:
This compiler warning, however, suggests wrong Numpy (and Python?) headers are used (I have numpy installed in base system via apt)
slycot-build-v.txt
I'm going to uninstall system numpy and python3-dev, and try again.
roryyorke commentedon Jun 25, 2023
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:If I look in /usr/include/python3.8:
My 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.roryyorke commentedon Jun 25, 2023
FWIW, the Ubuntu package for development is
libpython3.8-dev; removing this prevents a successful build.Check if likely-to-be-used Numpy include directory is from virtual en…
bnavigator commentedon Jul 2, 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?
Check if likely-to-be-used Numpy include directory is from virtual en…
ppisa commentedon Oct 30, 2023
I have problem to build actual slycot GIT mainline on Debian due this check
This 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.
roryyorke commentedon Jul 5, 2026
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.