Use simplify from Mathics in Python - python

I'm trying to use the simplify methods from Mathics in my Python program. The problem is, even I read the documentation of Mathics (https://mathics-development-guide.readthedocs.io/en/latest/extending/developing-code/calling-mathics-library-from-within-python-code.html) , I can't figure out how to use the "Simplify" method. I also tried to use the exemple one their documentation :
# This is the same as before
from mathics.session import MathicsSession
session = MathicsSession(catch_interrupt=True)
# These are Mathics classes we are going to use.
from mathics.core.expression import Expression, Integer
# Compute 20!
x = Expression("Factorial", Integer(10)
).evaluate(session.evaluation).to_python()
print(x) # 2432902008176640000
But it raised an error :
Traceback (most recent call last):
File "c:\Users\ASUS TUF\Documents\ESEO\Stage
Technique\Dev\geneticSolver\mathics_test.py", line 10, in <module>
).evaluate(session.evaluation).to_python()
File "C:\Users\ASUS TUF\AppData\Local\Programs\Python\Python310\lib\site-
packages\mathics\core\expression.py", line 441, in evaluate
names.add(expr.get_lookup_name())
File "C:\Users\ASUS TUF\AppData\Local\Programs\Python\Python310\lib\site-
packages\mathics\core\expression.py", line 636, in get_lookup_name
lookup_symbol = lookup_symbol._head
AttributeError: 'str' object has no attribute '_head'
Does anyone has already worked with Mathics on Python and can explain me how to deal with it ?

Related

(Python) ColabTurtle requires has initializeturtle() error, but we already used it

code:
import ColabTurtle.Turtle as tutel
tutel.initializeTurtle()
tutel.forward(10)
error is:
<IPython.core.display.HTML object>
Traceback (most recent call last):
File "f:\stuff\e.py", line 3, in <module>
tutel.forward(10)
File "C:\Users\U.S.E.R\AppData\Local\Programs\Python\Python311\Lib\site-packages\ColabTurtle\Turtle.py", line 174, in forward
_moveToNewPosition(ending_point)
File "C:\Users\U.S.E.R\AppData\Local\Programs\Python\Python311\Lib\site-packages\ColabTurtle\Turtle.py", line 163, in _moveToNewPosition
_updateDrawing()
File "C:\Users\U.S.E.R\AppData\Local\Programs\Python\Python311\Lib\site-packages\ColabTurtle\Turtle.py", line 144, in _updateDrawing
raise AttributeError("Display has not been initialized yet. Call initializeTurtle() before using.")
AttributeError: Display has not been initialized yet. Call initializeTurtle() before using.
basically, it tells me to use intializeturtle() before running a ColabTurtle function. Except, i did already use it.
Help.
Try to run it in Google Collab. If there will be no module ColabTurtle, you need to create a new code (+code) and write
!pip install ColabTurtle

AttributeError: 'NoneType' object has no attribute 'storid'

I am really new with ontologies especially with owlready2. I loaded an Ontology the basic example Pizza and imported I think successfully on python (I checked whether I can see the classes which I can so..)
Than I used the following code to search one class specifically with the method search():
from owlready2 import *
onto_path.append(r"C:/Users/AyselenKuru/Desktop/owl_docs/owlpizza.owl")
onto=get_ontology(r"C:/Users/AyselenKuru/Desktop/owl_docs/owlpizza.owl")
onto.load()
am= onto.search_one(is_a= onto.American)
for x in onto.classes():
print(x)
I want to know how can I search/get one specific Class and an Attribute and I get the following error message:
Traceback (most recent call last):
File "c:\Users\AyselenKuru\Desktop\pizza_ex1.py", line 6, in <module>
am= onto.search_one(is_a = onto.American)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AyselenKuru\AppData\Local\Programs\Python\Python311\Lib\site-packages\owlready2\namespace.py", line 395, in search_one
def search_one(self, **kargs): return self.search(**kargs).first()
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AyselenKuru\AppData\Local\Programs\Python\Python311\Lib\site-packages\owlready2\namespace.py", line 364, in search
else: v2 = v.storid
^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'storid'
Problem solved itself, the example owl File had errors with IRI that caused a Problem with the search

