Home / 6.101 Infrastructure / Windows

Setting Up For 6.101 On Windows (via WSL)

You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

Note: While we prefer Windows users to use WSL this semester, if you have already have Cygwin installed on your Windows machine, you can follow the Cygwin setup instructions instead.

Table of Contents

1) Introduction §

In this tutorial, we will provide instructions that will allow you to install all the necessary programs your Windows computer will need to run, edit, test, and submit the Python files for each lab in this course.

2) Python for Windows§

To install Python for Windows, please follow these steps carefully and in order:

  1. Uninstall Other Pythons. If you have other versions of Python installed on your computer and you don't have a compelling reason to keep them around, we recommend uninstalling those versions of Python before continuing on with these instructions.
  2. Download the software. Download and run the Python 3.11.1 for Windows installer.
  3. Installation. After running the installer, follow the following steps carefully:
    • On the first page, check the box labeled "Add Python 3.11 to the PATH".
    • Click "Install Now". The defaults automatically include IDLE and pip which are important.
    • Wait for the installation to finish and click "finish".
  4. Test.
    • If you have any shells (Windows Command Prompt) already open, close them.
    • Open a new Command Prompt window
    • Type python --version and press enter.
    • Python should report its version as 3.11.1.

3) Text Editor or IDE§

Installing Python allows you to run Python source files on your computer. However, you will also need a program for editing your Python source files. Depending on where you learned Python and how far along you are, you may or may not already have a preferred text editor (or Integrated Development Environment) for working with Python code. If you already have something you are familiar with, feel free to use that! If not, we recommend using the "IDLE" program (which is included with most Python installations) for editing your files.

4) Command Line§

Note that the instructions below (and throughout 6.101) will often refer to using your computer's command line to run programs. We don't expect you to be familiar with using the command line before starting 6.101, and we'll try our best to explain exactly what needs to be done. If you are not familiar with the command line, we suggest reading the section of our course readings about some command-line basics before proceeding.

With time, using the command line will start to feel more comfortable. But it can feel like a lot, especially right away at the start of 6.101! If it feels overwhelming, please don't fret; we're here to help! If you have questions about any of the steps described on this page, please feel free to ask for help, either in person during lab hours or over e-mail at 6.101-help@mit.edu.

5) Installing Pytest§

For all labs, you will also need the pytest module installed to run our test cases. Because the pytest package does not come included with Python 3.11, we will use pip (Python's package installer) to download and install it. Certain labs may have additional requirements (which will be described in the writeups for those labs), but for now, pytest is all we'll need. You can install pytest from the Command Prompt terminal using a command like the following:

python -m pip install pytest

To test that pytest is installed type pytest in the command line and press enter. The first couple of lines of output should look like the following:

========================================== test session starts ======================================
platform win32 -- Python 3.11.1, pytest-7.2.1, pluggy-1.0.0

If you get an error that looks like PermissionError: [WinError 5] Access is denied, don't worry! This just means that pytest was looking for tests and ran into a directory it couldn't access. Your pytest installation is working properly.

If something like this does not appear, look for a warning from the previous command of the following form:

WARNING: The scripts py.test.exe and pytest.exe are installed in '...' which is not on PATH.

In this case, you'll want to add the specified directory to your PATH environment variable (under System Properties / Advanced tab / Environment Variables).

6) Installing WSL §

In order to submit labs, you will need to download and run a submission script that can only run in UNIX based environments. Because the Windows Operating System is not UNIX based, we can't use the Command Prompt's default Windows environment to submit the labs. To give Windows a full UNIX environment for software development, we recommend WSL (Windows Subsystem for Linux). You can follow the WSL installation instructions and install the Linux flavor of your choice (e.g. Debian, Ubuntu) under either Windows 10 or Windows 11 by opening Command Prompt and running the following line:

wsl --install --distribution Debian

After installing WSL, restart your computer, let the installation finish and choose your Linux username and password. Importantly, when typing a password no characters will appear (to hide the length / content of your password) but the command line is still taking in your input. Remember to hit enter to submit your password!

Potential installation issues:

  • If you see an error message like "The requested operation requires elevation" exit Command Prompt, and open a new Command Prompt window by right clicking and selecting "Run as an administrator" and try the command again.
  • If after restarting your computer you see an error message like "WslRegisterDistribution failed with error: 0xc03a001a Error: 0xc03a001a The requested operation could not be completed due to a virtual disk system limitation. Virtual hard disk files must be uncompressed and unencrypted and must not be sparse." Follow the instructions in this tutorial to change the folder settings to be decompressed.

7) WSL vs Windows§

Once WSL is installed, your computer now has a virtual Linux environment! For the purpose of this course, we recommend using Windows to edit, run and test your Python files and using WSL for submitting your labs.

By default, when you open Command Prompt the shell will be running in a Windows environment in your User home directory:

C:\Users\YOUR_WINDOWS_USERNAME>

