A few hours ago I was looking for a simple way to build a macOS GUI app and bemoaning the status quo of native app development (as well as the onset of panic due to the end of Summer vacation, but never mind that now…). Having used PyObjC
for a good while, it especially irked me that none of my Python runtimes seemed to support it. And now I’ve come across an embarrassment of riches of sorts…
You see, for PyObjC
to work, your Python runtime has to be compiled with the --enable-framework
option. But if, like me, you rely on pyenv
, you’ll soon figure out that pyenv
cannot currently build and install Python that way cleanly1.
Since I wanted to re-use some old Python 2 code to speed up things, the workaround I eventually found was to install python@2
from brew
(which is compiled properly and ships with PyObjC
), and then symlink that into pyenv
’s versions
folder like so:
ln -s $(brew --cellar python@2)/* ~/.pyenv/versions/
Of course, if like me you like to be able to rebuild your environment from scratch, here’s a full recipe for that:
# I have a custom wrapper script, so I need to do this
unalias brew
# Install the runtimes
brew install pyenv python python2
# Make them visible to pyenv
ln -s $(brew --cellar python)/* ~/.pyenv/versions/
ln -s $(brew --cellar python@2)/* ~/.pyenv/versions/
# Now go and develop to your heart's content
cd ~/Development/foo
pyenv local 2.7.15_1
pip install py2app cx-freeze pyinstaller
# Or, if you're using Python 3.7.0 and want the bleeding-edge pyobjc 5.0,
# which is already being tested on Mojave betas:
pyenv local 3.7.0
pip3 install py2app pyobjc cx-freeze pyinstaller
This works well to run simon, a little monitor app I found (since I wanted a nice, simple bit of code that wasn’t mine for testing), and I’ve already gotten part of what I was aiming for to work.
I suspect I’ll switch to Python 3 ASAP and see how far I can go with asyncio
and PyObjC
, especially since I just stumbled onto Toga, a cross-platform GUI toolkit that seems to work despite some issues on High Sierra.
-
There are a number of issues like this, which manifest in a number of ways. ↩︎