This project contains everything you need to set up a Python development environment in Visual Studio Code on Ubuntu (WSL), with support for running Python scripts and Jupyter notebooks.
Important: If you're using VS Code on Windows with Ubuntu through WSL, please refer to the WSL Setup Guide for specific instructions.
docs/wsl_setup_guide.md- Specific instructions for using VS Code with WSL (Windows Subsystem for Linux)docs/python_environment_setup.md- Detailed instructions for setting up your Python environmentsetup_environment.py- Helper script to set up a Python virtual environmentsetup_jupyter.py- Helper script to set up Jupyter notebook supportnumber_game.py- A simple number guessing game to test Python script executionpython_basics.ipynb- A sample Jupyter notebook to test notebook functionalityrequirements.txt- List of Python packages required for this project:ipykernelandjupyter- Required for Jupyter notebook functionalitynumpy,pandas,matplotlib- Used in the sample notebook for data manipulation and visualizationpylintandautopep8- Code linting and formatting tools for better code quality
.vscode/settings.json- VS Code settings for Python development.vscode/launch.json- VS Code launch configurations for running Python scripts
-
Install VS Code Extensions
- Open VS Code on Windows
- Go to Extensions (Ctrl+Shift+X)
- Search for and install:
- Remote - WSL (by Microsoft)
- Python (by Microsoft)
- Jupyter (by Microsoft)
- Pylance (by Microsoft)
- IntelliCode (by Microsoft)
-
Set Up Python Environment (One-time Setup)
- Open a terminal in VS Code connected to WSL (Terminal > New Terminal)
- The terminal should show that you're in your Ubuntu WSL environment
- Run the setup script:
# Run in VS Code's WSL terminal (one-time setup) python3 setup_environment.py - This script will:
- Create a Python virtual environment
- Ask you to activate the virtual environment
- Install required packages
- Register a Jupyter kernel
- When prompted, activate your virtual environment:
# Run this when the script prompts you source .venv/bin/activate
- After activation, the script will continue automatically
- Note: You only need to run setup_environment.py once for initial setup, but you'll need to activate the virtual environment (source .venv/bin/activate) each time you open a new terminal
-
Optional: Additional Jupyter Setup
- The setup_environment.py script already sets up Jupyter support
- If you need to set up Jupyter separately, you can run:
# Only needed if you want to set up Jupyter separately # Run in VS Code's WSL terminal with virtual environment activated python setup_jupyter.py
- This script will install Jupyter packages and register your kernel for use with VS Code
-
Test Python Script Execution
- Open
number_game.pyin VS Code connected to WSL - Run it by clicking the play button in the top-right corner or pressing F5
- Follow the prompts in the VS Code terminal to play the number guessing game
- Open
-
Test Jupyter Notebook
- Open
python_basics.ipynbin VS Code connected to WSL - When prompted, select the Python kernel you registered
- Run the cells by clicking the play button or pressing Shift+Enter
- Open
If you encounter any issues:
-
Python Interpreter Not Found
- Press Ctrl+Shift+P
- Type "Python: Select Interpreter"
- Choose the Python interpreter in your virtual environment
-
Jupyter Notebook Not Working
- Make sure you've installed the Jupyter extension
- Ensure your virtual environment is activated
- Try running
setup_jupyter.pyagain
-
Virtual Environment Issues
- If the virtual environment isn't working, try creating it manually in your Ubuntu WSL terminal:
# Run these commands in your Ubuntu WSL terminal python3 -m venv .venv source .venv/bin/activate
- If the virtual environment isn't working, try creating it manually in your Ubuntu WSL terminal:
Once you've completed the initial setup, here's your typical workflow for Python development:
-
Start VS Code and Connect to WSL
- Open VS Code on Windows
- Click the green button in the bottom-left corner
- Select "Connect to WSL" (or open VS Code directly from your Ubuntu terminal with
code .)
-
Activate Your Virtual Environment
- Open a terminal in VS Code (Terminal > New Terminal)
- Activate the virtual environment:
# Run this each time you open a new VS Code WSL terminal source .venv/bin/activate
- You'll see
(.venv)at the beginning of your terminal prompt when it's activated
-
Work on Python Files
- Open Python files in VS Code
- Run scripts with the play button or F5
- Debug with breakpoints as needed
-
Work with Jupyter Notebooks
- Open .ipynb files in VS Code
- Select your registered kernel if prompted
- Run cells with the play button or Shift+Enter
For more detailed information, refer to the python_environment_setup_plan.md and wsl_setup_guide.md files, which contain comprehensive instructions for setting up your Python development environment.