Return to Course Home Page


Installing and configuring VSCode for Python development

1. Installing Visual Studio Code:

Windows/Mac/Linux: - Navigate to the VS Code download page. - Choose your operating system and download the installer. - Follow the on-screen instructions to install VS Code.

2. Launching VS Code and Installing the Python Extension:

After installation, launch VS Code. We’ll need the Python extension to work with Python in VS Code:

  • In the sidebar, click on the icon made of four little squares (Extensions).
  • Search for “Python” in the extensions search bar.
  • Click the install button for the official Microsoft Python extension.

3. Configuring Python Interpreter and Conda:

Assuming you’ve already installed Anaconda:

Windows/Mac/Linux: - Press Ctrl+Shift+P (or Cmd+Shift+P on Mac) to open the command palette. - Type Python: Select Interpreter. - From the dropdown, choose the conda environment corresponding to your course.

4. Installing Jupyter Extension:

Since you’ll be working with Jupyter notebooks:

  • Go to Extensions again.
  • Search for “Jupyter”.
  • Install the Jupyter extension provided by Microsoft.

5. Integrating with GitHub:

  • Go to Extensions.
  • Search for “GitHub Pull Requests and Issues”.
  • Install the extension.

Once installed, you can clone repositories, manage pull requests, and even review code right within VS Code. You will need to sign in to your GitHub account when prompted.

7. Optional Extensions for Data Scientists:

Here are some other extensions that might be helpful (later in the course):

  • Github Copilot: Offers AI-assisted code suggestions.
  • Python Docstring Generator: Helps in automatically generating docstrings for Python functions.
  • GitLens: Enhances the Git capabilities of VS Code, allowing you to visualize code authorship.
  • Linters and formatters: These extensions help in linting and formatting your code. Some popular ones include Pylint, Flake8, Black, and autopep8.
  • Code Spell Checker: Helps in detecting spelling mistakes in your code.
  • R Language Support: If you’re working with R, this extension provides syntax highlighting, code snippets, and more.

There are tons of great extensions and they are easy to add and remove, so feel free to explore and experiment!

4. Launching VSCode from a terminal:

With the environment activated, you can launch VSCode from the command line:

code .

Alternatively, you can launch VSCode from the Windows Start Menu or MacOS Applications folder, or however you normally launch applications on your machine.

Once VSCode is open, you can open a new Python file. Ensure you select the “Python (eds217_2023)” kernel for your file. VSCode will prompt you to install the ipykernel package if it is not already installed. In addition, VSCode will remember the kernel you selected for each file, so you will only need to select the kernel once for each file.

Setting Up the eds217_2023 Environment in VSCode

Prerequisites:

  1. Ensure you have Visual Studio Code installed.
  2. Install the Python extension for VSCode from the Visual Studio Code Marketplace.
  3. Follow the previous instructions to set up the eds217_2023 environment on your machine.

Instructions:

1. Open the eds217_2023 Directory in VSCode:

Launch VSCode, then go to File > Open Folder (or File > Open on MacOS) and select the eds217_2023 directory that you cloned from GitHub.

2. Selecting the Python Interpreter:

Once the folder is open in VSCode:

  • Click on the Python version in the corner of the VSCode window.
  • A list of available Python interpreters will appear at the top. Look for the one that corresponds to the eds217_2023 environment. It should look something like this: Python (eds217_2023).
  • Click on it to select it. This ensures that any Python file or Jupyter notebook you open in VSCode will use the eds217_2023 environment.

3. Verify the Jupyter Kernel:

If you’re working with Jupyter notebooks in VSCode:

  • Open or create a new Jupyter notebook (.ipynb file).
  • In the top-right corner of the notebook editor, you’ll see the kernel that the notebook is using. Ensure it says Python (eds217_2023). If not, click on it and select Python (eds217_2023) from the dropdown list.

4. Troubleshooting:

If you don’t see the eds217_2023 environment in the list of available interpreters or kernels:

  • Ensure you’ve activated the environment in your terminal and installed the Jupyter kernel as described in the previous instructions.

  • Restart VSCode.

There are a ton of great tutorials that can help you make the most of VSode. Here are some of our favorites:

Code
from IPython.display import YouTubeVideo

tutorial_ids = ["h1sAzPojKMg","E9U-EBG8jVk", "zulGMYg0v6U"]
for tutorial in tutorial_ids:
    display(YouTubeVideo(tutorial))