Skip to content

Visual Studio Code Setup

VS Code is an open-source editor by Microsoft. Since its release in 2015, VS Code has become incredibly popular. See, for example, the 2024 Developer Survey by Stack Overflow.

VS Code has support for many languages, including Python, Java, C/C++, JavaScript, and more. This page explains how to install and configure VS Code for Python in CS 149.

Note

If you are on a CS lab machine, Python and VS Code are already installed. Skip to Step 3.

Step 1: Install Python

Thonny comes with Python built-in, which is ideal for beginners. But generally, you need to install Python separately.

Visit python.org. Download the installer for your operating system, and run the installer. To verify the installation was successful, open a Terminal and type either python3 --version (on macOS) or py --version (on Windows). Your version number might be newer than the images below.

Tip

When installing on Windows, check the box for "Add python.exe to PATH".

Figure 1: Running the Python Installer
Python Installer Windows

Figure 2: Running Python in the Terminal
Terminal: java -version

Step 2: Install VS Code

Visit code.visualstudio.com and click the Download button.

  • On macOS, drag the app to the Applications folder. Additional details are available here.
  • On Windows, run the installer and follow the steps. Additional details are available here.

If you are running VS Code for the first time, you should see the Welcome Page. If you have used VS Code in the past, you will likely see your previous files.

Figure 3: VS Code's Welcome Page
Welcome - Visual Studio Code

Step 3: Install Extensions

Extensions add new features and languages to VS Code. Developers can publish extensions via the Marketplace.

Warning

For CS 149, we strongly discourage the use of AI tools. Do not install extensions like GitHub Copilot, ChatGPT, etc. You may use these tools in later courses and in your career. But for now, AI tools will likely interfere with your learning.

  1. Click the Extensions icon in the Activity Bar (on the left).
    Extensions (Ctrl+Shift+X)
  2. Search for (by name) and install the following extensions:

Note: The Python extension also installs Pylance and Python Debugger. In the end, you should have the following six extensions installed:

Figure 4: List of Installed Extensions
VS Code extensions screenshot

Step 4: User Settings

VS Code has thousands of settings that you can customize. The following settings are recommended for CS 149. You are welcome to change any of these and add your own.

  1. Press F1 to open the command pallette.
  2. Type user json and press Enter.
    • This will open a file named settings.json.
  3. Paste the following settings between the curly braces:
        "breadcrumbs.enabled": false,
        "editor.minimap.enabled": false,
        "editor.scrollBeyondLastLine": false,
        "files.insertFinalNewline": true,
        "files.trimFinalNewlines": true,
        "files.trimTrailingWhitespace": true,
        "terminal.integrated.allowChords": false,
        "workbench.tree.indent": 16,
        "autopep8.args": [
            "--max-line-length=100"
        ],
        "flake8.args": [
            "--select=D,DAR,E,F,C90,N",
            "--ignore=D401,W,E226,E123,W504,N818,E704,E24,E121,E126",
            "--max-line-length=100",
            "--docstring-convention=google",
            "--docstring-style=google",
            "--per-file-ignores=test_*:D103"
        ]
    
  4. Save and close the settings.json file.

At this point, you can open any folder in VS code and start programming.

Step 5: Your CS149 Folder

If you followed our advice at the beginning of the semester, you should a CS149 containing all your work for the course. Open this folder in VS Code by going to the File menu (at the top) and clicking "Open Folder…" The folder contents (on the left) might look like this:

CS149 folder in VS Code

Having a folder open in VS Code provides additional features that are not active when simply opening a file. For one, the Search feature (magnifying glass icon on the left) will allow you to search all of your CS 149 files.

Step 6: Virtual Environment

Once you have opened your CS149 folder, you should create a "virtual environment" (venv) for installing packages. Click the Python version number in the lower-right corner of the window:

Select interpreter button of VS Code

Then at the top of the screen, click the "Create Virtual Environment…" option. Select "Venv" and then click the Python interpreter you installed previously. This process will create a .venv folder (under your CS149 folder) that will store any packages you install.

Before moving on to the next step, make sure that your virtual environment is activated. Click the trash icon () on the top or right side of the terminal to delete all previous terminals. Then open a new terminal window. You should see the text (.venv) at the beginning of the command line.

In order to run flake8 with the CS 149 settings, you need to install a few packages. Previously, we had you install these packages via Thonny. Now that you have a separate Python installation, you will need to install the packages again. Run the following command in the terminal:

pip install darglint flake8-docstrings pep8-naming pytest-cov

Now that flake8 and related packages are installed, you will see feedback from flake8 in real time whenever you open a Python file.

Going Further (optional)

The official tutorial by Microsoft is available here: Getting Started with Python in VS Code (15 articles). You don't need to read the tutorial. We will teach you what you need to know.