2  Running Python

One of the defining characteristics of Python is that it is an interpreted language. If you’ve used a language like Java or C you’re used to having to compile your code. Python is instead typically translated to an intermediate representation (bytecode) and immediately executed without a separate compilation step.

To do this, we need a Python interpreter, a program called python (sometimes python3).

There are many ways to install & manage Python and packages. We will be using uv, a relatively new entrant that has quickly become the preferred tool of a large portion of the Python community.

WarningConda Warning

If you have already installed Python via conda/miniconda, you may need to uninstall it to get some things to work properly.

While most Python tools are mostly compatible, Conda does not follow the standards that these tools have adopted.

You are free to try to proceed without uninstalling, but if you run into issues see Paul Romer’s Escaping from Anaconda on why and how.

WarningWindows Users

If you are a Windows user, we strongly recommend using WSL to have a Linux environment on your machine.

TAs and I are used to working in a Unix-like environment as provided by MacOS, Linux, or WSL on Windows. Many commands that work on all three of these will not work in Windows Powershell.

Due to the vast number of possible configurations, course staff are not able to offer technical support for Windows-specific issues and can only offer limited support for machine-specific issues regardless of platform.

Installing uv

  1. Go to this page, and follow the instructions for your environment: installing uv.
  2. Once uv is installed, type uv python install 3.14 in your terminal.
  3. After Python is installed, verify the version with uv run python -V. You should see a version that starts with 3.14.

Using uv

For this course, every assignment will come with uv configuration files (e.g. pyproject.toml and uv.lock).

These files specify any dependencies (third-party tools and libraries) that our given project depends upon.

By having these files exist on a per-project basis, different projects can use different tools (and versions of tools), and we do not need to worry about incompatabilities between say, the version of Pandas used in a PA for this course and for a project you’re using at work.

(Behind the scenes, uv is managing a virtual environment for you, replacing virtualenv, pip, poetry, and pdm if you are familiar with those tools.)

uv sync

After checking out a project, this is the first command you should run.

It will install all necessary packages into a local environment specific to that project.

For example:

course/$ git clone git@github.com:jamesturk/assignment1.git
course/$ cd assignment1
course/assignment1/$ uv sync
Resolved 24 packages in 0.97ms
Audited 14 packages in 0.11ms

uv run <command>

To run commands using the installed dependencies, you must:

  1. Be inside the assignment directory where uv sync was previously run.
  2. Prefix those commands with uv run

So pytest becomes uv run pytest. Some common commands:

  • uv run pytest - Run tests.
  • uv run python file.py - Execute a specified python file.
  • uv run ipython - Run an interactive REPL with access to all dependencies.

uv add / uv remove

These commands add and remove dependencies, they will both update your pyproject.toml, uv.lock, and local environment.

If you see a library that gives an instruction like: pip install Django

You would instead write: uv add Django

For the most part you will not need to use this, but in later assignments where you are given the option to use different libraries, you might. Be sure to commit the changes to pyproject.toml and uv.lock!

uv remove will do the opposite: the equivalent of pip uninstall or poetry add, etc.

After reading this you may decide to dive deeper with the uv docs.

Why uv?

uv is a newer tool, if you have used Python before you may wonder why we’re adopting it.

Compared with older tools, it offers some distinct advantages:

  • It uses Python-standard conventions, such as installing packages from PyPI and using a pyproject.toml file.1
  • It allows installing Python, python packages, and eases developing locally with a single tool.2
  • It is signficantly faster than most alternatives.
  • It has quickly become a favored tool among long-time Python developers.3

Of course, you will need to use other tools in other classes, but that is par for the course in our field.

The Python REPL

One of the benefits of an interpreted language is that it is possible to run it one line at a time, in an interactive session.

uv run python

This feature of most interpreted languages is called a REPL (pronounced rep-el).

REPL stands for:

  • Read - takes user input, typically one line at a time
  • Evaluate - evaluate user input, running the code in the current context
  • Print - print the output of the evaluation automatically (without the need for a print())
  • Loop - repeat, until the user quits

This is incredibly useful, many Python programmers keep a REPL open at all times, to try out ideas / test things / look up documentation.

Exercise: python-demos directory

Let’s set up a small local Python project using uv so that we can try a different REPL and run some code together.

  1. Open a terminal and navigate (using cd) to a location where you’d like to create our demo repository.
  2. Make a new directory (mkdir python-demos) and then enter it (cd python-demos).
  3. Initialize the directory as a uv project with uv init.

This will create a pyproject.toml and some other files that aren’t needed for our purposes.

pyproject.toml exists at the root of a Python project and configures what other packages are needed.

  1. Let’s install a package with uv, run uv add ipython

This will update your pyproject.toml and uv.lock files and install the package for use from within this directory.

  1. To use this new package you can type uv run ipython from within the python-demos directory, and you will see ipython.

We’ll talk more about package management and what this tool is doing later in the course.

ipython vs python

ipython is an enhanced REPL for Python. It is using the same version of Python you already installed, but providing a different interface.

It provides command history, syntax highlighting, and a handful of other useful features that make it many people’s preferred REPL. It is up to you which you prefer, both provide access to the same core language.

You will often see interactive Python prompts shown as:

>>> x = 4 * 3
>>> print(x)
12  

The lines that begin with >>> are the Python prompt, and lines without >>> indicating output.

In ipython input/output lines are marked with In[0] and Out[0] prefixes, but when showing interactive output I will stick to convention and use >>>.

Tip: Don’t use pip (or conda)

You will see instructions using tools other than uv, but it is best to stick to a single tool.

When you are looking at Python libraries, which we’ll discuss later, you will often see instructions which state you should run pip install foo.

When you see pip install foo you should use uv add foo instead.

conda install instructions can usually be translated to uv add as well.

These tools are older than uv and can easily leave your system in a broken state, where uv restricts installs to the directory you are working in.


  1. Conda quite notably does not follow Python conventions, often leading to incompatibilities with other Python tools. It is also starting to monetize as of 2025.↩︎

  2. In the past, a combination of pyenv, pipx, poetry, and/or pdm was required to get the same functionality.↩︎

  3. See https://simonwillison.net/2024/Aug/20/uv-unified-python-packaging/ and https://andrich.me/2024/09/uv-i-am-somewhat-sold/ for more.↩︎