How to Build MyPaint on Mac OSX (without MacPorts)

Tags: #<Tag:0x00007f1ee793ab18> #<Tag:0x00007f1ee793a6b8> #<Tag:0x00007f1ee793a2a8>

I spent a little bit of time trying to build MyPaint without MacPorts because I have Homebrew and didn’t want MacPorts to bork my system. Unfortunately, like Krita, it’s a pain in the ass to build. Thankfully, it’s not as cumbersome as Krita, but it still took a lot of time, and pressure sensitivity still doesn’t work. I loosely followed the readme here. I will just make notes here for stuff you need to adjust since that guide is catered for MacPort users.
Please note that I built this on Mavericks. I have no idea if the process will be different on Yosemite or El Capitan.
EDIT: There is a way to build MyPaint with pressure sensitivity. However, it’s very bleeding edge, and requires that you build GTK+3 from source directly rather than from Homebrew. Read my second post below this one when you get to installing GTK+3 if you want pressure sensitivity.

Setup environment variables
Just use the same export variables as in the guide. You will probably have to change the paths for them though.

  • PKG_CONFIG_PATH - where you will find .pc files for pkgconfig. If you hit on a folder with a ton of .pc files, then you’ve probably found it. In Homebrew, it’s under /usr/local/lib/pkgconfig

  • CFLAGS - include folder for most libraries used as dependencies. On non-Macports (and probably Homebrew), this is usually under /usr/local/include

  • CC and CXX flags - SCons, the build tool will use whatever default value you have set for the CC and CXX flags. My computer didn’t pick the right one, so if you get weird wrong architecture symbol errors, just set them:

      export CC="clang -arch x86_64"
      export CXX="clang++ -arch x86_64"
    

Install dependencies
I used Python 2.7 for this. You may not need the Homebrew version of this, but depending on how you have it set up, Homebrew prefers its version of Python. Which is okay, except that you will later have to tell SCons to use the Homebrew Python as well. Most of the dependencies below can be obtained through Homebrew. Sometimes, Homebrew will not link the dependencies because your system might have a version of it already. If you plan to use these dependencies for building MyPaint, you will have to link them. Use brew link [dependency] for that. If you’ve already built Krita, some of these dependencies might look familiar.

  • swig
  • scons
  • pkgconfig (you can install this from pip or Homebrew)
  • gettext (if you install this with Homebrew, make sure it’s linked.)
  • gtk3 (in Homebrew, it’s gtk+3)
  • pygobject3 (if you install this with Homebrew make sure it’s linked. Note: this is not the same as python-gi. python-gi is only for pygobject2, and if you already have it, the gi module will not build properly with MyPaint. Make sure the one linked here is from pygobject3. You can find them in /usr/local/lib/python2.7/site-packages/gi.)
  • libffi (this will probably be installed with pygobject3, but if you installed it with Homebrew, make sure it’s linked.)
  • json-c
  • hicolor-icon-theme (Should be installed with gtk3 if you’re using Homebrew)
  • librsvg
  • libpng (OSX usually comes with this. If you don’t already have it, you should get it now.)
  • lcms2 (in Homebrew, it’s little-cms2)

If you’re not building with Homebrew, you’ll need these as well:

  • glib2
  • cairo

Some dependencies you should install with pip:
sudo pip install [dependency]

  • numpy
  • scipy
  • pyobjc-framework-Cocoa (you do not need the entire pyobjc framework! Save yourself the frustration and time by only getting this one.)

Clone source files
As per the readme.

Build
Note: If you build dependencies with Homebrew, you must tell SCons to use the
Python binary from Homebrew: In SConstruct, there is a line like opts.Add('python_binary', 'python executable to build for', $). Replace $ with the actual path from the Homebrew binary: '/usr/local/Cellar/python/[version]/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python'
Do the same for the python_config option below it as well, but link to '/usr/local/Cellar/python/[version]/Frameworks/Python.framework/Versions/2.7/bin/python-config'
Then run SCons like in the instructions. I personally didn’t have to use sudo -E, but your mileage may vary.

Running
The readme suggests running the app with a -c flag, but I’m not sure if you absolutely have to specify it every time you run MyPaint. To automate that process (since there are no app bundles yet), I wrote a little script that you can run instead:

#!/bin/sh
./mypaint -c /tmp/mypaint_cfgtmp_$$

Just save it as something like mypaint.sh and run it with ./mypaint.sh from your MyPaint folder.

Troubleshooting
MyPaint can’t find its icons
If you have attempted previous installs of other graphics software like Krita, you may have set up a XDG_DATA_DIRS environment variable. MyPaint attempts to find hicolor icons from this variable, and it might not get added automatically. You will have to add it yourself. If you installed hicolor-icon-theme with Homebrew, the icons are under /usr/local/share/icons (but linking /usr/local/share should be good enough).

