Related
See also my post on setting up a Git development environment and R on Windows.
Windows without WSL
-
Check if you have Windows Terminal installed. If not, install it from the Microsoft Store.
-
Launch a Windows Terminal instance. This should start a PowerShell session.
-
Update the PowerShell execution policy by running the following command:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
-
Run
Get-ExecutionPolicy
to check if it is set toRemoteSigned
. If not, try setting it again in a terminal with administrative rights. -
Check if winget (the Windows package manager) is installed. The following command should bring up details about winget. If not, install it from the Microsoft Store.
winget --help
Note
When using winget for the first time, you will be asked to accept some terms and conditions. -
Install a text editor. We will use Visual Studio Code.
winget install vscode
-
Find an appropriate Python version to install using the following command.
winget search --tag python --cmd python --source winget
This will output the following:
Name Id Version Match ----------------------------------------------------------- Python 3 Python.Python.3.9 3.9.13 Tag: python Python 3.12 Python.Python.3.12 3.12.0 Tag: python Python 3.11 Python.Python.3.11 3.11.6 Tag: python Python 3.10 Python.Python.3.10 3.10.11 Tag: python Python 2 Python.Python.2 2.7.18150 Tag: python Python Launcher Python.Launcher 3.12.0 Tag: python Miniconda3 Anaconda.Miniconda3 py39_4.10.3 Tag: python Anaconda3 Anaconda.Anaconda3 2023.09 Tag: python
-
Install Python. At the time of writing this guide, the latest version was 3.12, so I am installing 3.11.
winget install python.python.3.11
-
Check if Python was installed correctly. This command should display the version.
py --version
-
Launch Visual Studio Code and install the following extensions:
-
Create a project folder, e.g. in
C:\User\Username\Documents\project_folder
. -
Create a virtual environment in the project folder.
cd C:\User\Username\Documents\project_folder py -m venv .venv .venv\Scripts\activate
-
Install appropriate packages (e.g. JupyterLab) in the virtual environment.
py -m pip install --upgrade pip setuptools wheel py -m pip install jupyterlab matplotlib pandas
-
Create an example Jupyter Notebook in the project folder, e.g.
my_notebook.ipynb
. -
Try to open the notebook using either VS Code or JupyterLab. To launch JupyterLab, run the following in the terminal from the project folder, which will launch a web browser instance:
jupyter lab
-
Activate the kernel in the Jupyter notebook and start coding!
Windows Subsystem for Linux (WSL) - Ubuntu
-
In PowerShell, install Visual Studio Code and WSL (Ubuntu):
winget install vscode wsl --install
-
Install the WSL VS Code extension locally in Windows.
-
Launch an Ubuntu Bash shell instance from Windows Terminal.
-
Python should already be installed; check its version:
python --version
Note
Note that it’spython
on Ubuntu, notpy
. -
Launch VS Code using the WSL shell from the project folder’s directory:
cd C:/User/Username/Documents/project_folder code .
-
Install local VS Code extensions (e.g. Python and Jupyter) in WSL.
-
Set-up a virtual environment in the project folder and install relevant packages:
python3 -m venv .venv source .venv/bin/activate python -m pip install --upgrade pip setuptools wheel python -m pip install jupyterlab matplotlib pandas