


Edit the file to reflect your mathematica version (this might not be strictly necessary): mathematicaversion = "10.0" One of those files, the setup.py file, uses Python’s distutils facility to compile and install the Python MathLink bindings extension to our Python environment’s site-packages directory. That way, if we mess something up we have a backup of the original files. Since we will be editing these files, go ahead and copy them to a folder in which to work. Now we find the MathLink Python bindings and example code: /Applications/Mathematica.app/SystemFiles/Links/Python We’ll also need the mathlink.h header file here: /Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions I’m using the “AlternativeLibraries” version as per the README file located in that directory.

On my system it is found here: /Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions/AlternativeLibraries I’ll assume you have the usual command line developer tools installed.įirst we locate the necessary MathLink library, namely libMLi3.a.

Here I show you how I got it working on my system running Mac OS X Yosemite, Mathematica 10.0, and Python 2.7. Unfortunately the MathLink Python bindings are undocumented, unsupported, and very outdated. If you poke around in the Mathematica installation directory you will discover Python bindings for MathLink and a couple of example programs. Mathematica ships with something called MathLink that allows developers of C and C++ (and some other languages) to communicate with a Mathematical kernel programmatically. You know what would be really great, though? If we could interact with a Mathematica kernel directly from our Python code. With packages like SciPy and SymPy and the comprehensive computer algebra system Sage, Python has access to very sophisticated computational abilities. Python has gained a lot of ground in the scientific computation space. Unfortunately Mathematica is not open source and comes with a hefty price tag, but your institution might have a site license that allows you to install it on your personal computer. It provides the computational power to WolframAlpha and is available on “thousands of colleges and universities in over 50 countries” according to Wolfram Research’s ad copy. It’s a very sophisticated computer algebra system with the best notebook interface on the market if you ask me. Mathematica is the flagship product of Wolfram Research. Mathematica, Python, and Scientific Computation In which I show you how to programmatically interface with a Mathematica kernel from Python.