You can switch to the WSL environment by searching for and running the Linux distribution program you installed (we recommended Debian but the WSL default is Ubuntu). When you open a WSL terminal you should see something like the line below appear in the command line:

YOUR_LINUX_USERNAME@YOUR_COMPUTERS_NAME:~$

Importantly, you can tell whether the command line is using a Windows environment or using a WSL environment by looking at the character at the end of the most recent line. A command line running in a Windows environment will end in > while WSL will end in a $. If you see >>> that likely means you are in a Python shell, which you can quit using the exit() command.

Another way to tell which shell is running is by using the pwd command. If you are running WSL you should see something like /mnt/c/YOUR_CURRENT_PATH output. However, running pwd in a Windows environment will output 'pwd' is not recognized as an internal or external command, operable program or batch file.

Accessing Your Files in WSL

Note also that your WSL and Windows environments share the same file system. /mnt/c/ in WSL points at the Windows C: directory. If you are having trouble navigating to a folder in the Linux terminal (cd ~ may point to a different home folder than your Windows terminal), it is always possible to run cd /mnt/c/ which will move you to the Windows's C: directory.

8) Lab Submission Script§

Throughout 6.101, every time you are ready to submit an assignment to our server to be officially tested and scored, you will run a program from the command line in your Linux environment to make that submission.

8.1) Installing the Submission Script§

In order to be able to run the program, we will first need to install it on your machine. Make sure your command line is in a WSL environment (see the WSL vs Windows section above), and then run the following lines one at a time (without including the $):

$ sudo apt install curl
$ sudo curl -o /usr/local/bin/6.101-submit https://py.mit.edu/_static/spring23/6.101-submit
$ sudo chmod a+rx /usr/local/bin/6.101-submit

You can test whether the installation succeeded by running the following command:

$ 6.101-submit -t

If everything is working, that command should have produced some output, ultimately ending with the message: "labs@py.mit.edu: Permission denied (publickey)." If you see that message, the script was installed successfully!

Note: you may see an error about ssh not being installed. If so, run the following command as well:

$ sudo apt install openssh-client

8.2) Configuring SSH Keys§

The "permission denied" message from the previous step happened because, as of right now, we do not know how to tell that it is you who is running the submission script. In order to be able to tell who you are, we will need one or more "SSH public keys" from you (one for each machine you plan to submit from).

Depending on your previous experience, you may already have one or more SSH keys installed on your machine. You can test for their presence by running the following command in WSL:

$ cat ~/.ssh/*.pub

If that command produced any output (typically a line starting with ssh-), you already have an SSH key on your machine! In that case, copy-and-paste the output into this form in order to let us know about this SSH key.

If the command above did not produce any output, that's OK, too; it just means that we'll need to take a few steps to set up a new SSH key. You can do that by running the following command in your WSL environment:

$ ssh-keygen -t ed25519

That command should ask you several questions. If you do not have a reason to change your answers to those questions, it should be fine to accept the default values for each (by hitting "Enter" at each question without typing anything). If you do choose a password here, be sure to remember it, as you will need to enter it every time you submit an assignment to the 6.101 server!

Once you have generated a key, rerun the command above in your WSL environment (cat ~/.ssh/*.pub) and copy/paste the output into this form.

8.3) Testing§

Once we have your SSH public keys, running the following command in your WSL environment should produce slightly different results from before:

$ 6.101-submit -t

Now it should report back your username, as well as your role within 6.101. If you see your username there, you should be all set!

9) Optional: Python for WSL§

For the purpose of this course, to avoid the potential confusion that comes with having multiple multiple Python environments that may have different packages or Python versions installed, we recommend using a normal Windows command line to run and test your Python files and using WSL/a Linux environment just for submitting your labs. However, if you want, you can configure WSL to run Python files and install packages using the following instructions:

To install Python 3.11 in WSL, open a terminal in your installed Linux distribution. Then run the following commands in order, one line at a time (without including the $ sign):

$ sudo apt install python3.11
$ sudo ln -s /usr/bin/python3.11 /usr/bin/python

Using sudo tells Linux that you want to run a command as an administrator, and the command line may prompt you for your password. After running the commands you can test that Python3.11 was successfully installed in your Linux environment by running the following commands:

$ sudo apt update
$ sudo apt upgrade
$ python --version
$ python3.11 --version

Both commands should output something that includes Python 3.11.

10) Optional: Pytest for WSL§

First we need to install pip in our Linux environment using the following command:

$ sudo apt install python3-pip

For all labs, you will also need the pytest module installed to run our test cases. Certain labs may have additional requirements (which will be described in the writeups for those labs), but for now, pytest is all we'll need. You can install pytest from the command line using a command like the following:

$ pip3 install pytest

(depending on your setup, you may need to type pip instead of pip3; or you may need to include sudo at the front, i.e. sudo pip3 install pytest)

You should now be able to run pytest from the command line.