MacPorts Differences
I actually looked at the portfile to see the missing dependencies that I
needed that weren’t in the readme. It appears that Homebrew tends to
build the dependencies for the dependencies listed in the portfile, so I didn’t mention cairo or glib except for building from source. Also, I did a clean install from a different computer without protobuf, and found it wasn’t required. Either that, or I already had protobuf and just didn’t notice it. If you need it though, you can get it through pip.
I’ve never actually tried the MacPorts build, so I don’t know if it just builds it from source and bundles an actual OSX app, or if it just dumps the build files somewhere and links them to what looks like an app, like the Homebrew cask version of MyPaint does (which is actually outdated, and the whole reason I wrote this guide). Bundling could be an interesting exercise though.

1 Like

Pressure support is vital for MyPaint and GIMP, so it would be worth chasing this. The component that makes pressure work at all on any system is the “GDK backend” that system. This is the sub-component of GDK, itself part of GTK, that converts the OS or desktop environment’s concept of input events into GDK’s representation.

(Which backend did you use, @beelzy? I’m assuming it’s the Quartz one.)

Quartz is the display technology for OSX, occupying a role like Wayland or X11 for Linux, or WinAPI’s USER component. Its GDK backend can be found in https://git.gnome.org/browse/gtk+/tree/gdk/quartz. You’ll notice a mix of Objective C and C with GObject in there. If anyone with OSX skills wants to do some work to improve pressure support, please report to your local GTK development office! :slight_smile:

MyPaint is built on GTK, meaning we are limited by what it reports to us. We try to avoid too much backend-specific code.

Okay, good news. After a bit of chatting on the GTK+ IRC and trying to figure out how to build GTK+3 from source on OSX, I got the pressure sensitivity to work. It might not be the final version of it, and I don’t know what other tablets it works on. It does work on Wacom Intuos Pro M and Wacom Bamboo though. One thing I noticed was strange was that the gtk3 demo app that came with the build doesn’t appear to detect the pressure sensitivity like in the screenshot you posted in the other thread, but it somehow works in MyPaint.

Anyways, here’s how I did it:

First, install GTK+3 from source. I never managed to get it to work from Git directly, nor with jhbuild, so I grabbed a tarball instead and reapplied the patches.
Just follow the console commands here: http://pastebin.com/raw/VbPKirNe
I already had most of the dependencies, so I didn’t bother reinstalling anything except maybe gtk-doc, which you can get off of Homebrew as well. No idea if the tarball requires it, but if it complains about gtk-doc missing, then just install it. GTK patch from the instructions above is here: http://pastebin.com/37JR6Scc
If you need the patches for the other dependencies, they’re here:
glib: http://pastebin.com/raw/rQmD5K0d
cairo: http://pastebin.com/raw/0gEez8dW

Before you continue to the configure and make steps of installing GTK+3, you have to patch it so that it detects your tablet. I grabbed the patch from the bug report: https://bug695701.bugzilla-attachments.gnome.org/attachment.cgi?id=241615

Unfortunately, that bug report is a bit outdated, and the patch it applies to is also not recent. if you do patch -p1 -i > [patch name] in the GTK+3 source directory, it will fail on gdkevents-quartz.c. They made some changes to those functions in the meantime. I just grabbed the changes directly from the patch and applied them. It seems not to make much of a difference. Here’s mine for reference: https://gist.github.com/Algorithmus/7bfdbc6ac6ba18d254840299a218fe21
Continue with configure, make and make install as in the script.
You shouldn’t need to reinstall MyPaint after this.

Important note: I just realized that this only works if you run MyPaint from the XQuartz terminal. I tried it from the regular Terminal, and it only detects Core Pointer. I guess you do need X11 afterall.

Here’s what it looks like:

1 Like

Woohoo, pressure! Thank you for the testing you’ve done so far,

I’ve given the upstream bug a bit of a kick. Can I suggest that people bitten by this bug do the same? Add your voice, back it up on the GTK+ IRC. Yes, I am asking people to go and make (polite) nuisances of themselves once again; hiya GTK devs! :grin:

Technical Mac people with git skills: please try to put together a good, updated patch for the GTK guys using git format-patch, and attach it to the upstream report. If this work helps put pressure support back on the radar for OSX in mainstream GTK, it will save a lot of people an absolute ton of time.

It’s not something I can do myself because I don’t have a Macintosh to test on. I’m just cheerleading here. Go team? :dancer:

Here’s what upstream are saying rn. I can only ask OSX users with technical skills to join that thread and help out, because I can’t do very much to help myself.

Matthias Clasen 2016-05-03 12:49:15 UTC
(In reply to Emmanuele Bassi (:ebassi) from comment #6)

The patch in attachment 241615 [details] [review] [review] is definitely not ready
for landing in master.

But, regardless: thanks a lot for providing and testing it! It is very much appreciated. I don’t have an OS X system, so I am really relying on this kind of cooperation.