| title | Setup |
|---|
This lesson is designed to be run on a personal computer. All of the software and data used in this lesson are freely available online, and instructions on how to obtain them are provided below.
In this lesson, we will be using Python 3 with some of its most popular scientific libraries. We'll use uv, a modern Python package manager that makes installation simple and reliable.
First, install uv using one of these methods:
Windows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"or
winget install -e --id astral-sh.uvmacOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | shor
brew install uvuv makes Python installation simple - it will automatically install Python when needed:
uv python installThis installs the latest stable Python version. You can also specify a version:
uv python install 3.12Create a new project for this workshop:
uv init swc-python
cd swc-pythonAdd the scientific libraries we'll need:
uv add numpy matplotlibThis automatically creates a virtual environment and installs the packages.
- Download python-programming-foundations-data.zip and python-programming-foundations-code.zip.
- Move downloaded files to your
swc-pythonproject directory. - Unzip the files.
You should see two folders called data and code in the swc-python directory.
To start working with Python, we'll use uv to run Python in your project environment. This ensures you have access to all the libraries we installed. Below are several options for working with Python:
The simplest approach is to use uv run with your preferred Python interface. This automatically uses your project's virtual environment.
A Jupyter Notebook provides a browser-based interface for working with Python.
First, add Jupyter to your project:
uv add jupyterThen launch a notebook using uv:
- Navigate to your project directory:
cd swc-python- Navigate to the
datadirectory:
cd data- Start Jupyter using uv:
uv run jupyter notebook- In the browser window that opens, click "New" and select "Python 3" to create a new notebook.
IPython is an alternative solution situated somewhere in between the plain-vanilla Python interpreter and Jupyter Notebook. First add IPython to your project:
uv add ipythonTo start using IPython with uv:
uv run ipythonTo launch a plain Python interpreter using uv:
uv run pythonThis ensures you're using the Python version and packages from your project environment.
uv is a modern Python package manager that provides several benefits for beginners:
- Automatic environment management: Creates isolated environments for each project
- Fast and reliable: Downloads and installs packages quickly
- Simple commands:
uv add package_nameinstead of complex pip commands - No conflicts: Each project has its own dependencies
- Automatic Python installation: No need to manually install Python first