Installing Python and VS Code
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.
1) Overview
This page guides you through installing Python on your computer and setting up an integrated development environment (IDE) in which to run Python code. There are separate instructions below for Windows and macOS.
The overall procedure is as follows:
- Set up a folder for your 6.100 psets.
- Install the base Python interpreter.
- Install the Visual Studio Code (VS Code) editor.
- Install the Python extension for VS Code.
- Install additional Python packages that we will use in this course.
Please follow the instructions carefully and exactly! Previous students have run into problems when they skipped steps that they thought weren't important. If you are unsure about what any of the instructions mean, ask a TA or LA during office hours.
Before starting, make sure your operating system is up-to-date. The instructions below have been tested with Windows 11, version 23H2 and macOS Sonoma, version 14.
2) Windows
2.1) Set up 6.100 folder
-
In File Explorer, create a folder called
6.100A
somewhere on your system. (Or call it6.100L
or6.100B
as appropriate.) -
Download the
1_pset0.zip
file from the top of the Pset 0 page. This file contains a compressedps0
folder. In File Explorer, right-click the file and click Extract All... to unzip it. Then move the unzippedps0
folder into6.100A
. The folder structure should look like this:6.100A |---ps0 |---ps0.py |---test_packages.py |---test_python.py
- To clearly distinguish between zip files versus folders in File Explorer, you may need to enable File name extensions under View → Show.
2.2) Install the base Python interpreter
-
Download the Python installer executable (big yellow button) from https://www.python.org/downloads/.
-
In File Explorer, double-click the executable file to run it. Click through any security warnings. When the setup window appears, do not select any checkboxes at the bottom. Just click Install Now, which accepts all the default options.
-
At the end, the installer may ask you to Disable path length limit. Click this if you see it, and click through the security warning.
-
To verify the installation, open the Command Prompt from the Start menu. This is a text-based interface for running programs, and the native Windows prompt ends with a single
>
.In this interface, type
py -3
(note the space) and pressEnter
. This launches the Python program in interactive mode, which has its own>>>
prompt.C:\Users\bob>py -3 Python 3.12.5 (tags/v3.12.5:ff3bc82, Aug 6 2024, 20:45:27) [MSC v.1940 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
-
To exit Python, press
Ctrl+Z
and thenEnter
. This should take you back to the native Windows prompt. To exit that, typeexit
and pressEnter
.
2.3) Install VS Code
-
Download the VS Code installer executable (big blue button) from https://code.visualstudio.com/.
-
Run the executable file, and click through any security warnings. Accept all the default options as you click through the setup.
-
When you click Finish, the VS Code program should launch with a Welcome tab and potentially a Release Notes tab. Ignore and close any recommendations that pop up in the bottom right.
-
Open the EXPLORER pane from its icon (first one) in the top left. Click Open Folder, navigate to and select your
6.100A
folder, and click Open. When the security warning about trust pops up, click Yes, I trust the authors. -
From the top menu bar, go to Files → Preferences → Settings, and a Settings tab will appear. Under the User category, go to Text Editor → Files, and check the boxes for the following options. (They are listed in alphabetical order.)
- Insert Final Newline
- Trim Final Newlines
- Trim Trailing Whitespace
Close the Settings tab when done.
2.4) Install the Python extension for VS Code
-
In VS Code, open the EXTENSIONS pane from its icon (fifth one) in the top left.
-
You can either search for the Python extension from Microsoft, or it may already appear in the list of POPULAR extensions.
-
Click on the tile result, which opens an Extension: Python tab. Make sure it's the official extension from Microsoft, and click Install.
-
When installation completes, you should see the Python extension tile under the INSTALLED category. There may be a couple other Python-related extensions from Microsoft as well. Now close VS Code and open it again from the Start menu.
-
Go to Files → Preferences → Settings to open a Settings tab again. Navigate to Extensions → Python, and enable the setting Terminal: Execute in File Dir.
Do not skip this step! -
Open the EXPLORER pane again, and navigate to your
ps0
folder. Double-clicktest_python.py
to open it in a tab. At the very bottom right, you should see the word Python along with the version number of your Python installation. When you click the version number, a drop-down from the top center should list exactly which executable file is being used as the Python interpreter.
-
Press
Esc
to close the drop-down, and click the Run Python File play button in the top right. This should open a TERMINAL pane at the bottom with the execution of thetest_python.py
file. -
Click in the TERMINAL pane, type your response to its query, and press
Enter
. The program should repeat what you typed. -
At the top-right of the TERMINAL pane, click the Kill Terminal trash button to close it.
2.5) Install Python packages
-
Open a new terminal in VS Code by going to Terminal → New Terminal in the top menu bar.
-
In the terminal, type each of the following commands, followed by
Enter
to execute. Do not type the>
; that just indicates the prompt.> py -3 -m pip install numpy > py -3 -m pip install matplotlib > py -3 -m pip install seaborn > py -3 -m pip install scikit-learn
Ignore any warnings in the output about a certain directory not being on
PATH
.Note: After the first command, you don’t have to completely retype the subsequent commands. By pressing the
Up
arrow while in the terminal, you can access your command history, and just change the package name at the end. -
Kill the terminal when finished.
-
Open the file
test_packages.py
, and run it by clicking the play button. After a moment, you should see a plot of earthquake magnitudes over time. -
Close the plot window, then kill the terminal.
That's it!
For future psets and lecture code downloads, just unzip them into the 6.100A
folder, and press the play button for any file you wish to run.
3) macOS
3.1) Set up 6.100 folder
-
In Finder, create a folder called
6.100A
somewhere on your system. (Or call it6.100L
or6.100B
as appropriate.) -
Download the
1_pset0.zip
file from the top of the Pset 0 page. This file contains a compressedps0
folder. In Finder, double-click the file to unzip it. Then move the unzippedps0
folder into6.100A
. The folder structure should look like this:6.100A |---ps0 |---ps0.py |---test_packages.py |---test_python.py
3.2) Install the base Python interpreter
-
Download the Python installer package (big yellow button) from https://www.python.org/downloads/.
-
In Finder, double-click the package file to run it. Click through each page in the installer. At the Installation Type step, just directly click Install and enter your password to continue; don't click Customize or anything similar to that.
-
When the installer finishes, a new Finder window will pop up. Click Close in the installer window and then Move to Trash.
-
Double-click Install Certificates.command in the Finder window. A Terminal window will pop up and run something briefly. Close both the Terminal and Finder windows.
-
To verify the installation, open a new Terminal window. This is a text-based interface for running programs, and the native macOS prompt ends with a single
%
.- If you have an older Mac, even with the latest macOS, the prompt may end with
$
instead of%
.
In this interface, type
python3
and pressEnter
. This launches the Python program in interactive mode, which has its own>>>
prompt.bob@macbook ~ % python3 Python 3.12.5 (v3.12.5:ff3bc82f7c9, Aug 7 2024, 05:32:06) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
- If you have an older Mac, even with the latest macOS, the prompt may end with
-
To exit Python, press
Control+D
. This should take you back to the native macOS prompt. To exit that, pressControl+D
again, and then close the Terminal window.
3.3) Install VS Code
-
Download the VS Code installer zip file (big blue button) from https://code.visualstudio.com/.
-
Unzip the file, which produces another file Visual Studio Code.app. Drag the file to the Applications folder in the left-side navigation under Favorites.
- If you don't see the Applications folder there, navigate to it via Go → Applications in the menu bar. Then open another Finder window, and drag the app file across windows into Applications.
-
Double-click the app file to launch it, and click through the security warning. VS Code should launch with a Welcome tab and potentially a Release Notes tab. Ignore and close any recommendations that pop up in the bottom right.
-
Open the EXPLORER pane from its icon (first one) in the top left. Click Open Folder, navigate to and select your
6.100A
folder, and click Open. When the security warning about trust pops up, click Yes, I trust the authors. -
From the menu bar, go to Code → Settings... (or Preferences on older Macs) → Settings, and a Settings tab will appear. Under the User category, go to Text Editor → Files, and check the boxes for the following options. (They are listed in alphabetical order.)
- Insert Final Newline
- Trim Final Newlines
- Trim Trailing Whitespace
Close the Settings tab when done.
3.4) Install the Python extension for VS Code
-
In VS Code, open the EXTENSIONS pane from its icon (fifth one) in the top left.
-
You can either search for the Python extension from Microsoft, or it may already appear in the list of POPULAR extensions.
-
Click on the tile result, which opens an Extension: Python tab. Make sure it's the official extension from Microsoft, and click Install.
-
When installation completes, you should see the Python extension tile under the INSTALLED category. There may be a couple other Python-related extensions from Microsoft as well. Now make sure to quit (and not just close) VS Code, and launch it again.
-
Go to Code → Settings... (or Preferences) → Settings to open a Settings tab again. Navigate to Extensions → Python, and enable the setting Terminal: Execute in File Dir.
Do not skip this step! -
Open the EXPLORER pane again, and navigate to your
ps0
folder. Double clicktest_python.py
to open it in a tab. At the very bottom right, you should see the word Python along with the version number of your Python installation. When you click the version number, a drop-down from the top center should list exactly which binary file is being used as the Python interpreter.
A small window about "python3" may pop up, asking to install the command line developer tools. Click Cancel, not Install.
-
Press
Esc
to close the drop-down, and click the Run Python File play button in the top right. This should open a TERMINAL pane at the bottom with the execution of thetest_python.py
file. -
Click in the TERMINAL pane, type your response to its query, and press
Enter
. The program should repeat what you typed. -
At the top-right of the TERMINAL pane, click the Kill Terminal trash button to close it.
3.5) Install Python packages
-
Open a new terminal in VS Code by going to Terminal → New Terminal in the menu bar.
-
In the terminal, type each of the following commands, followed by
Enter
to execute. Do not type the%
; that just indicates the prompt.% python3 -m pip install numpy % python3 -m pip install matplotlib % python3 -m pip install seaborn % python3 -m pip install scikit-learn
Ignore any warnings in the output about a certain directory not being on
PATH
.Note: After the first command, you don’t have to completely retype the subsequent commands. By pressing the
Up
arrow while in the terminal, you can access your command history, and just change the package name at the end. -
Kill the terminal when finished.
-
Open the file
test_packages.py
, and run it by clicking the play button. After a moment, you should see a plot of earthquake magnitudes over time. -
Close the plot window, then kill the terminal.
That's it!
For future psets and lecture code downloads, just unzip them into your 6.100A
folder, and press the play button for any file you wish to run.