Skip to article frontmatterSkip to article content

Practical: Setup Programming Environment

Visual Studio Code (VS Code)

We recommend using Visual Studio Code in this course. It is an open-sourced (free) software and is available for most of the main stream OS. Its intuitive interface and robust functionality make coding smoother and more enjoyable.

Here’s how you can get started:

  1. Download and Install VS Code: Visit the official Visual Studio Code website (https://code.visualstudio.com/Download) and download the installer compatible with your operating system. Follow the on-screen instructions during installation, accepting default settings.

  2. Install extensions: You should install Python and Jupyter plugin under the Extensions on the left side of the VS Code. Other plugins that are recommended: Git Graph, and GitHub Copilot.

  3. (For Windows only) Install Git: Download and install Git for Windows. Choose Use Windows’ default console window during installation.

(For macOS only) Install Xcode Command Line Tools: Open Terminal and run the following command:

xcode-select --install
  1. (For Windows only) Install Visual Studio C++ build tools. This will download a few GB data. You can do this after you go home!

Visual Studio Code offers a convenient file explorer panel for easy script navigation and access. You can also launch an integrated terminal using “Terminal > New Terminal” for seamless coding workflows.

Creating Python Virtual Environments

A virtual environment is a self-contained directory that contains a Python installation for a particular version of Python, plus a number of additional packages. This allows you to work on a specific project without affecting other projects or your system Python installation.

Here’s a step-by-step guide to creating virtual environments in both Windows, macOS, and Linux:

Windows
macOS
Linux
  • Install Miniconda: Download and install Miniconda from here. Follow the installation instructions and make sure to add Miniconda to your PATH environment variable.

  • Open Anaconda Prompt: After installation, open the Anaconda Prompt from the Start Menu. You should see a window like this:

(base) C:\Users\YourUsername>
  • Create the virtual environment: Run the following command, replacing “mi” with your desired environment name:
conda create -n mi python=3.13

You will see a series of prompts asking you to confirm the installation of various packages. Type y and press Enter to proceed.

  • Activate the virtual environment:
conda activate mi

Your prompt should now look like this, indicating that the environment is active:

(mi) C:\Users\YourUsername>
  • Install packages: Use conda or pip to install packages specific to your project: You might need to install the Visual Studio C++ build tools first for installing packages like spglib, which is a dependency of pymatgen. Please see the VS Code instruction #4 above.
pip install pymatgen ase jupyter
  • Deactivate the virtual environment: When you are finished working on your project, deactivate the environment by typing:
conda deactivate

Your prompt will return to:

(base) C:\Users\YourUsername>

Select Interpreter in VS Code

If you’re editing any Python code (file ends with .py), you should select your Python interpreter for your project in VS Code. Make sure you installed the Python extension in VS Code. Here’s how you can do it:

  1. Open VS Code and press Ctrl/Command+Shift+P to open the command palette. You will see a prompt like this at the top of the window:
> 
  1. Type Python: Select Interpreter in the command palette. As you type, you will see a list of options appear. Select Python: Select Interpreter from the list. The prompt will look like this:
> Python: Select Interpreter
  1. After selecting Python: Select Interpreter, you will see a list of available Python interpreters. Look for the interpreter you just created. It should be named something like Python 3.13.1 ('mi').

  2. Select the appropriate interpreter for your OS.

  3. Once selected, you should see the interpreter path at the bottom left corner of VS Code, indicating that it is now using the specified Python environment for your project.

By following these steps, you ensure that VS Code uses the correct Python interpreter, which is essential for running your code and managing dependencies correctly.

Setting Up GitHub Copilot in VS Code (Optional)

GitHub Copilot is an AI-powered code completion tool that helps you write code faster and with fewer errors. Here’s how you can set it up in Visual Studio Code:

Set Up GitHub Copilot

  1. Install the GitHub Copilot Extension:

    • Open Visual Studio Code.
    • Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window or by pressing Ctrl/Command+Shift+X.
    • In the search bar, type GitHub Copilot.
    • Click on the GitHub Copilot extension from the list and then click the Install button.
  2. Sign In to GitHub:

    • After installing the extension, you will need to sign in to your GitHub account.
    • Click on the Sign in to GitHub button that appears in the notification or go to the Accounts view and sign in from there.
    • Follow the prompts to authorize Visual Studio Code to access your GitHub account.
  3. Enable GitHub Copilot:

    • Once signed in, GitHub Copilot should be enabled automatically.
    • You can check if it is enabled by looking for the Copilot icon in the status bar at the bottom of the VS Code window.

Using GitHub Copilot

Tips for Effective Use