PyNoon Plus Lesson 3

Warm-Up Exercise

  • Continue working on your Personal Python Project
  • Pair up and review each other’s project work
    • Without explaining your code, can they understand what each line achieves?
    • What changes would make it easier to read?
    • Do you have any suggestions to DRY out your partner’s code?

Thanks

  • To the host for the great venue!
  • To our sponsors

Administrivia

  • Fire escapes
  • Toilets
  • Cleaning up after ourselves
  • WiFi

Lunch Talk: Deploying Python Code

  • Sharing a Jupyter notebook
  • Users already have Python installed
  • “Native” applications (e.g. desktop or mobile app)
  • Python web applications
    • Beyond the scope of this course

Sharing a notebook

  • Option 1: Just send them the .ipynb file
    • They’ll need to open it with Colab or Jupyter
  • Option 2: Export an html or pdf file
    • Won’t run Python code, just show the code and its results

    • html files can be opened in a web browser and retain plot interactivity

    • Use nbconvert, e.g. to export as html:

      !jupyter nbconvert --HTMLExporter.require_js_url "" --to html \
          "drive/MyDrive/Colab Notebooks/pynoon_plus_1.ipynb
  • Option 3: Create an interactive web application

Sharing a notebook

  • Option 4: Create a runnable html file
    • A recent development; some Python libraries and functions won’t work
    • E.g. Panel convert, Voici, stlite
    • pyscript also lets you write Python directly in a html file (without a notebook)
    • We’ll look at Panel convert in today’s tutorial

Users already have Python installed

  • Option 1: Make a runnable zip file: zipapp
  • Option 2: Create a Python package
    • Poetry or Rye makes packaging easy
    • Share the package as a pip-installable file
    • Publish on pypi for anyone to install with pip
  • Useful for:
    • Libraries of functions for other programmers
    • Command-line apps - e.g. Built with argparse
    • Desktop/GUI apps - e.g. Built with Tkinter

Packaging a “native” application

Tutorial Objectives

  • Building user interfaces in Jupyter notebooks
  • Deploying a notebook as an html file (web page)

Independent Work/Homework

  1. Exercise Notebook:
  2. Work on your own Python project