Did pyglet change recently?

So, The other day, I went back to an old project to finish it but when I tried running it, it gave me several errors that I've tried to fix but some of them I don't know how to fix. The program worked fine when I stopped working on it, so I'm very confused at what happened. My guess is that pyglet got a new update and removed a lot of stuff I used to use. Some of the errors I get are as follows
Traceback (most recent call last):
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 9,
in <module>
screen =
pyglet.window.get_platform().get_default_display().get_default_screen()
AttributeError: module 'pyglet.window' has no attribute 'get_platform'
and
Traceback (most recent call last):
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 216, in <module>
main()
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 208, in main
win = Window(caption = "3D Program 1", width = WINW, height = WINH, resizable = False, vsync = True)
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 57, in __init__
self.tex1 = get_tex("steel_tex.png")
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 21, in get_tex
tex = pyglet.image.load(file).texture
AttributeError: 'ImageData' object has no attribute 'texture'
I also had problems with it saying that there was no such thing as the "pyglet.graphics.TextureGroup" class
Yes, it looks like both of snippets of code you show are using features that were deprecated in previous versions of Pyglet and removed in the recent 1.4 release. You can see the deprecation (and their suggested replacements) in the documentation for older versions:
The get_platform() function in pyglet.window:
Deprecated. Use pyglet.canvas.Display.
The .texture attribute of an image:
Deprecated. Use get_texture().

PyPDF2 TypeError when trying to run example from lib

I've got PyPDF2 lib from here:
https://github.com/mstamy2/PyPDF2/tree/Python3-3
When trying to run script "Example 1:" from from there see it:
PyPDF2 python versions (2.5 - 3.3) compatibility branch
Traceback (most recent call last):
File "1.py", line 6, in <module>
input1 = PdfFileReader(open("document1.pdf", "rb"))
File "C:\Python33\lib\site-packages\PyPDF2\pdf.py", line 595, in __init__
self.read(stream)
File "C:\Python33\lib\site-packages\PyPDF2\pdf.py", line 1097, in read
streamData = StringIO(xrefstream.getData())
TypeError: initial_value must be str or None, not bytes
What is wrong?
It was a problem related to the compatibility within PyPDF2 and Python 3.
In my case, I have solved it by replacing pdf.py and utils.py with the ones you will find here, where they basically control if you are running Python 3 and, in case you are, receive data as bytes instead of strings.

Import error when using XPath from PyXML-0.8.4

I'm learning Xpath and XSLT using Python 2.6.6-64bit on my unix workstation. For Xpath, I'm using the xpath module provided in PyXml-0.8.4.
However, the import line itself throws the following error:
Traceback (most recent call last):
File "xp.py", line 7, in <module>
from xml.xpath import Evaluate
File "/usr/local/python-2.6.6-64bit/lib/python2.6/site-packages/_xmlplus/xpath/__init__.py", line 112, in <module>
from pyxpath import ExprParserFactory
File "/usr/local/python-2.6.6-64bit/lib/python2.6/site-packages/_xmlplus/xpath/pyxpath.py", line 59, in <module>
from xml.xpath.ParsedAbbreviatedRelativeLocationPath import ParsedAbbreviatedRelativeLocationPath
File "/usr/local/python-2.6.6-64bit/lib/python2.6/site-packages/_xmlplus/xpath/ParsedAbbreviatedRelativeLocationPath.py", line 31
as = ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self')
^
SyntaxError: invalid syntax
Looking it up led me to understand that this is because 'as' is a reserved name in python-2.6 and PyXML-0.8.4 tries to redefine it. However, there are no directions on how to resolve this issue.
Please advise.
PyXML is obsolete and should not be used (see here). That's why there are no updates for it. Many features that were included in it were added to Python's standard library. There are also fully-supported third-party packages for Python XML processing like lxml.

Categories

Resources