VS Code essentials
Use VS Code to edit files, run Python, and review Git changes.
Install and open your project
- Install VS Code.
- Open File > Open Folder. Select your project folder, not one file.
- Open Extensions. Install Python from Microsoft. Install Jupyter from Microsoft only if you use
.ipynbnotebooks. - Open Terminal > New Terminal. Run commands from the project folder.
- Press Ctrl+Shift+P on Windows/Linux, or Cmd+Shift+P on macOS, to open the Command Palette.
Install the extensions you need
Open Extensions and search by name. Check that the publisher is Microsoft. Install Python for Python code, Jupyter for notebooks, and Remote - SSH only for remote server work. Add other extensions when a project needs them.
Select Python and run a file
- Create a project environment with the next guide.
- Open the Command Palette. Run Python: Select Interpreter.
- Choose the Python inside your project’s
.venv, or choose your named Conda environment. - Create
hello.py:
print("My project is ready")
- Save the file. Click Run Python File at the top of the editor.
- Read the result in the terminal. If it fails, check the selected interpreter first.
Find errors with the debugger
- Click beside a line number to add a breakpoint.
- Open Run and Debug. Start Python Debugger: Current File if VS Code asks for a configuration.
- Read the variable values when the program pauses.
- Use Step Over to run the next line. Use Continue to run to the next breakpoint.
The Microsoft Python extension installs the Python Debugger extension. You do not need a separate code-runner extension for these steps. Official debugging guide.
Use notebooks and Git carefully
- Open a notebook. Click Select Kernel at the top right. Choose the same environment as your project. A notebook kernel can differ from the Python interpreter used for
.pyfiles. - Run all cells from top to bottom before sharing results. A cell must not depend on a hidden earlier test.
- Open Source Control before each commit. Click each changed file and read the difference.
- Commit related changes with a short message. Pull before starting new work. Push after the commit.
- If Git reports a conflict, open the file and compare both versions. Ask for help if the correct version is unclear. Do not use force push to fix a conflict.
Official guides: Python in VS Code, Python environments, Source Control, and Jupyter notebooks.
Open an approved lab server with SSH
Use these steps only after you receive the server address and your account from the lab.
- Install Remote - SSH from Microsoft in VS Code.
- Check that SSH works in your computer’s terminal. Replace
usernameandHOSTNAMEwith your lab details:
ssh username@HOSTNAME
- Compare the server fingerprint with the details given by the server administrator before accepting a new host. Sign in with your assigned account.
- In VS Code, open the Command Palette. Run Remote-SSH: Connect to Host. Enter the same address.
- After it connects, use File > Open Folder to open your project on the server.
- Install the Python extension in the remote window when VS Code asks. Create or select the Python environment on the server. Your laptop’s environment is separate.
- Open a terminal and check its folder before running commands. Save changes before you disconnect.
The remote window edits and runs files on the server. Ask the lab for its account, storage, and GPU rules before starting a long job. Official Remote SSH guide.
Learn these first shortcuts
| Action | Windows / Linux | macOS |
|---|---|---|
| Save file | Ctrl+S | Cmd+S |
| Open Command Palette | Ctrl+Shift+P | Cmd+Shift+P |
| Find a file | Ctrl+P | Cmd+P |
| Search the project | Ctrl+Shift+F | Cmd+Shift+F |
| Find text in the open file | Ctrl+F | Cmd+F |
Use Terminal > New Terminal to open a terminal. Use Preferences: Open Keyboard Shortcuts to find or change other shortcuts. Keyboard shortcut guide.
Fix common problems
| Problem | What to do |
|---|---|
| A package is installed, but Python cannot import it | Run python -c "import sys; print(sys.executable)". Compare the path with Python: Select Interpreter. Install the package in that environment. |
| The notebook cannot find a package | Select the correct notebook kernel. The kernel and terminal may use different environments. |
| A saved change does not appear | Check that you opened the correct project folder. Save the file. Run the correct file again. |
Git shows many files from .venv | Add .venv/ to .gitignore. Do not commit environment files. If files were already committed, ask for help before removing them from Git. |
| The remote connection fails | Check your network or required university VPN, server address, and account. Test ssh in a terminal and read the error. |
Use File > Preferences > Settings on Windows/Linux, or Code > Settings > Settings on macOS, for editor settings. Use the Workspace tab for project-only changes. Keep shared settings small. Settings guide.
