601.465/665 assumes familiarity with Python. This guide describes the recommended environment setup for completing homework assignments. It ensures that you’re using the same package versions as the course staff.
You should use Python 3.12 for homework assignments. We recommend working locally with an editor such as VS Code and a Python virtual environment.
The CS Linux machines are also available if you prefer to work remotely.
The CS Linux machines provide a shared Conda environment,
nlp-class, with the packages required for this course.
First, obtain a CS account by following the instructions in
Dr. Eisner’s Piazza post. Then, connect over SSH to an available
ugrad or
grad machine (SSH
guide).
After logging in, activate the shared environment:
conda activate nlp-classYou can now run Python on the remote machine.
You can also use VS Code remotely through the Remote - SSH extension.
Install Python 3.12 from the official Python website. Then open a new terminal and verify that you can run it:
macOS or Linux
python3.12 --versionWindows (PowerShell)
py -3.12 --versionSome assignment helper scripts also require Perl and a Unix-style shell. On macOS or Linux, confirm that Perl is installed by running
perl --version. On Windows, we recommend using WSL and following the Linux instructions.
Install Visual Studio Code and Microsoft’s Python extension.
For an introduction, see VS Code’s Python tutorial.
Open the assignment directory in VS Code with File > Open Folder, then use the integrated terminal for the commands below.
Open a terminal with Terminal > New Terminal,
then follow these instructions to create a virtual
environment named nlp-class. You will use this
environment for all NLP assignments throughout the semester.
macOS or Linux
VENVS=~/.venvs # or another directory name you prefer
mkdir -p $VENVS
python3.12 -m venv $VENVS/nlp-classOn Debian or Ubuntu (including WSL), if you’re using the system’s
Python rather than one from python.org, the last command may fail with a
message that ensurepip is not available. Fix this by
running sudo apt install python3.12-venv, then rerun the
command.
Windows (PowerShell)
$VENVS = ~/venvs # or another directory name you prefer
New-Item -ItemType Directory -Force $VENVS
py -3.12 -m venv $VENVS/nlp-classOptional: For larger or longer-lived Python projects, uv is a fast, modern alternative for managing Python versions, virtual environments, and dependencies.
Download the homework materials to a local directory. Open that
directory in VS Code and then select the nlp-class
environment.
Cmd/Ctrl+Shift+P).$VENVS/nlp-class.
If it does not appear in the list, choose Enter interpreter
path… and browse to $VENVS/nlp-class/bin/python on
macOS or Linux, or $VENVS/nlp-class/Scripts/python.exe on
Windows.VS Code will then associate the nlp-class environment
with this project, using it for all of the project’s Python scripts,
notebooks, tests, and tools.
VS Code will automatically activate nlp-class when you
open a new integrated terminal. If you want to run Python from a
terminal outside VS Code, or if automatic activation does not occur, you
need to first activate nlp-class within that particular
shell session.
macOS or Linux
source $VENVS/nlp-class/bin/activateWindows (PowerShell)
$VENVS/nlp-class/Scripts/Activate.ps1PowerShell may initially block activation scripts. See the Python
venvdocumentation for the recommended execution policy setting.
nlp-class environmentSo far, nlp-class is an empty environment: no special
packages will be available. So let’s add the packages required for the
assignment. With nlp-class activated, run
python -m pip install --upgrade pip
python -m pip install --upgrade -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpuwhere requirements.txt was provided in the homework
directory. For your convenience, we are trying to use the same
requirements.txt for the entire course, so you’ll probably
only have to do this for HW1 and never again.
If you have an NVIDIA GPU (on Linux or Windows), then change
cpuat the end of the URL tocu130, and you’ll get the full version of PyTorch that will use your GPU. This will add a few GB of NVIDIA libraries, though. On a Mac, no change is needed: Apple Silicon GPUs are supported by the standard version.
Note: If your solution needs any additional packages
that were not in the starter code, please add them to
requirements.txt yourself (rerunning the above commands)
and include that file in your submitted code. Then the autograder will
be able to find the additional packages and everything will run.
Each time you work on an assignment:
nlp-class environment.nlp-class. Then you can run your code:python your_program.py