1 Scripting in the Jupyter Qt Console

The Jupyter Qt Console blends the simplicity of a terminal with features of a GUI to quickly test ideas, explore datasets, and work through tutorials. The interface is not intended for extended interactive use, but includes line numbers, multiple tabs, rich media output, command history retrieval across sessions, multiline editing, syntax highlighting, session export, and more.

There is a pretty quick tutorial available if you wish to practice a bit after completing this section.

1.1 Seaborn Data Visualization Library

Viewing plots in the QtConsole requires installation of the seaborn data visualization library. We’ll use my_first_env environment during this section.

  1. In Navigator, make the my_first_env environment as the active environment.
  2. Select Not Installed in the package dropdown menu
  3. Enter seaborn in the package search field
  4. Select the check box next to the seaborn package.
  5. Select the Apply button at the bottom of the panel.
  6. When the “Install packages” window pops up, select Apply in that window to install seaborn and required dependencies (there may be many).

2 Install and Launch Jupyter Qt Console Using Navigator

  1. Select the Home tab in Navigator.
  2. Select my_first_env in the dropdown to identify the environment in which to install Qt Console.
  3. Select the Install button on the Qt Console tile.
    • Ignore the package named jupyter console as it does not include graphics capability.
    • If no Qt Console package is available on the Home tab, then it has not been installed yet.
      1. In Navigator, select the Environment tab and make the my_first_env environment as the active environment.
      2. Select Not Installed in the package dropdown menu
      3. Enter qtconsole in the package search field
      4. Select the check box next to the qtconsole package.
      5. Select the Apply button at the bottom of the panel.
      6. When the “Install packages” window pops up, select Apply in that window to install seaborn and required dependencies (there may be many).
      7. Return to the Home tab, select the Refresh button. Complete steps 1-2 above.
    • If Qt console still does not appear in a tile,
      1. Return to the Environments tab and select the button for the my_first_env environment and select Open Terminal.
      2. Enter conda install qtconsole
      3. Review the messages returned, if it warns you to upgrade, enter conda update -n base -c defaults conda
      4. There will be a lengthy message to upgrade, downgrade, and remove packages below which you will need to enter y at the **Proceed? ([y],n) prompt.
      5. You may get a verification error, but the installation was likely successful.
  4. Launch Jupyter Qt Console
    1. Return to the Environments tab and select the button for the my_first_env environment and select Open Terminal.
    2. Enter jupyter qtconsole and hit enter.
    3. Input 5 * 2 + (10 / 2) adjacent to the In [1]: and Enter. The result should say Out[1]: 15.0**.

3 Qt Console Controls

3.1 Syntax Style

The console provides color-coding for various elements like the In and Out called syntax highlighting. You can choose from a large number of style types by selecting View Syntax Style at your discretion.

Open a new tab by selecting File New Tab with New kernel. You can rename the tab by entering Window Rename Current Tab. You can choose a different syntax style on each tab if you wish. That can be helpful when experimenting with different codes.

3.2 Keyboard Shortcuts

Keyboard shortcuts (or keybindings) such as Ctrl-C for copy are available at Help QtConsole help under the Key bindings heading.

The box below contains a list of these, some you will use all the time, others you may not use at all.

  • Ctrl-c copy highlighted text to clipboard (prompts are automatically stripped).
  • Ctrl-Shft-C copy highlighted text to clipboard (prompts are not stripped).
  • Ctrl-v paste text from clipboard.
  • Ctrl-z undo (retrieves lost text if you move out of a cell with the arrows).
  • Ctrl-Shft-Z redo.
  • Ctrl-l clear terminal.
  • Ctrl-a go to beginning of line.
  • Ctrl-e go to end of line.
  • Ctrl-p previous line (like up arrow)
  • Ctrl-n next line (like down arrow)
  • Ctrl-f forward (like right arrow)
  • Ctrl-b back (like left arrow)
  • Alt-< move to the beginning of the input region.
  • Alt-> move to the end of the input region.
  • Ctrl-y yank (paste)
  • Ctrl-d delete next character, or exits if input is empty
  • Alt-d delete next word.
  • Alt-backspace: delete previous word.
  • Ctrl-+ increase font size.
  • Ctrl– decrease font size.
  • Ctrl-. force a kernel restart (a confirmation dialog appears).
  • Ctrl-Alt-space toggle full screen. (Command-Control-Space on Mac OS X)
  • Ctrl-o move to ‘other’ area, between pager and terminal.
  • Ctrl-u kill from cursor to the begining of the line.
  • Ctrl-k kill from cursor to the end of the line.

3.2.1 Running code

When typing code in the console, the code on that line will execute if you select Enter unless you are working on a multi-line script.

A multi-line script can be input by selecting Ctrl-Enter after typing the first line of code. Each line input after which you insert a new line by selecting Ctrl-Enter. Once you’ve input all lines of code, select Shft-Enter to execute the script.

Basics

  1. Enter execute single line
  2. Ctrl-Enter force new line, never causes execution.
  3. Shft-Enter force execution regardless of where cursor is, no newline added.

Practice inputting the code shown below one line at a time.

  • After inputting each line, select Ctrl-Enter
  • Make sure to include the semi-colon (;) only at the end of the last line
  • After inputting the semi-colon on the last line, select Shft-Enter

The output should be four line graphs of Density vs tip for each day in the dataset. You can save this as an HTML file and open the code and graphs in a browser.

import seaborn as sns
tips = sns.load_dataset('tips')
ordered_days = tips.day.value_counts().index
chart = sns.FacetGrid(tips, row='day', row_order=ordered_days, height 1.5, aspect = 4)
chart.map(sns.kdeplot, 'tips');

3.3 Tabs and Kernels

A kernel is the active “computational engine” that executes code. When you add a new tab you have three options for the kernel

The first two are the most common. The New tab with same kernel is convenient if you are investigating alternative scripts or writing functions.