Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I know there is some support for running Mathematica from Python, but is there any way to do the reverse. For example, to import some Python classes and use them in Mathematica?

share|improve this question
related: mathematica.stackexchange.com/q/1894/5 (I don't know enough to tell if it's a dupe or not) –  rm -rf Dec 3 '12 at 21:59
@rm-rf: Different: that relies on .NET. –  raxacoricofallapatorius Dec 3 '12 at 22:01
Google Pythonika –  Mark McClure Dec 3 '12 at 22:19
@Jens He says he wants "to import some Python classes and use them in Mathematica". That's exactly what Pythonika does. I've used it to run sage from Mathematica. One of the dumbest things I've ever done, but I did it: facstaff.unca.edu/mcmcclur/Mathematica/Sage –  Mark McClure Dec 3 '12 at 22:40
@MarkMcClure: Pythonica seems not to be a viable solution. I can't get it to load (0S X 10.8.2, Python 2.7.2, Mathematica 9.0). Are there any alternatives? –  raxacoricofallapatorius Dec 12 '12 at 1:52

2 Answers 2

If all you want is to invoke Python scripts and use the output they generate in Mathematica, then simply

pythonOutput = Import["!python fullpathtoscript/your_scipt.py --some_opt arg arg ...", "String"];

is sufficient.

share|improve this answer

There's a "Python link" called Pythonika. I have used it briefly and it works.

What it does:

  • translates basic data types, including arbitrary size integers, to/from Python
  • makes it possible to implement functions in Python and call them from Mathematica

It does not provide any means to work with classes directly. Also, the implementation is rather hackish using unsafe practices (e.g. symbols are not localized to a context, and this has bitten me). To implement a link properly it would take lot more work.

I made a few basic fixes (e.g. using contexts), but I haven't used the thing in a long time. Contact me if you want the fixes.

share|improve this answer
Does nt compile and does nt work. –  Being Human Aug 12 at 20:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.