linking to libpari within the sage environment

47 views
Skip to first unread message

Nils Bruin

unread,
12:13 PM (6 hours ago) 12:13 PM
to sage-devel
I ran into an issue with https://github.com/nbruin/RiemannTheta where installing it into modern sage completes without an error but where I get:

sage: import riemann_theta.riemann_theta
ImportError: /usr/local/sage/sage-git/local/var/lib/sage/venv-python3.13/lib64/python3.13/site-packages/riemann_theta/riemann_theta.cpython-313-x86_64-linux-gnu.so: undefined symbol: pari_err

Clearly, libpari doesn't get linked. Previously it did, so this is probably due to some tightening of dependency determination in cython or python's setup machinery.

The setup.py for this project is below. This used to work. Is there an obvious way in which I should change it? Particularly is there something sage-specific that can help here? The package in question really depends quite closely on a lot of sage so it would need to be built within its venv anyway.

--------------------------------------
import setuptools
from Cython.Build import cythonize
import numpy

with open("README.md", "r") as fh:
    long_description = fh.read()

setuptools.setup(
    name='RiemannTheta',
    version="1.0.0",
    author="Nils Bruin, Sohrab Ganjian",
    author_email="nbr...@sfu.ca",
    license="GPL2+",
    description="Evaluate Riemann Theta function numerically in Sagemath",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="",
    packages=setuptools.find_packages(),
    ext_modules=cythonize("riemann_theta/riemann_theta.pyx"),
    include_dirs=[numpy.get_include()],
    zip_safe=False,
)
-----------------------------------------------

I guess there need to be some "libraries" and possibly "library_dirs" added to the config but hardcoding them is probably not a good idea. Suggestions? (ChatGPT suggests running "pari-config" but I think it just came up with that because it looked convenient)

There may be other third party packages out there that quietly broke due to some backwards incompatible changes in the python/sage build system.

Nils Bruin

unread,
12:26 PM (6 hours ago) 12:26 PM
to sage-devel
OK, it seems like a "# distutils: libraries = pari" at the top of the pyx file does the trick, as suggested by the cython docs. Still interested in hearing if it's a good idea to solve it like that.

Tobia...@gmx.de

unread,
1:26 PM (5 hours ago) 1:26 PM
to sage-devel
The most future-proof version would be to convince the maintainers of Pari to include a pkg-config file (Pari is one of the few dependencies without one...)

Dima Pasechnik

unread,
1:59 PM (4 hours ago) 1:59 PM
to sage-...@googlegroups.com
You should follow the modern guidelines to specify the dependencies etc, with pyproject.toml
<https://packaging.python.org/en/latest/guides/section-build-and-publish/>
AFAIK, # distutils tags in Cython header is
the usual setuptools way.

I would also say, switch from setuptools to meson or pybind11/nanobind

Dima

Nils Bruin

unread,
2:02 PM (4 hours ago) 2:02 PM
to sage-devel
Thanks. As far as I understood, the setuptools way allowed "cythonize" to figure everything out for me, which meant I could use just some boilerplate setup.py. Is that now deprecated? That would be unfortunate. It would make packaging vanilla cython packages much harder.

Dima Pasechnik

unread,
4:09 PM (2 hours ago) 4:09 PM
to sage-...@googlegroups.com
On Mon, Jan 12, 2026 at 1:02 PM Nils Bruin <nbr...@sfu.ca> wrote:
>
> Thanks. As far as I understood, the setuptools way allowed "cythonize" to figure everything out for me, which meant I could use just some boilerplate setup.py. Is that now deprecated? That would be unfortunate. It would make packaging vanilla cython packages much harder.

I'm not sure about "much harder", why?
I don't know the current status of setuptools in this regard is.
Tobias has switched cysignals, memory_allocator, cypari2 and
primecountpy to use meson,
and it didn't look like a huge change, code-wise.
> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/sage-devel/0b461a48-36fe-4bac-926e-50559d5670b7n%40googlegroups.com.

Nils Bruin

unread,
4:14 PM (2 hours ago) 4:14 PM
to sage-devel
On Monday, 12 January 2026 at 13:09:01 UTC-8 dim...@gmail.com wrote:
I'm not sure about "much harder", why?
I don't know the current status of setuptools in this regard is.
Tobias has switched cysignals, memory_allocator, cypari2 and
primecountpy to use meson,
and it didn't look like a huge change, code-wise.

The "harder" is in comparison to what you do for setup.py: just copy-paste from the cython documentation:

it's not clear to me where to find such a straightforward solution for pyproject.toml
If it's declarative I wouldn't expect that calling "cythonize" is still an option, since that's basically executing arbitrary python code (at least as far as the build system is concerned).
Reply all
Reply to author
Forward
0 new messages