Skip to content

WorldEngine on Mac OsX with Python 3

Federico Tomassetti edited this page Jul 21, 2015 · 2 revisions

Thanks to Mike Simpson for sharing this!

So, it took me a little bit of finagling to get WorldEngine running on my Mac laptop under Python 3.x, and since I combined a bunch of different tips and tricks from various Google searches, I thought I'd summarize the process here, in case it's of use to anyone ... no promises about the following being at all optimal, since there was a lot of scrambling around and trying different things during the process. But as best as I can document it from my notes: The base platform was a recent-gen MacBook Pro running OS X Yosemite, version 10.10.4, including Xcode 6.4 and the associated command-line tools.

Prior to starting the process, I had already installed the Homebrew package manager, and then used it to install a non-system instance of Python 3.4.3, via:

brew update && brew install python3

Note that this symlinks the Python executables in /usr/local/bin with "*3" suffixes, to differentiate them from the system-supplied Python 2.x that lives in /usr/bin, e.g. "/usr/local/bin/pip3", "/usr/local/bin/python3", etc.

I built out all of the source under /usr/local:

cd /usr/local
mkdir src ; cd src

There were a couple of prerequisites ("cmake", used by plate-tectonics, and the Python 3-compliant branches of "PyInstaller" and "protobuf") that needed to be installed first:

brew install cmake

curl -Lo pyinstaller-python3.zip https://github.com/pyinstaller/pyinstaller/archive/python3.zip
pip3 install pyinstaller-python3.zip

pip3 install -Iv protobuf==3.0.0-alpha-1

Then it was time to build and install the "plate-tectonics" library from source:

git clone https://github.com/Mindwerks/plate-tectonics.git 
cd plate-tectonics 
cmake . 
make 
cp -p libPlateTectonics.a /usr/local/lib 
cp -p src/platecapi.hpp /usr/local/include 
cp -p src/utils.hpp /usr/local/include 
cd ..

Note that the copy commands seemed to be necessary (or sufficient, anyway) to put the appropriate library and header files in locations where they would be automatically found later on during the compilation of the WorldEngine Python bindings.

Finally I compiled and installed the main "worldengine" code from source:

git clone https://github.com/Mindwerks/worldengine.git
cd worldengine
pip3 install -r requirements_base.txt

Note that I installed the requirements from the base file; the "requirements3.txt" file adds the older 2.x version of "protobuf-py3", which wasn't needed since I had already installed the 3.x alpha version, up above.

Everything built and installed at this point, but I then ran into problems at runtime. I tracked back the errors and made a few modifications to the Python source, based on some Python 3-compliance notes about execfile, import syntax, and xrange/range. I also changed the protobuf-py3 dependency definition in the "setup.py" file. I've posted a Gist of the results of "git diff" to document the changes I made -- once those were in place, I could successfully build, install, and run "worldengine":

python3 setup.py build
python3 setup.py install

cd
worldengine world -v -n testworld -s 9 -x 128 -y 128 -q 9
[ ... got the expected output and some lovely images ... ]

I just realized that I installed PyInstaller, but in the end, didn't wind up using it for anything -- oh well. :)

As always, YMMV.

The diff you need to make it works with Python 3: https://gist.github.com/stendhal9/90db5178e0c892965a83