probleming in getting Mathics3 working

175 views
Skip to first unread message

Rashad alsharpini2

unread,
Mar 14, 2026, 12:07:37 PM (5 days ago) Mar 14
to sage-devel

so i have install the package 
`pip install mathics3` and i get this huge error log
would this be the objective of the project 'Improve integration with Mathics'
or this an isolated error for machine because i can't really i identify the error
i thought it was a mismatch in npmath package but that didn't solve it 
and there are a problem when calling the .sage() function to convert the object to a sageobj
(sage-dev) >>>    sage [develop] pip list | grep -i mathics
Mathics_Scanner               2.0.0
Mathics3                      9.0.0
(sage-dev) >>>    sage [develop] python --version
Python 3.12.12
(sage-dev) >>>    sage [develop] which python
/home/rashad/.conda/envs/sage-dev/bin/python
(sage-dev) >>>    sage [develop]
(sage-dev) >>>    sage [develop] ./sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.9.beta7, Release Date: 2026-02-25              │
│ Using Python 3.12.12. Type "help()" for help.                      │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: from sage.interfaces.mathics import mathics
sage: mobj = mathics(x^2 - 1); mobj
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/sage/sage/src/sage/interfaces/interface.py:329, in Interface._coerce_from_special_method(self, x)
    328 try:
--> 329     return (x.__getattribute__(s))(self)
    330 except AttributeError:

File sage/structure/sage_object.pyx:979, in sage.structure.sage_object.SageObject._mathics_()

File sage/symbolic/expression.pyx:1123, in sage.symbolic.expression.Expression._interface_()

File sage/structure/sage_object.pyx:723, in sage.structure.sage_object.SageObject._interface_()

File ~/sage/sage/src/sage/interfaces/interface.py:294, in Interface.__call__(self, x, name)
    293 if isinstance(x, str):
--> 294     return cls(self, x, name=name)
    295 try:
    296     # Special methods do not and should not have an option to
    297     # set the name directly, as the identifier assigned by the
    298     # interface should stay consistent. An identifier with a
    299     # user-assigned name might change its value, so we return a
    300     # new element.

File ~/sage/sage/src/sage/interfaces/interface.py:732, in InterfaceElement.__init__(self, parent, value, is_name, name)
    731 try:
--> 732     self._name = parent._create(value, name=name)
    733 except (TypeError, RuntimeError, ValueError) as x:

File ~/sage/sage/src/sage/interfaces/interface.py:515, in Interface._create(self, value, name)
    514 name = self._next_var_name() if name is None else name
--> 515 self.set(name, value)
    516 return name

File ~/sage/sage/src/sage/interfaces/mathics.py:596, in Mathics.set(self, var, value)
    595 cmd = f'{var}={value};'
--> 596 _ = self.eval(cmd)

File ~/sage/sage/src/sage/interfaces/mathics.py:579, in Mathics.eval(self, code, *args, **kwds)
    570 """
    571 Evaluates a command inside the Mathics interpreter and returns the output
    572 in printable form.
   (...)    577     '2'
    578 """
--> 579 res = self._eval(code)
    580 if res.result == 'Null':

File ~/sage/sage/src/sage/interfaces/mathics.py:562, in Mathics._eval(self, code)
    553 """
    554 Evaluates a command inside the Mathics interpreter and returns the output
    555 as a Mathics result.
   (...)    560     <Integer: 2>
    561 """
--> 562 self._lazy_init()
    563 S = self._session

File ~/sage/sage/src/sage/interfaces/mathics.py:499, in Mathics._lazy_init(self)
    498 self._initialized = True
--> 499 self._start()

File ~/sage/sage/src/sage/interfaces/mathics.py:514, in Mathics._start(self)
    513 if not self._session:
--> 514     from mathics.session import MathicsSession
    515     from mathics.core.load_builtin import import_and_load_builtins

File ~/.conda/envs/sage-dev/lib/python3.12/site-packages/mathics/session.py:19
     17 from mathics_scanner.location import ContainerKind
---> 19 from mathics.core.definitions import Definitions
     20 from mathics.core.evaluation import Evaluation, Result

File ~/.conda/envs/sage-dev/lib/python3.12/site-packages/mathics/core/definitions.py:17
     15 from mathics_scanner.tokeniser import full_names_pattern
---> 17 from mathics.core.atoms import Integer, String
     18 from mathics.core.attributes import A_NO_ATTRIBUTES

File ~/.conda/envs/sage-dev/lib/python3.12/site-packages/mathics/core/atoms.py:50
     47 T = TypeVar("T")
