Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Cython on Ubuntu 24.04

I'm running SageMath 10.4, which was installed using mamba. When trying the example of load("power2.spyx") in Coding in Cython documentation on the SageMath website, I get the following error. I tried to avoid the error by installing libgd3 and libgd-dev via apt, but the error remains.

$ sage ┌────────────────────────────────────────────────────────────────────┐ │ SageMath version 10.4, Release Date: 2024-07-19 │ │ Using Python 3.10.15. Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘ sage: load("power2.spyx")

Compiling power2.spyx...

KeyError Traceback (most recent call last) File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/misc/cachefunc.pyx:1010, in sage.misc.cachefunc.CachedFunction.__call__ (build/cythonized/sage/misc/cachefunc.c:8371)() 1009 try: -> 1010 return self.cache[k] 1011 except TypeError: # k is not hashable

KeyError: ((), ())

During handling of the above exception, another exception occurred:

PackageNotFoundError Traceback (most recent call last) Cell In[1], line 1 ----> 1 load("power2.spyx")

File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/misc/persist.pyx:176, in sage.misc.persist.load (build/cythonized/sage/misc/persist.c:4564)() 174 175 if sage.repl.load.is_loadable_filename(filename): --> 176 sage.repl.load.load(filename, globals()) 177 return 178

File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/repl/load.py:282, in load(filename, globals, attach) 280 if attach: 281 add_attached_file(fpath) --> 282 exec(load_cython(fpath), globals) 283 elif ext in ['.f', '.f90']: 284 from sage.misc.inline_fortran import fortran

File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/repl/load.py:73, in load_cython(name) 60 """ 61 Helper function to load a Cython file. 62 (...) 70 module. 71 """ 72 from sage.misc.cython import cython ---> 73 mod, dir = cython(str(name), compile_message=True, use_cache=True) 74 import sys 75 sys.path.append(dir)

File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/misc/cython.py:317, in cython(filename, verbose, compile_message, use_cache, create_local_c_file, annotate, sage_namespace, create_local_so_file) 313 shutil.copy(filename, pyxfile) 315 # Add current working directory to includes. This is needed because 316 # we cythonize from a different directory. See Issue #24764. --> 317 standard_libs, standard_libdirs, standard_includes, aliases = _standard_libs_libdirs_incdirs_aliases() 318 includes = [os.getcwd()] + standard_includes 320 # Now do the actual build, directly calling Cython and distutils

File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/misc/cachefunc.pyx:1015, in sage.misc.cachefunc.CachedFunction.__call__ (build/cythonized/sage/misc/cachefunc.c:8499)() 1013 return self.cache[k] 1014 except KeyError: -> 1015 w = self.f(args, *kwds) 1016 self.cache[k] = w 1017 return w

File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/misc/cython.py:51, in _standard_libs_libdirs_incdirs_aliases() 37 @cached_function 38 def _standard_libs_libdirs_incdirs_aliases(): 39 r""" 40 Return the list of libraries and library directories. 41 (...) 49 {...}) 50 """ ---> 51 aliases = cython_aliases() 52 standard_libs = [ 53 'mpfr', 'gmp', 'gmpxx', 'pari', 'm', 54 'ec', 'gsl', 55 ] + aliases["CBLAS_LIBRARIES"] + [ 56 'ntl'] 57 standard_libdirs = []

File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/env.py:442, in cython_aliases(required_modules, optional_modules) 440 else: 441 try: --> 442 aliases[var + "CFLAGS"] = pkgconfig.cflags(lib).split() 443 pc = pkgconfig.parse(lib) 444 libs = pkgconfig.libs(lib)

File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/pkgconfig/pkgconfig.py:144, in cflags(package) 138 def cflags(package): 139 """ 140 Return the CFLAGS string returned by pkg-config. 141 142 If pkg-config is not on path, raises EnvironmentError. 143 """ --> 144 _raise_if_not_exists(package) 145 return _query(package, '--cflags')

File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/pkgconfig/pkgconfig.py:103, in _raise_if_not_exists(package) 101 def _raise_if_not_exists(package): 102 if not exists(package): --> 103 raise PackageNotFoundError(package)

PackageNotFoundError: gdlib not found

click to hide/show revision 2
None

updated 0 years ago

FrédéricC gravatar image

Cython on Ubuntu 24.04

I'm running SageMath 10.4, which was installed using mamba. When trying the example of load("power2.spyx") in Coding in Cython documentation on the SageMath website, I get the following error. I tried to avoid the error by installing libgd3 and libgd-dev via apt, but the error remains.

