Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

* Setup Programming Environment (local)

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.