---> 50 class Number(Atom, ImmutableValueMixin, NumericOperators, Generic[T]):
     51     """
     52     Different kinds of Mathics Numbers, the main built-in subclasses
     53     being: Integer, Rational, Real, Complex.
     54     """

File ~/.conda/envs/sage-dev/lib/python3.12/site-packages/mathics/core/atoms.py:119, in Number()
    117     return True
--> 119 def to_mpmath(self, precision: Optional[int] = None) -> mpmath.ctx_mp_python.mpf:
    120     """
    121     Convert self.value to an mpmath number with precision ``precision``
    122     If ``precision`` is None, use mpmath's default precision.
   (...)    127     change the implementation accordingly.
    128     """

AttributeError: module 'mpmath.ctx_mp_python' has no attribute 'mpf'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 mobj = mathics(x**Integer(2) - Integer(1)); mobj

File ~/sage/sage/src/sage/interfaces/interface.py:301, in Interface.__call__(self, x, name)
    294     return cls(self, x, name=name)
    295 try:
    296     # Special methods do not and should not have an option to
    297     # set the name directly, as the identifier assigned by the
    298     # interface should stay consistent. An identifier with a
    299     # user-assigned name might change its value, so we return a
    300     # new element.
--> 301     result = self._coerce_from_special_method(x)
    302     return result if name is None else result.name(new_name=name)
    303 except TypeError:

File ~/sage/sage/src/sage/interfaces/interface.py:331, in Interface._coerce_from_special_method(self, x)
    329     return (x.__getattribute__(s))(self)
    330 except AttributeError:
--> 331     return self(x._interface_init_())

File sage/symbolic/expression.pyx:1151, in sage.symbolic.expression.Expression._interface_init_()

TypeError: _interface_init_() takes exactly 1 positional argument (0 given)
sage:

Travis Scrimshaw

unread,
Mar 14, 2026, 8:34:12 PM (5 days ago) Mar 14
to sage-devel
It seems to me you would certainly want the interface to work in a manner that is consistent with the other interfaces.

Best,
Travis

Marc Culler

unread,
Mar 14, 2026, 11:09:32 PM (4 days ago) Mar 14
to sage-devel
You are installing an extremely out of data mathics pip package which also forces installation of versions of other packages that are not compatible with SageMath 10.9.

You should run:

 %pip install Mathics3

instead.. That works for me.

- Marc

Rashad alsharpini2

unread,
Mar 15, 2026, 7:54:19 AM (4 days ago) Mar 15
to sage-...@googlegroups.com
of course but to be honest still don't understand the problem i am facing
i can't really determine if it's my setup problem or this an existing issue in the source code itself

--
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/4ea9449d-9ead-4f51-81d6-e51a0624fa29n%40googlegroups.com.

Marc Culler

unread,
Mar 15, 2026, 9:15:49 AM (4 days ago) Mar 15
to sage-devel
It is a setup problem.  You need to uninstall the pip packages that were installed with the mathics package (and the mathics package itself) and install Mathics3 instead.

- Marc

Rashad alsharpini2

unread,
Mar 15, 2026, 11:51:33 AM (4 days ago) Mar 15
to sage-devel
that's what i did and resulted and this weird problem

Dima Pasechnik

unread,
Mar 15, 2026, 12:56:06 PM (4 days ago) Mar 15
to sage-...@googlegroups.com
Have you uninstalled mathics (i.e. "pip uninstall mathics"), before
trying Mathics3 ?

There is also a potential problem that "pip install mathics" overwrote
some already installed packages, then "pip unistall" won't restore
them.
There is currently an incompatibility between mathics3 (as installed
by pip from PyPI, maybe the current development version is better),
and Sage packages sympy and mpmath.
> --
> 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/1f3136a6-dbb0-4cd4-b7f7-617888f507acn%40googlegroups.com.

Rashad alsharpini2

unread,
Mar 15, 2026, 3:00:36 PM (4 days ago) Mar 15
to sage-devel
yes i did uninstall and reinstall the package with same problem and how could i be using an out of date package i used the same thing as you wrote
(sage-dev) >>>    sage [develop] pip install mathics3
Collecting mathics3
  Using cached mathics3-9.0.0-py3-none-any.whl.metadata (4.6 kB)
Collecting Mathics-Scanner>1.4.1 (from mathics3)
  Using cached mathics_scanner-2.0.0-py3-none-any.whl.metadata (5.0 kB)
