index rss mastodon twitter github linkedin email
Álvaro Ramírez
sponsor

Álvaro Ramírez

13 March 2017 Installing gnuplot on macOS

UPDATE(2019-05-19 Sun): Plan A and B use options no longer available since the recent changes to remove all options from Homebrew/homebrew-core formulae. See Plan C.

Plan A

Install gnuplot Qt

If you have the resources, you can try the Qt flavor. You need at least 15GB to download and a long build. Ran out of space on my Macbook Air. Aborted.

brew install gnuplot --with-qt

Plan B

Install xquartz

brew install Caskroom/cask/xquartz

Install gnuplot x11

brew install gnuplot --with-x11

Install feedgnuplot

Feedgnuplot is handy for plotting data streams realtime.

brew install feedgnuplot

Plan C

Install with no options

brew install gnuplot

So far so good, but default gnuplot formula uses Qt and the Cocoa plugin could not be loaded:

qt.qpa.plugin: Could not find the Qt platform plugin "cocoa" in ""

Debugging

  • QT_DEBUG_PLUGINS

    Turns out you can get plugin logs using the QT_DEBUG_PLUGINS environment variable:

    export QT_DEBUG_PLUGINS=1
    

    QFactoryLoader::QFactoryLoader() checking directory path "/Users/myuser/homebrew/Cellar/gnuplot/5.2.6_1/libexec/gnuplot/5.2/platforms" …

    This led me to find out about the gnuplot/5.2/gnuplot_qt binary.

  • qt_prfxpath

    Getting the Qt prefix can be done by inspecting QtCore's strings:

    strings /Users/myuser/homebrew/Cellar/qt/5.12.3/Frameworks/QtCore.framework/QtCore | grep qt_prfxpath
    
    qt_prfxpath=/usr/local/Cellar/qt/5.12.3
    

    Ok so qt_prfxpath is pointing to /usr/local/Cellar/qt, while my installation's is at /Users/myuser/homebrew/Cellar/qt. This is problematic and indeed my fault for installing homebrew in /Users/myuser/homebrew instead of the recommended /usr/local.

    Symlinking did the job:

    sudo mkdir -p /usr/local/Cellar
    sudo ln -s ~/homebrew/Cellar/qt /usr/local/Cellar/qt
    
    /Users/myuser/homebrew/Cellar/gnuplot/5.2.6_1/libexec/gnuplot/5.2/gnuplot_qt
    
    QFactoryLoader::QFactoryLoader() checking directory path "/Users/myuser/homebrew/Cellar/qt/5.12.3/plugins/platforms" ...
    QFactoryLoader::QFactoryLoader() looking at "/Users/myuser/homebrew/Cellar/qt/5.12.3/plugins/platforms/libqcocoa.dylib"
    Found metadata in lib /Users/myuser/homebrew/Cellar/qt/5.12.3/plugins/platforms/libqcocoa.dylib
    

    Success.