Skip to content
Alexander Zhukov edited this page May 10, 2019 · 14 revisions

You can use Qt5 based GUI widgets in your pyORBIT scripts. It will require matplotlib and PyQt5 installation.

Installing on Mac

  1. Install Xcode, launch it, agree to all license agreements (! Important)

  2. Install the latest version of macports.

    This guide is known to work for following OS/port combinations

    Mac OS version MacPorts version
    Sierra 10.12 2.5.3
    Mojave 10.14.4 2.5.4
  3. Run port

    sudo port install python27 py27-matplotlib py27-pyqt5
  4. Select python27

    sudo port select --set python python27
  5. Download a test file and make sure that it works with python

    curl -o test-qt.py https://matplotlib.org/_downloads/embedding_in_qt_sgskip.py
    python test-qt.py

    If the script fails, try replacing

    super().__init__() 

    with

    super(ApplicationWindow,self).__init__()

    in test-qt.py and run again.

  6. Reinstall pyORBIT, this is needed to compile it with correct python headers/libraries.

  7. Try running the same test-qt.py with pyORBIT

    $ORBIT_ROOT/bin/pyORBIT test-qt.py

Installing on RPM based Linux

  1. Install required packages

    yum groupinstall 'Development Tools' 'X Window System'
    yum install qt5-qtbase qt5-qtbase-devel python-devel epel-release 
    yum install python-pip
  2. Download sip and PyQt5.

    sip-4.19.7 and PyQt5_gpl-5.10 are known to work. Some newer versions are known to produce installation errors.

  3. Install sip

    cd sip-4.19.7
    python configure.py
    make
    make install
    cd ..
  4. Install PyQt5

    cd PyQt5_gpl-5.10
    python configure.py --qmake /usr/bin/qmake-qt5
    make
    make install
    cd ..
  5. Install matplotlib

    pip install --upgrade pip
    pip install -U matplotlib
  6. Try standard example with matplotlib (should draw nice plots).

    curl -o test-qt.py https://matplotlib.org/_downloads/embedding_in_qt_sgskip.py
    python test-qt.py

    If the script fails, try replacing

    super().__init__() 

    with

    super(ApplicationWindow,self).__init__()

    in test-qt.py and run again.

  7. Proceed with pyORBIT installation as usual.

  8. Try to run the same test-qt.py script with pyORBIT executable

    $ORBIT_ROOT/bin/pyORBIT test-qt.py

Imports to set Qt5 as a backend for matplotlib

import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt

Alternatively you can set an environment variable (and maybe put it in setupEnvironment.sh of your pyORBIT installation). More details are provided here.

export MPLBACKEND="Qt5Agg"
Clone this wiki locally