Requirement already satisfied: mpmath>=1.2.0 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (1.3.0)
Requirement already satisfied: numpy in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (2.3.5)
Collecting palettable (from mathics3)
  Using cached palettable-3.3.3-py2.py3-none-any.whl.metadata (3.3 kB)
Requirement already satisfied: pillow>=9.2 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (12.0.0)
Collecting pint (from mathics3)
  Using cached pint-0.25.2-py3-none-any.whl.metadata (10 kB)
Requirement already satisfied: python-dateutil in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (2.9.0.post0)
Collecting Pympler (from mathics3)
  Using cached Pympler-1.1-py3-none-any.whl.metadata (3.6 kB)
Requirement already satisfied: requests in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (2.32.5)
Requirement already satisfied: scipy in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (1.16.3)
Requirement already satisfied: setuptools in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (80.9.0)
Collecting stopit (from mathics3)
  Using cached stopit-1.1.2-py3-none-any.whl
Collecting sympy<1.14,>=1.13 (from mathics3)
  Using cached sympy-1.13.3-py3-none-any.whl.metadata (12 kB)
Requirement already satisfied: PyYAML in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from Mathics-Scanner>1.4.1->mathics3) (6.0.3)
Collecting chardet (from Mathics-Scanner>1.4.1->mathics3)
  Using cached chardet-7.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.metadata (7.0 kB)
Requirement already satisfied: click in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from Mathics-Scanner>1.4.1->mathics3) (8.1.8)
Collecting flexcache>=0.3 (from pint->mathics3)
  Using cached flexcache-0.3-py3-none-any.whl.metadata (7.0 kB)
Collecting flexparser>=0.4 (from pint->mathics3)
  Using cached flexparser-0.4-py3-none-any.whl.metadata (18 kB)
Requirement already satisfied: platformdirs>=2.1.0 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from pint->mathics3) (4.5.1)
Requirement already satisfied: typing-extensions>=4.0.0 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from pint->mathics3) (4.15.0)
Requirement already satisfied: six>=1.5 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from python-dateutil->mathics3) (1.17.0)
Requirement already satisfied: charset_normalizer<4,>=2 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from requests->mathics3) (3.4.4)
Requirement already satisfied: idna<4,>=2.5 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from requests->mathics3) (3.11)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from requests->mathics3) (2.6.2)
Requirement already satisfied: certifi>=2017.4.17 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from requests->mathics3) (2025.11.12)
Using cached mathics3-9.0.0-py3-none-any.whl (3.4 MB)
Using cached sympy-1.13.3-py3-none-any.whl (6.2 MB)
Using cached mathics_scanner-2.0.0-py3-none-any.whl (168 kB)
Using cached chardet-7.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (559 kB)
Using cached palettable-3.3.3-py2.py3-none-any.whl (332 kB)
Using cached pint-0.25.2-py3-none-any.whl (306 kB)
Using cached flexcache-0.3-py3-none-any.whl (13 kB)
Using cached flexparser-0.4-py3-none-any.whl (27 kB)
Using cached Pympler-1.1-py3-none-any.whl (165 kB)
Installing collected packages: stopit, sympy, Pympler, palettable, flexparser, flexcache, chardet, pint, Mathics-Scanner, mathics3
  Attempting uninstall: sympy
    Found existing installation: sympy 1.14.0
    Uninstalling sympy-1.14.0:
      Successfully uninstalled sympy-1.14.0
Successfully installed Mathics-Scanner-2.0.0 Pympler-1.1 chardet-7.1.0 flexcache-0.3 flexparser-0.4 mathics3-9.0.0 palettable-3.3.3 pint-0.25.2 stopit-1.1.2 sympy-1.13.3
(sage-dev) >>>    sage [develop] pip uninstall mathics3 mathics-scanner -y
Found existing installation: Mathics3 9.0.0
Uninstalling Mathics3-9.0.0:
  Successfully uninstalled Mathics3-9.0.0
Found existing installation: Mathics_Scanner 2.0.0
Uninstalling Mathics_Scanner-2.0.0:
  Successfully uninstalled Mathics_Scanner-2.0.0
(sage-dev) >>>    sage [develop] pip install mathics3
Collecting mathics3
  Using cached mathics3-9.0.0-py3-none-any.whl.metadata (4.6 kB)
Collecting Mathics-Scanner>1.4.1 (from mathics3)
  Using cached mathics_scanner-2.0.0-py3-none-any.whl.metadata (5.0 kB)