$ sage
┌────────────────────────────────────────────────────────────────────┐
 SageMath version 10.4, Release Date: 2024-07-19                    
 Using Python 3.10.15. Type "help()" for help.                      
└────────────────────────────────────────────────────────────────────┘
sage: load("power2.spyx")

load("power2.spyx") Compiling power2.spyx...

power2.spyx... --------------------------------------------------------------------------- KeyError Traceback (most recent call last) File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/misc/cachefunc.pyx:1010, in sage.misc.cachefunc.CachedFunction.__call__ (build/cythonized/sage/misc/cachefunc.c:8371)() 1009 try: -> 1010 return self.cache[k] 1011 except TypeError: # k is not hashable

hashable KeyError: ((), ())

()) During handling of the above exception, another exception occurred:

occurred: PackageNotFoundError Traceback (most recent call last) Cell In[1], line 1 ----> 1 load("power2.spyx")

load("power2.spyx") File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/misc/persist.pyx:176, in sage.misc.persist.load (build/cythonized/sage/misc/persist.c:4564)() 174 175 if sage.repl.load.is_loadable_filename(filename): --> 176 sage.repl.load.load(filename, globals()) 177 return 178

File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/repl/load.py:282, in load(filename, globals, attach) 280 if attach: 281 add_attached_file(fpath) --> 282 exec(load_cython(fpath), globals) 283 elif ext in ['.f', '.f90']: 284 from sage.misc.inline_fortran import fortran

fortran File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/repl/load.py:73, in load_cython(name) 60 """ 61 Helper function to load a Cython file. 62 (...) 70 module. 71 """ 72 from sage.misc.cython import cython ---> 73 mod, dir = cython(str(name), compile_message=True, use_cache=True) 74 import sys 75 sys.path.append(dir)

sys.path.append(dir) File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/misc/cython.py:317, in cython(filename, verbose, compile_message, use_cache, create_local_c_file, annotate, sage_namespace, create_local_so_file) 313 shutil.copy(filename, pyxfile) 315 # Add current working directory to includes. This is needed because 316 # we cythonize from a different directory. See Issue #24764. --> 317 standard_libs, standard_libdirs, standard_includes, aliases = _standard_libs_libdirs_incdirs_aliases() 318 includes = [os.getcwd()] + standard_includes 320 # Now do the actual build, directly calling Cython and distutils

distutils File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/misc/cachefunc.pyx:1015, in sage.misc.cachefunc.CachedFunction.__call__ (build/cythonized/sage/misc/cachefunc.c:8499)() 1013 return self.cache[k] 1014 except KeyError: -> 1015 w = self.f(args, *kwds) self.f(*args, **kwds) 1016 self.cache[k] = w 1017 return w

w File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/misc/cython.py:51, in _standard_libs_libdirs_incdirs_aliases() 37 @cached_function 38 def _standard_libs_libdirs_incdirs_aliases(): 39 r""" 40 Return the list of libraries and library directories. 41 (...) 49 {...}) 50 """ ---> 51 aliases = cython_aliases() 52 standard_libs = [ 53 'mpfr', 'gmp', 'gmpxx', 'pari', 'm', 54 'ec', 'gsl', 55 ] + aliases["CBLAS_LIBRARIES"] + [ 56 'ntl'] 57 standard_libdirs = []

[] File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/sage/env.py:442, in cython_aliases(required_modules, optional_modules) 440 else: 441 try: --> 442 aliases[var + "CFLAGS"] = pkgconfig.cflags(lib).split() 443 pc = pkgconfig.parse(lib) 444 libs = pkgconfig.libs(lib)

pkgconfig.libs(lib) File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/pkgconfig/pkgconfig.py:144, in cflags(package) 138 def cflags(package): 139 """ 140 Return the CFLAGS string returned by pkg-config. 141 142 If pkg-config ``pkg-config`` is not on path, raises EnvironmentError. ``EnvironmentError``. 143 """ --> 144 _raise_if_not_exists(package) 145 return _query(package, '--cflags')

'--cflags') File ~/mambaforge/envs/sage104/lib/python3.10/site-packages/pkgconfig/pkgconfig.py:103, in _raise_if_not_exists(package) 101 def _raise_if_not_exists(package): 102 if not exists(package): --> 103 raise PackageNotFoundError(package)

PackageNotFoundError(package) PackageNotFoundError: gdlib not found

found