Skip to main content Link Search Menu Expand Document (external link)

🙋‍♂️ Tech Support

Table of contents

  1. Introduction
  2. Environments and Package Managers
  3. Replicating the Gradescope Environment
    1. Step 1: Install uv
    2. Step 2: Download pyproject.toml
    3. Step 3: Create a new environment
  4. Working on Assignments
    1. Using Git
    2. Choosing a Text Editor or IDE
    3. Using VSCode to Run Jupyter Notebooks

Introduction

In DSC 10, you worked on assignments on DataHub, a computing platform that already had all of the Python packages you needed installed. But in the real world, you’ll be expected to set up and maintain a Python environment locally – that is, on your own computer – and so that’s what we’ll have you do here. That’s right – no DataHub! You already have experience writing and running code locally from DSC 20 and DSC 30; setting up your environment for DSC 80 will be slightly more involved than it was there, but most of these steps only need to be done once.

There has been a lot written about how to set up a Python environment, so we won’t reinvent the wheel. This page will only be a summary; Google will be your main resource. But always feel free to come to a staff member’s office hours if you have a question about setting up your environment, using Git, or similar — we’re here to help.

Environments and Package Managers

For this class, the software you’ll need includes Python 3.13, a few specific Python packages, Git, and a text editor.

Gradescope has an environment which it uses to autograde your work. You can think of an environment as a combination of a Python version and specific versions of Python packages that is isolated from the rest of your computer. In practice, developers create different environments for different projects, so that they can use different versions of packages in different projects.

We’re going to have you replicate the environment Gradescope has on your computer. The reason for this is so that your code behaves the same when you submit it to Gradescope as it does when you work on it on your computer. For example, our Gradescope environment uses numpy version 2.1.1; if you install a different version of numpy on your computer, for example, you might see different results than Gradescope sees.

How do you install packages, then? pip is a common choice, but even though it’s widely used, it lacks built-in support for creating isolated environments. This limitation makes it challenging to maintain version consistency and avoid conflicts between packages. Consequently, we do not recommend relying solely on pip install for environment management, as it may inadvertently introduce incompatible package versions.

uv, on the other hand, is a powerful tool that not only installs packages but also manages environments effortlessly. It allows you to create isolated environments and ensures compatibility among the packages within those environments.


Replicating the Gradescope Environment

Below, we’re going to walk you through how to create the same environment that Gradescope uses.

Step 1: Install uv

The way to do this depends on whether you’re on a Unix-like platform (macOS or Linux) or on Windows.

Unix-like platforms (macOS or Linux):

Run the uv installer. To do this, open your Terminal and run:

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

After this step, check that uv is available by running the uv command:

$ uv
An extremely fast Python package manager.

Usage: uv [OPTIONS] <COMMAND>

...

You should see a help menu listing the available commands.

Windows:

Run the uv installer. To do this, open PowerShell and run:

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

After this step, check that uv is available by running the uv command:

PS> uv
An extremely fast Python package manager.

Usage: uv [OPTIONS] <COMMAND>

...

You should see a help menu listing the available commands.

Step 2: Download pyproject.toml

This file contains the necessary details to configure your environment. If you take a look at it, you’ll see that it contains a specific Python version (python=3.13) along with specific package versions (like pandas==2.2.3 and requests==2.32.3, for example).

Download the file, and then put it in the folder where you want to store your work.

Step 3: Create a new environment

To create the environment, navigate to your folder, then in your Terminal, run:

uv sync

You should see that uv will download and install the packages we need for the course.


Working on Assignments

The setup instructions above only need to be run once. But there’s one more thing you need to do every time you open a new terminal window: activate the environment.

For macOS/Linux, run:

source .venv/bin/activate

For Windows, run:

.venv\Scripts\activate

Now, you can open Jupyter Lab, by using the jupyter lab command in your Terminal.

Using Git

All of our course materials, including your assignments, are hosted on GitHub in this Git repository. This means that you’ll need to download and use Git in order to work with the course materials.

Git is a version control system. In short, it is used to keep track of the history of a project. With Git, you can go back in time to any previous version of your project, or even work on two different versions (or "branches") in parallel and "merge" them together at some point in the future. We'll stick to using the basic features of Git in DSC 80.

There are Git GUIs, and you can use them for this class. You can also use the command-line version of Git. To get started, you'll need to "clone" the course repository. The command to do this is:

git clone https://github.com/dsc-courses/dsc80-2024-fa

This will copy the repository to a directory on your computer. You should only need to do this once.

Moving forward, to bring in the latest version of the repository, in your local repository, run:

git pull

This will not overwrite your work. In fact, Git is designed to make it very difficult to lose work (although it's still possible!).

Merge Conflicts

You might face issues when using git pull regarding merge issues and branches. This is caused by files being updated on your side while we are also changing the Git repository by pushing new assignments on our side. Here are some steps you can follow to resolve them:

NOTE: Whenever working with GitHub pulls, merges, etc., it’s a good idea to save your important work locally so that if you accidentally overwrite your files you still have the work saved. Save your work locally before following the steps below.

  1. git status shows the current state of your Git working directory and staging area. It’s a good sanity check to start with. You will probably see your project and lab files that you have worked on.
  2. git add . will add all your files to be ready to commit.
  3. git commit -m "some message of your choice" will commit the files, with some description in the quotations. This can be whatever you want, it won’t matter.

At this stage, if you git pull, it should work. You should double-check that you have new files, as well as that your old files are unchanged. If they are changed then you should be able to just copy-paste from your local backup. If this does not work then you may have merge conflicts, follow the next steps:

  1. git checkout --theirs [FILENAME] will tell git that whenever a conflict occurs in [FILENAME] to keep your version. Run this for each file with a conflict.
  2. git add [FILENAME] to mark each file with a conflict as resolved.
  3. git rebase --continue or git merge, depending on the setup.

Choosing a Text Editor or IDE

In this class, you will need to use a combination of editors for doing your assignments: The Python files should be developed with a text editor (for syntax highlighting and running doctests) and the data/results should be analyzed/presented in Jupyter Notebooks. Below is an incomplete list of IDEs you might want to try. For more information about them, feel free to ask the course staff.

If you’re curious, Suraj uses VSCode to edit .py files and the vanilla Jupyter environment to edit notebooks.

  • The JupyterLab text editor: see below. Can be used to edit both notebooks and .py files.

  • VSCode: Microsoft Visual Studio Code. Currently very popular, and can also be used to edit both notebooks and .py files.

  • sublime: A favorite text editor of hackers, famous for its multiple cursors. A good, general-purpose choice.

  • atom: GitHub’s editor. Pretty nice fully featured IDE. Can only work locally.

  • PyCharm (IntelliJ): Those who feel at home coding Java. Can only work locally.

  • nano: available on most unix commandlines (e.g. DataHub Terminal). If you use this for more than changing a word or two, you'll hate your life.

  • (neo)vim: lightweight, productive text-editor that might be the most efficient way to edit text, if you can ever learn how to use it. Justin Eldridge’s text editor of choice.

  • emacs: A text editor for those who prefer a life of endless toil. Endlessly customizable, it promises everything, but you’re never good enough to deliver.

Using VSCode to Run Jupyter Notebooks

Many students like to use VSCode to edit Jupyter Notebooks. If that’s you, then you’ll need to make sure to activate your dsc80 conda environment within your notebook in VSCode. Here’s how to do that.

  1. Open a Juypter Notebook in VSCode.
  2. Click “Select Kernel” in the top right corner of the window.
  1. Click “Python Environments” in the toolbar that appears in the middle.
  1. Finally, click “.venv (Python 3.13.2)”.