Using an Existing Codespace

Using an Existing Codespace#

If Colab or JupyterLite is unreliable on a school network, or you’d rather work the way real Python developers do – in a terminal, with real files – you can do your homework in a GitHub Codespace: a full computer running in your browser. This page assumes you already have one open (for CS50, or any other class) and walks through setting up this course’s own environment inside it.

Once, the first time:

  1. Start your Codespace. If you’re using CS50’s, just go to https://cs50.dev – don’t create or switch to a different folder, just use the one it opens you into.

  2. Download the tools, unzip them, and move into the new folder:

    wget https://python.porttack.com/wip-tools.zip
    unzip wip-tools.zip
    cd wip
    
  3. Create a virtual environment – your own private copy of Python for this class, kept separate from anything else in the Codespace – and activate it:

    python3 -m venv .venv
    source .venv/bin/activate
    
  4. Install the packages the chapters need:

    pip install ipykernel matplotlib pyyaml notebook
    

For each chapter, from inside wip/:

  1. Download the chapter (swap in the actual chapter number):

    wget https://raw.githubusercontent.com/porttack/working-in-python/v3/chapters/chapNN.ipynb
    

    (python3 fetch.py chapter-number also works, if you’d rather not retype the URL.)

  2. Open the chapter as a Jupyter notebook:

    code chapNN.ipynb
    

    The first time you run a cell, VS Code asks you to select a kernel:

    • Choose Install/Enable suggested extensions (installs the Python and Jupyter extensions), then run the cell again.

    • This time, choose Python Environments…, then pick .venv, marked Recommended.

Do the homework, then use “Finished? Copy your work” to turn it in.

Want every chapter at once instead?#

Two zip files are published, and both unzip straight into a ready-to-go wip/ folder:

  • wip-tools.zip – just setup.sh, fetch.py, and requirements.txt, no chapters. Unzip it, then follow steps 3-4 above (or run bash setup.sh, which sets up the same environment for you – it installs from requirements.txt, pinned exact versions, rather than typing package names by hand), and fetch chapters one at a time as you go.

  • wip.zip – the same files, plus every chapter that’s ready right now.

The all-at-once zip is a snapshot, not a live copy. If a chapter gets fixed after you download it, your copy doesn’t update on its own – if you’re not sure yours is current, re-fetch that one chapter (python3 fetch.py chapter-number, or the wget command above) rather than re-downloading the whole zip.