Requirement already satisfied: mpmath>=1.2.0 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (1.3.0)
Requirement already satisfied: numpy in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (2.3.5)
Requirement already satisfied: palettable in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (3.3.3)
Requirement already satisfied: pillow>=9.2 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (12.0.0)
Requirement already satisfied: pint in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (0.25.2)
Requirement already satisfied: python-dateutil in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (2.9.0.post0)
Requirement already satisfied: Pympler in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (1.1)
Requirement already satisfied: requests in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (2.32.5)
Requirement already satisfied: scipy in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (1.16.3)
Requirement already satisfied: setuptools in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (80.9.0)
Requirement already satisfied: stopit in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (1.1.2)
Requirement already satisfied: sympy<1.14,>=1.13 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from mathics3) (1.13.3)
Requirement already satisfied: PyYAML in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from Mathics-Scanner>1.4.1->mathics3) (6.0.3)
Requirement already satisfied: chardet in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from Mathics-Scanner>1.4.1->mathics3) (7.1.0)
Requirement already satisfied: click in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from Mathics-Scanner>1.4.1->mathics3) (8.1.8)
Requirement already satisfied: flexcache>=0.3 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from pint->mathics3) (0.3)
Requirement already satisfied: flexparser>=0.4 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from pint->mathics3) (0.4)
Requirement already satisfied: platformdirs>=2.1.0 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from pint->mathics3) (4.5.1)
Requirement already satisfied: typing-extensions>=4.0.0 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from pint->mathics3) (4.15.0)
Requirement already satisfied: six>=1.5 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from python-dateutil->mathics3) (1.17.0)
Requirement already satisfied: charset_normalizer<4,>=2 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from requests->mathics3) (3.4.4)
Requirement already satisfied: idna<4,>=2.5 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from requests->mathics3) (3.11)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from requests->mathics3) (2.6.2)
Requirement already satisfied: certifi>=2017.4.17 in /home/rashad/.conda/envs/sage-dev/lib/python3.12/site-packages (from requests->mathics3) (2025.11.12)
Using cached mathics3-9.0.0-py3-none-any.whl (3.4 MB)
Using cached mathics_scanner-2.0.0-py3-none-any.whl (168 kB)
Installing collected packages: Mathics-Scanner, mathics3
Successfully installed Mathics-Scanner-2.0.0 mathics3-9.0.0
(sage-dev) >>>    sage [develop]

Rashad alsharpini2

unread,
Mar 15, 2026, 3:00:40 PM (4 days ago) Mar 15
to sage-devel
i believe  The issue is that Sage uses its own mpmath backend (sage.libs.mpmath.ext_main) which replaces the standard mpmath.ctx_mp_python module, but mathics3 was trying to import mpf/mpc from that module.

On Sunday, March 15, 2026 at 6:56:06 PM UTC+2 dim...@gmail.com wrote:

Michael Orlitzky

unread,
Mar 15, 2026, 3:16:52 PM (4 days ago) Mar 15
to sage-...@googlegroups.com
On 2026-03-15 11:58:52, Rashad alsharpini2 wrote:
> i believe The issue is that Sage uses its own mpmath backend
> (sage.libs.mpmath.ext_main) which replaces the standard
> mpmath.ctx_mp_python module, but mathics3 was trying to import mpf/mpc from
> that module.

This should change in the next beta:

https://github.com/sagemath/sage/pull/41728

Rashad alsharpini2

unread,
Mar 15, 2026, 4:49:20 PM (4 days ago) Mar 15
to sage-devel
thanks i was about to start working  on it and reporting  it :)

Marc Culler

unread,
Mar 16, 2026, 2:45:06 PM (3 days ago) Mar 16
to sage-devel
For whatever it is worth, I tested on ubuntu 24.04 with the pre-reelase appimage for Sage 10.9, based on 10.9.beta7 with python 3.14.  
After running  %pip install mathics3  the commands:

sage: from sage.interfaces.mathics import mathics
sage: mobj = mathics(x^2 - 1); mobj

did not produce any tracebacks.  They did produce warnings that there is no module named pkg_resources, which apparently caused some components of mathics to fail to load.  Since pkg_resources is not included in Python 3.14 it would seem that mathics doesn't completely support Python 3.14 (yet?).

- Marc

seb....@gmail.com

unread,
Mar 17, 2026, 1:46:54 PM (2 days ago) Mar 17
to sage-devel
I can confirm Marc's observation. On the other hand, I can reproduce the bug even with Mathics3 7.0.0 and Sage 10.5.beta3 (from our Docker Hub repository). This constellation is interesting since the last time I successfully tested the Mathics3 interface was with that release (for pull request 37395, which was published in 10.5.beta3).

Sebastian
Reply all
Reply to author
Forward
0 new messages