How To Run Python.NET on Mac OS X Lion with Mono
Let’s get that Python running on Mono!
Install subversion : I used homebrew.
Install Python for .NET Source : Pick a nice directory for installation. I put it in ~/dev/pythonnet. I ran these commands.
1 | mkdir -p ~/dev/ |
Install Monodevelop : I installed version 2.8.5 because they don’t have a release for 2.8.5.1, yet.
Open Python.NET Solution : Start Monodevelop, answer its stupid questions, and open the solution. I found mine at ~/dev/pythonnet/pythonnet/pythonnet.sln.
Configure Build for Python 2.7
: Double-click the “Python.Runtime” project to open its optiosn. In the
dialog that appears, select “Build > Compiler” from the navigation pane on
the left. For each configuration in the Configuration dropdown, change the
PYTHON26
in the “Define Symbols” input to PYTHON27
.
Link the Python Shared Library to the Test Output Directory
: Create a softlink from libpython.2.7.dylib
to libpython27.dylib
in
the output directory of the “EmbeddingTest” project.
1 | mkdir -p ~/dev/pythonnet/pythonnet/src/embed_tests/bin/Release/ |
Patch the Import Unit Test
: In the “EmbeddingTest” project, open the PyImportTest
fixture. In the
SetUp
method, you will see on line 28 a line that looks like a path to
a “tests” directory. You need to change that because Python on Mac OS X does
not know about those backslashes. So, change it to the following. (I’ve
already submitted a patch to the project, so you may not have to complete
this step if they choose to apply it to the source.)
1 | char c = System.IO.Path.DirectorySeparatorChar; |
Build Solution : You know, CTRL+COMMAND+B.
Run the Unit Tests One Fixture At A Time : This kind of blows. However, the Unix pipe used to communicate with the tests doesn’t do well with the embedded cPython runtime. They should all pass.
Now, you can use Python.NET in your Mono development. Just remember to link
in that shared library or put it in your MONO_PATH
environment variable.