Skip to content

Sympy fails to import in rustpython #4506

Description

@jimmiebtlr

Feature

I'm unsure what feature specifically, but install and import of sympy results in an error that doesn't happen in python.

~ % rustpython -m pip install sympy                                                                                                                           
Defaulting to user installation because normal site-packages is not writeable                                                                                                            
Requirement already satisfied: sympy in ./.local/lib/rustpython3.10/site-packages (1.11.1)                                                                                               
Requirement already satisfied: mpmath>=0.19 in ./.local/lib/rustpython3.10/site-packages (from sympy) (1.2.1)                                                                            
~ % rustpython                                                                                                                                                
Welcome to the magnificent Rust Python 0.2.0 interpreter 😱 🖖  

When in the interpreter, running import sympy I get the following error.

Traceback (most recent call last):                                                                                                                                                       
  File "<stdin>", line 1, in <module>                                                                                                                                                    
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/__init__.py", line 73, in <module>                                                                                   
    from .polys import (Poly, PurePoly, poly_from_expr, parallel_poly_from_expr,                                                                                                         
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/polys/__init__.py", line 75, in <module>                                                                             
    from .polyfuncs import (symmetrize, horner, interpolate,                                                                                                                             
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/polys/polyfuncs.py", line 11, in <module>                                                                            
    from sympy.polys.specialpolys import (                                                                                                                                               
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/polys/specialpolys.py", line 297, in <module>
    from sympy.polys.rings import ring
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/polys/rings.py", line 30, in <module>
    from sympy.printing.defaults import DefaultPrinting
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/printing/__init__.py", line 5, in <module>
    from .latex import latex, print_latex, multiline_latex
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/printing/latex.py", line 18, in <module>
    from sympy.tensor.array import NDimArray
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/tensor/__init__.py", line 4, in <module>
    from .indexed import IndexedBase, Idx, Indexed
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/tensor/indexed.py", line 114, in <module>
    from sympy.functions.special.tensor_functions import KroneckerDelta
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/functions/__init__.py", line 10, in <module>
    from sympy.functions.combinatorial.numbers import (carmichael, fibonacci, lucas, tribonacci,
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/functions/combinatorial/numbers.py", line 329, in <module>
    class tribonacci(Function):
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/functions/combinatorial/numbers.py", line 374, in tribonacci
    @recurrence_memo([S.Zero, S.One, _sym**2]) 
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/core/expr.py", line 232, in __pow__
    return self._pow(other)
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/core/decorators.py", line 236, in _func
    return func(self, other)
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/core/decorators.py", line 106, in binary_op_wrapper
    return func(self, other)
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/core/expr.py", line 228, in _pow
    return Pow(self, other)
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/core/cache.py", line 74, in wrapper
    retval = func(*args, **kwargs)
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/core/cache.py", line 70, in wrapper
    retval = cfunc(*args, **kwargs)
  File "/Users/jimmie/.cargo/git/checkouts/rustpython-f8ef4d934ac33cd8/adc2325/pylib/Lib/functools.py", line 593, in wrapper
    result = user_function(*args, **kwds)
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/core/power.py", line 355, in __new__
    from sympy.functions.elementary.exponential import exp_polar
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/functions/elementary/exponential.py", line 1124, in <module>
    class LambertW(Function):
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/functions/elementary/exponential.py", line 1159, in LambertW
    _singularities = (-Pow(S.Exp1, -1, evaluate=False), S.ComplexInfinity)
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/core/cache.py", line 74, in wrapper
    retval = func(*args, **kwargs)
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/core/cache.py", line 70, in wrapper
    retval = cfunc(*args, **kwargs)
  File "/Users/jimmie/.cargo/git/checkouts/rustpython-f8ef4d934ac33cd8/adc2325/pylib/Lib/functools.py", line 593, in wrapper
    result = user_function(*args, **kwds)
  File "/Users/jimmie/.local/lib/rustpython3.10/site-packages/sympy/core/power.py", line 378, in __new__
    obj.is_commutative = (b.is_commutative and e.is_commutative)
AttributeError: can't set attribute

Python Documentation

Sympy docs are here
https://www.sympy.org/en/index.html

Activity

  1. added
    C-bugSomething isn't working
    C-compatA discrepancy between RustPython and CPython
    on Feb 15, 2023
  2. DimitrisJim commented on Feb 15, 2023

    @DimitrisJim
    Member

    Thanks!

    Definitely seems like a descriptor bug though I haven't investigated thoroughly. I'll try and find some time to reduce it to a simpler example to make it easier to work with.

  3. siefkenj commented on Jan 16, 2024

    @siefkenj

    Can confirm this issue still persists in RustPython 0.3.0 (The stacktrace is the same).

  4. jafioti commented on Apr 24, 2024

    @jafioti

    Has there been any progress on this? I've seen this issue crop up in a few different packages.

  5. youknowone commented on Oct 6, 2026

    @youknowone
    Member

    Rechecked on current main with a RustPython venv (pip install sympy). Latest SymPy 1.14.0 (mpmath 1.3.0) imports, and the originally failing Pow(S.Exp1, -1, evaluate=False).is_commutative assignment succeeds. Closing per #8982.

    — commented by Grok 4.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugSomething isn't workingC-compatA discrepancy between RustPython and CPython

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions