BANA409BANA409

Python and VS Code Setup

We use uv to manage Python and Python packages in this course. uv is a single fast tool that replaces python, pip, and virtualenv — it installs the Python interpreter for you, creates the virtual environment, and locks the package versions so that everyone in class runs exactly the same code.

Install uv

macOS / Linux — open Terminal and run:

curl -LsSf https://astral.sh/uv/install.sh | sh

Windows — open PowerShell and run:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Close and reopen your terminal, then verify the installation:

uv --version

You should see something like uv 0.12.x. If the command is not found, the terminal has not picked up the new PATH yet — close every terminal window and open a fresh one.

If you already have uv installed, upgrade it:

uv self update

Install Python 3.14

We use Python 3.14 in this course. You do not need to download Python from python.org — uv manages Python interpreters for you, and the version it installs is completely separate from whatever Python already came with your computer.

Install it, and make it your default Python at the same time:

uv python install --default 3.14

You will see output like this:

warning: The `--default` option is experimental and may change without warning. Pass `--preview-features python-install-default` to disable this warning
Installed Python 3.14.7 in 7.79s
 + cpython-3.14.7-macos-aarch64-none (python, python3, python3.14)

The warning is expected — ignore it. --default is still marked experimental in uv, but it works fine and is what we want.

The last line is the important one: (python, python3, python3.14) means uv put all three of those commands on your PATH, pointing at 3.14. That is what makes 3.14 the Python on your computer.

Close and reopen your terminal, then check:

python --version

You should see Python 3.14.x. (If you left off --default, just run the command again with it — nothing is downloaded twice.)

Also make 3.14 the default for every uv project you create:

uv python pin --global 3.14

This writes a global .python-version in your uv config folder, so any project that does not pin its own version uses 3.14 instead of whatever else happens to be installed.

See every Python version uv knows about, and which ones you already have:

uv python list

The versions marked with a path (e.g. cpython-3.14.x-macos-aarch64 followed by a path under ~/.local/share/uv/python/) are installed and ready to use. You can try it out right away:

uv run --python 3.14 python -c "import sys; print(sys.version)"

You should see 3.14.x.

Create the Course Project

You should get comfortable with command line commands. We are going to create one folder that holds all your work for this course — I use ml4biz — and turn it into a uv project. Follow the section for your operating system.

We put the folder directly in your home folder.

A note on ~

Your home folder is the one named after your user account: /Users/<your-name> on a Mac, C:\Users\<your-name> on Windows. It holds Documents, Desktop, Downloads, and so on.

Because you refer to it constantly, the command line gives it a one-character nickname: the tilde ~ (on most keyboards, Shift + the key to the left of 1). Anywhere you could type the full path to your home folder, you can type ~ instead.

On macOS these two commands are identical:

cd /Users/harrywang/ml4biz
cd ~/ml4biz

and on Windows these two are:

cd C:\Users\harrywang\ml4biz
cd ~/ml4biz

Two ~ commands worth memorizing now — they work the same in macOS Terminal and Windows PowerShell:

  • cd ~ — go straight back to your home folder from anywhere. Use this when you are lost.
  • cd ~/ml4biz — jump straight to your course folder from anywhere. This is how you will start most class sessions.

PowerShell accepts forward slashes in paths, so you can type ~/ml4biz on Windows exactly as written here — you do not have to switch to backslashes. The one place ~ does not work is the old Command Prompt (cmd.exe); there the home folder is %USERPROFILE%. Use PowerShell and you can ignore this.

You will see ~ in paths throughout this page and in the rest of the course; every time, it just means "my home folder."

Creating the Folder

macOS

Open Terminal (press Command + Space, type Terminal, hit Return). Terminal already starts in your home folder, so you can create the project right away:

mkdir ml4biz
cd ml4biz
uv init --python 3.14

The project ends up at /Users/<your-name>/ml4biz. To see it in Finder, choose Go → Home from the menu bar (or press Command + Shift + H).

Windows

Open PowerShell (press the Windows key, type PowerShell, hit Enter — the blue one, not "PowerShell ISE"). PowerShell also starts in your home folder:

mkdir ml4biz
cd ml4biz
uv init --python 3.14

The project ends up at C:\Users\<your-name>\ml4biz. To see it in File Explorer, type %USERPROFILE% in the address bar and press Enter.

Both

These commands do the same three things on either system: mkdir makes a new folder, cd moves you into it, and uv init sets up the project. --python 3.14 is the part that matters — it locks this folder to Python 3.14. After the last command you should see a message that uv initialized the project. Confirm you are in the right place and see the new files:

pwd
ls

On Windows PowerShell pwd and ls work the same way. You should see pyproject.toml, README.md, and src listed.

uv init creates a few files for you:

  • pyproject.toml — the list of packages your project needs
  • .python-version — pins the project to Python 3.14
  • src/ — a starter package uv makes for you (src/ml4biz/__init__.py). We write our notebooks and scripts at the top level of ml4biz, so you can ignore this folder for the whole course
  • README.md — a description of your project, written in Markdown
  • .gitignore — only appears if you happen to have Git installed, since uv writes it, together with a hidden .git folder, as part of setting up a Git repository. You won't use either until the Data App lecture, where you publish a project to GitHub; .gitignore keeps the .venv folder out of the repository.

The first two are the ones that matter. Note that .python-version and .gitignore start with a dot, which makes them hidden files — plain ls will not show them. Use ls -a (macOS) or ls -Force (Windows PowerShell) to see them. VS Code shows them in the file explorer either way.

If there is no .gitignore or .git

Nothing is wrong — you simply do not have command-line Git installed, so uv had nothing to set up a repository with. You can carry on. The Code Management lecture later uses GitHub Desktop, which installs its own copy of Git, and the Data App lecture shows how to turn a project folder into a repository with it.

The .python-version file is what makes this reproducible: every uv run and uv sync in this folder uses Python 3.14, no matter which Python is first on your PATH. If you ever need to change or re-pin the version, run:

uv python pin 3.14

If you forgot the --python flag when you ran uv init, uv python pin 3.14 fixes it after the fact — then delete the .venv folder and run uv sync so the environment is rebuilt on 3.14.

Install the Packages

Add every package we use this semester in one command — copy the whole thing, it is one line:

uv add ipykernel ijson numpy pandas matplotlib seaborn streamlit scipy scikit-learn joblib statsmodels xgboost plotly

uv add does everything at once: it creates a virtual environment in a hidden .venv folder inside ml4biz, installs the packages, records them in pyproject.toml, and writes the exact versions to uv.lock. It takes a minute or two the first time.

Here is what each one is for, listed in the order we first use them during the semester:

PackageWhat it isWhere we use it
ipykernelruns Jupyter notebooks inside VS Codeevery notebook
ijsonstreaming JSON parserPython Basics
numpyarrays and numerical computingNumpy Basics, then everywhere
pandasdata frames for tabular dataPandas Basics, then everywhere
matplotlibthe core plotting libraryMatplotlib Basics, then everywhere
seabornstatistical plots, nicer defaultsMatplotlib Basics, SVM, Ensembles, Clustering
streamlitturns a script into a web data appData App tutorial and lab
scipystatistics and sparse matricesData Cleaning, Decision Trees
scikit-learnthe machine learning libraryDecision Trees onward
joblibsaves trained models to diskFull Pipeline
statsmodelsregression summary tablesLinear Regression
xgboostfast boosted treesEnsemble Learning
plotlyinteractive and 3D chartsClustering, Feature Importance

Installing them all now means you will not be interrupted mid-semester. If you ever need something else later, the command is the same — for example uv add nltk.

NOTE: it's critical to have the following versions of the packages so that the sample code would work. Check what got installed:

uv pip list

Make sure your versions are the same or greater than the following:

matplotlib      3.10.0
numpy           2.0.1
pandas          2.3.1
scikit-learn    1.7.1
scipy           1.14.0
seaborn         0.13.2
statsmodels     0.14.2
streamlit       1.37.0
xgboost         2.1.0

If a version is too old, upgrade it:

uv add --upgrade pandas

Running Code

You never have to "activate" anything with uv. Prefix any command with uv run and uv will use the project's environment automatically:

uv run python -c "print('hello from uv')"
uv run python -c "import sklearn; print(sklearn.__version__)"

Both of those run right now — they do not need a file. Once you have written a script you run it the same way, by putting uv run in front of it. You will create test1.py in the VS Code section below, and from then on this is how you run it:

uv run python test1.py

uv run also re-syncs the environment first, so if you pull a new pyproject.toml from me the missing packages get installed for you.

Sharing and Restoring a Project

Because pyproject.toml and uv.lock record the exact versions, anybody can reproduce your environment with one command:

uv sync

VS Code

We use VS Code as the IDE (Integrated Development Environment) for this course. Follow the instructions at https://code.visualstudio.com/docs/setup/setup-overview to download and install VS Code.

Use the latest version. This page is written against VS Code 1.135 (August 2026). The Select Kernel and Python environment menus change often, so on an older build the menus will not match the screenshots below and some options are missing entirely. A much newer build may word things slightly differently too — follow the described steps rather than matching the pictures pixel for pixel. If you installed VS Code for a previous course, update it before you continue:

  • Check your version — Help → About on Windows, Code → About Visual Studio Code on macOS.
  • Update — Help → Check for Updates… on Windows, Code → Check for Updates… on macOS. Restart VS Code when it finishes, then check the version again.

Install the Python and Jupyter Extensions

You also need two VS Code extensions, Python and Jupyter. These are not the same thing as the packages uv add installed, and you need both halves:

  • ipykernel, which you installed with uv add, is the Python side of a notebook — the process that actually executes your cells. It lives inside your project's .venv.
  • The extensions are the VS Code side — they are what lets the editor show an .ipynb file as a notebook with runnable cells, find your environments, and talk to that kernel.

Installing one does not install the other. Extensions are installed once per computer, not per project, so you only do this the first time.

What each one gives you:

ExtensionPublisherWhat it does
PythonMicrosoftpicks the interpreter for .py files, puts the environment name in the status bar, adds Run Python File in Terminal and the debugger, and installs Pylance for autocomplete and error squiggles
JupyterMicrosoftthe notebook editor itself: cells, the run buttons, the Select Kernel picker, and notebook Export

To install them:

  1. Open the Extensions panel — click the icon in the left sidebar that looks like four small squares, or press Command + Shift + X on macOS / Ctrl + Shift + X on Windows.
  2. Type Python in the search box at the top. Choose the one published by Microsoft (it has millions of installs and a blue check mark next to the publisher name — do not grab a look-alike) and click Install. It also pulls in Pylance and Python Debugger; that is expected, leave them alone.
  3. Clear the search box, type Jupyter, again choose the Microsoft one, and click Install.
  4. If VS Code offers to Reload or Restart Extensions, do it.
  5. Check your work: type @installed in the Extensions search box. Python and Jupyter should both be in the list.

The shortcut. You can also let VS Code offer them: open a notebook, click Select Kernel in the top-right corner, and choose Install/Enable suggested extensions Python + Jupyter, which installs both in one click:

Install/Enable suggested extensions Python + Jupyter|652

If you do not see that option, you most likely have both extensions already — VS Code only offers to install what is missing. Check the Extensions panel for Python and Jupyter, and if they are there, carry on to the setup steps below.

Do not skip this. Without these two extensions VS Code cannot run notebooks — the kernel picker in step 4 below will offer nothing but this install prompt, and none of your Python environments will be listed.

Set Up the Project in VS Code

Next, we need to set up VS Code:

  1. We use the ml4biz folder you created above — you do not create a new one here. Make sure you can find it: on macOS choose Go → Home in Finder (Command + Shift + H); on Windows type %USERPROFILE% in the File Explorer address bar. This is the same folder as ~/ml4biz:

    ml4biz folder in Finder

  2. Open VS Code, then choose File → Open Folder… and select ml4biz:

    File menu, Open Folder|292

    Open the folder, not a single file. VS Code only looks for your Python environment inside the folder you opened, so opening test.ipynb on its own finds nothing. You have done it right when the Explorer on the left is headed ml4biz and lists .venv, src, pyproject.toml and uv.lock.

    Say yes when VS Code asks whether you trust the folder. The first time you open ml4biz it asks "Do you trust the authors of the files in this folder?" — choose Yes, I trust the authors. If you answer no, VS Code opens in Restricted Mode and turns off all extensions, including Python and Jupyter. Everything then looks installed but nothing works, which is a miserable thing to debug. Check the bottom-left corner of the window: if you see a blue Restricted Mode badge, click it and choose Trust.

  3. Create a new Jupyter Notebook. Choose File → New File…, then pick Jupyter Notebook from the list. Save it as test.ipynb in your ml4biz folder:

    File, New File, Jupyter Notebook

  4. Make sure the notebook uses the project's .venv environment — the one uv add created. Click the kernel name in the top-right corner to switch:

    Select Kernel button in the top right

    Choose Python Environments…:

    Select Kernel, Python Environments

    Then pick the one marked Recommended — it is named after your project and points at .venv/bin/python:

    Select a Python Environment

    On macOS the path ends in .venv/bin/python; on Windows it ends in .venv\Scripts\python.exe.

    If ml4biz is not in the list, check for Restricted Mode. Look at the bottom-left corner of the VS Code window. A blue Restricted Mode badge means extensions are disabled, so the Python extension never scans for anything. Click the badge and choose Trust, or run Ctrl + Shift + P → Workspaces: Manage Workspace Trust → Trust.

    The giveaway: the picker offers only "Install Python" and nothing else. That means VS Code can see no Python at all — not merely that it missed your ml4biz environment — and a disabled Python extension is the usual reason.

  5. Create a code cell, type print('hello world'), and run the cell to confirm the setup is correct:

    Run a code cell

    Next, create a Markdown cell and type the following:

    Markdown cell source

    which is formatted as follows once you run the cell:

    Markdown cell rendered

    Save the notebook file.

  6. Create and run a Python program. In the same folder, create test1.py containing one line, print('this is from a python program'):

    test1.py

    Tell VS Code which interpreter to use for .py files. Click the Python version in the status bar at the bottom right of the window:

    Python version in the status bar

    That opens the interpreter list:

    Select Interpreter list

    and pick the same .venv interpreter inside your ml4biz folder that you chose in step 4.

    Save the file, then right click test1.py in the Explorer and choose Run Python File in Terminal:

    Run Python File in Terminal

    The result of the program is shown in the terminal.

    You can also open a terminal inside VS Code (Terminal → New Terminal):

    VS Code integrated terminal

    It opens already in your ml4biz folder, so you can run the program directly:

    uv run python test1.py

    Finally, notebooks can be exported as a Python script (.py), HTML, or PDF. Open test.ipynb, click the ⋯ button in the notebook toolbar, and choose Export:

    Notebook toolbar, Export

    then pick the format you want:

    Export As formats

Cheat Sheet

TaskCommand
Check uv versionuv --version
Install Python + make it defaultuv python install --default 3.14
Make 3.14 the default for new projectsuv python pin --global 3.14
List Python versionsuv python list
Pin the project's Pythonuv python pin 3.14
Start a projectuv init --python 3.14
Add a packageuv add pandas
Remove a packageuv remove pandas
Upgrade a packageuv add --upgrade pandas
List installed packagesuv pip list
Recreate the environmentuv sync
Run a programuv run python test1.py
Start Jupyter Labuv run --with jupyter jupyter lab

On this page