I'd like to know how can I call Mathematica functions from Python.
I appreciate a example, for example, using the Mathematica function Prime.
I had search about MathLink but how to use it in Python is a little obscure to me.
I tried to use a Mathematica-Python library called pyml but I hadn't no sucess, maybe because this lib looks very old (in tutorial says Mathematica 2 or 3).
Tried compile a source in Wolfram/Mathematica/8.0/SystemFiles/Links/Python
but ended with several errors when using python 2.6 (documentation says should work to python 2.3 only).
Pythonika is interesting, but, looks like is just to use in Mathematica notebooks and I would like write .py
files who calls Mathematica functions.
So, someone knows a good way to write python programs who uses Mathematica functions and can give me an example?
Everything I do regularly in Mathematica can be done in Python. Even though Mathematica has a mind-boggling amount of functionality, I only use a tiny proportion of it. I skimmed through some of my Mathematica files to see what functions I use and then looked for Python counterparts.
If you would be using Mathematica in your data science job, you would realise very soon that you wasted a lot of time by using other software like for example Python. Yes, Python is a very good software but it is not Mathematica.
You can call Mathematica function in Python using the Python MathLink module (the source you found in .../SystemFiles/Links/Python), though you'll need to edit a couple of setup files to get it up and running ([email protected] should be able to help you out there).
To use Prime from Python you would run something like:
kernel.ready()
0
kernel.putfunction("Prime",1)
kernel.putinteger(10)
kernel.flush()
kernel.ready()
1
kernel.nextpacket()
3
packetdescriptiondictionary[3]
'ReturnPacket'
kernel.getinteger()
29
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With