* 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:
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. 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.
(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(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:
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.13You 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 miYour prompt should now look like this, indicating that the environment is active:
(mi) C:\Users\YourUsername>Install packages: Use
condaorpipto install packages specific to your project: You might need to install the Visual Studio C++ build tools first for installing packages likespglib, which is a dependency ofpymatgen. Please see the VS Code instruction #4 above.
pip install pymatgen ase jupyterDeactivate the virtual environment: When you are finished working on your project, deactivate the environment by typing:
conda deactivateYour prompt will return to:
(base) C:\Users\YourUsername>Install Miniconda: Download and install Miniconda from here. Follow the installation instructions and make sure to add Miniconda to your PATH environment variable.
Open Terminal: After installation, open the Terminal application from your Launchpad. You should see a window like this:
Your-MacBook:~ YourUsername$Create the virtual environment: Run the following command, replacing “mi” with your desired environment name:
conda create -n mi python=3.13You 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 miYour prompt should now look like this, indicating that the environment is active:
(mi) Your-MacBook:~ YourUsername$Install packages: Use
condaorpipto install packages specific to your project:
pip install pymatgen ase jupyterDeactivate the virtual environment: When you are finished working on your project, deactivate the environment by typing:
conda deactivateYour prompt will return to:
Your-MacBook:~ YourUsername$Install Miniconda: Download and install Miniconda from here. Follow the installation instructions and make sure to add Miniconda to your PATH environment variable.
Open Terminal: After installation, open a terminal. You should see a window like this:
yourusername@yourmachine:~$Create the virtual environment: Run the following command, replacing “mi” with your desired environment name:
conda create -n mi python=3.13You 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 miYour prompt should now look like this, indicating that the environment is active:
(mi) yourusername@yourmachine:~$Install packages: Use
condaorpipto install packages specific to your project:
pip install pymatgen ase jupyterDeactivate the virtual environment: When you are finished working on your project, deactivate the environment by typing:
conda deactivateYour prompt will return to:
yourusername@yourmachine:~$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:
Open VS Code and press
Ctrl/Command+Shift+Pto open the command palette. You will see a prompt like this at the top of the window:
> Type
Python: Select Interpreterin the command palette. As you type, you will see a list of options appear. SelectPython: Select Interpreterfrom the list. The prompt will look like this:
> Python: Select InterpreterAfter 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 likePython 3.13.1 ('mi').Select the appropriate interpreter for your OS.
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.