Notes / Python

Setting Up Jupyter Notebook in VS Code

Although Jupyter Notebook is commonly used with the Anaconda distribution, running it within VS Code makes coding easier and data management smoother. For a clear introduction to Jupyter Notebook itself, see the following article (in Japanese):
qiita.com ↗

1. Install Python

Download and install the desired version of Python from the official website (python.org ↗). If you prefer Anaconda, download it from anaconda.com ↗.

2. Install Visual Studio Code

Download and install VS Code from the official website (code.visualstudio.com ↗).

3. Create a Virtual Environment and Install Jupyter

Anaconda ships with a ready-to-use Jupyter environment, whereas a standalone Python installation requires the Jupyter packages to be installed separately.

First, prepare a virtual environment. Type cmd in the Windows search bar to open the Command Prompt, and create a directory for virtual environments. In this example, a virtual environment named jupyter is created in C:\venv.

> cd C:\
> mkdir venv
> cd venv
> python -m venv jupyter

Activate the environment and install the Jupyter packages.

> C:\venv\jupyter\Scripts\activate
(jupyter) > pip install jupyter ipykernel

Open an .ipynb file in VS Code and choose the Python interpreter of this environment via “Select Kernel” in the upper-right corner to run the notebook.