Python findet sympy.parsing.mathml sublibary nicht?

McHusky  09.01.2023, 11:41

Kannst du prüfen, ob mathml im aktuellen sympy package enthalten ist? Müsste so gehen:

import sympy
dir(sympy.parsing)
Max1236 
Fragesteller
 09.01.2023, 11:49

Ausgabe ist: ['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'parse_expr', 'sympy_parser']

1 Antwort

Vom Fragesteller als hilfreich ausgezeichnet

Probier mal bitte sympy neu zu installieren mit:

pip install sympy --upgrade

und prüfe dann nochmal mit

import sympy
dir(sympy.parsing)

ob mathml enthalten ist. Wenn nicht, wurde es wahrscheinlich aus dem sympy package entfernt.

Eine Alternative dazu wäre die lxml library um den mathml string zu parsen.
Hier mal ein Beispielcode:

from lxml import etree
mathml_str = '<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>x</mi><mo>+</mo><mi>y</mi><mo>=</mo><mn>2</mn></math>'
root = etree.fromstring(mathml_str)
for element in root:
print(element.tag, element.text)
Woher ich das weiß:Recherche

Max1236 
Fragesteller
 09.01.2023, 12:55

Ist nicht mehr aufgetaucht. An die Entfernung hab ich ehrlich gar nicht gedacht. Danke dir!

0