← Lab 2

Python on your own machine

You've navigated the terminal β€” now let's run Python there. Watch the demo, then follow along on your laptop. Pick your OS once: 🍎 macOS or ⊞ Windows β€” every command below adjusts to match.

⏱️
No timeouts

Colab disconnects and forgets. On your machine a program runs as long as it needs β€” and it's still there tomorrow.

πŸ“„
Real programs

Your code becomes a .py file you can save, re-run, and share β€” not cells that vanish.

🐍
One tool: uv

A single command installs Python and runs your code. No hunting on python.org, no PATH headaches.

Step 1 β€” Install uv & get Python

Paste this once. It installs uv β€” the tool that manages Python for you. Copied straight from docs.astral.sh/uv.

Terminal
you@mac ~ %curl -LsSf https://astral.sh/uv/install.sh | sh
installing uv… βœ” uv is installed

⚠️ Close and reopen your terminal afterwards β€” that's how it finds the new uv command.

Now let uv fetch Python itself β€” and check it worked.

Terminal
you@mac ~ %uv python install 3.14
Installed Python 3.14
you@mac ~ %uv run python --version
Python 3.14.0

βœ… If you see Python 3.14.x, Python is on your machine β€” you never touched python.org.

Step 2 β€” A quick hello (then a catch)

uv run python opens Python's live prompt (>>>). Type, and it answers instantly.

Python
you@mac ~ %uv run python
Python 3.14.0 β€” type exit() to leave
>>> species = ["oak", "birch", "hazel"]
>>> len(species)
3
>>> exit()
…but where did it go?

The moment you typed exit(), every variable vanished. Nothing was saved.

That's the whole point of a file

The live prompt is great for a quick check. But real work lives in a .py file you can save and re-run β€” which is exactly what's next.

Step 3 β€” Run a real program 🐝

Download the bumblebee gene translator into your folder:

Terminal
you@mac ~ %curl -O https://raw.githubusercontent.com/HocheggerLab/y3-bio-python/main/lab02/translate_bee.py
translate_bee.py βœ” downloaded

It's the complete translator Claudia built in Lectures 1–4 β€” the genetic code, the clean-up, the safety checks β€” now a file you own.

Run it β€” then press Enter for the example gene:

Terminal
you@mac ~ %uv run translate_bee.py
🐝 Bumblebee gene translator
Paste a DNA sequence, or press Enter for the example.
>
DNA : ATGTTTGTT…GATTAA
Protein : MFVLTHGKPWELARIGNSVD
Length : 20 amino acids

Your turn β€” your code, your machine

You just ran real Python locally

No Colab, no timeout, no account. A program on your own laptop, translating a bumblebee gene.

Try it for real

Run it again and paste a different DNA sequence β€” one of your own from Lab 2, or a gene you find online. Same file, new data.

If something breaks
  • β–Έcommand not found: uv β†’ close and reopen your terminal (it finds uv on restart)
  • β–Έcan’t find translate_bee.py β†’ you’re not in the right folder β€” use ls / dir and cd
  • β–ΈWindows blocks the script β†’ reopen PowerShell and run the install line again

Before next lab: you ran a program someone gave you β€” next you'll write your own in VS Code. Install it now so you turn up ready: code.visualstudio.com.