04 — Visual Studio Code
VS Code for this course
Visual Studio Code (VS Code) is the officially supported IDE for this course.
Download it from:
https://code.visualstudio.com/
This guide assumes that you have already created the course Conda environment named cv.
1. Install VS Code
Install VS Code on your main operating system.
Windows + WSL
Install VS Code on Windows. Do not install a separate Linux copy of the VS Code desktop application inside WSL.
The VS Code WSL extension will allow the Windows application to work directly with files and tools inside Ubuntu.
Official WSL documentation:
2. Install the recommended extensions
Open the Extensions view using the left sidebar or:
Ctrl+Shift+X
Install these Microsoft extensions:
- Python
- Pylance
- Jupyter
Windows users using WSL should also install:
- WSL
When VS Code suggests installing Python-related extensions the first time you open a .py file, accept the recommendation.
3. Create a course projects folder
Keeping course projects together makes environments and file paths easier to manage.
Windows + WSL
Inside Ubuntu:
mkdir -p ~/cv_projects
cd ~/cv_projectsThen open the folder in VS Code:
code .VS Code should open a new window connected to WSL.
Look at the bottom-left corner of VS Code. It should indicate that the window is connected to WSL, for example:
WSL: Ubuntu
macOS/Linux
Create a projects folder:
mkdir -p ~/cv_projects
cd ~/cv_projects
code .You can also use File → Open Folder from VS Code.
4. Confirm the integrated terminal
Open a VS Code terminal:
Terminal → New Terminal
or:
Ctrl+`
On Windows with WSL, this terminal should be running inside Ubuntu.
Check:
pwdThen activate the course environment:
conda activate cv5. Select the cv Python interpreter
Open a Python file, then open the Command Palette:
Ctrl+Shift+P
Search for:
Python: Select Interpreter
Choose the interpreter associated with the Conda environment:
cv
The exact Python version shown next to the environment may change as the course environment is updated. The important part is that the selected environment is cv.
Do not select an interpreter simply because its Python version looks correct. Make sure it belongs to the cv Conda environment.
6. If VS Code cannot find the environment
Activate the environment in a terminal:
conda activate cvOn macOS/Linux/WSL, run:
which pythonCopy the returned path.
Then in VS Code:
- Open Python: Select Interpreter.
- Choose Enter interpreter path if necessary.
- Select or paste the Python path from the
cvenvironment.
You can verify the selected interpreter in the integrated terminal:
python --versionand:
python -c "import sys; print(sys.executable)"7. Test the environment
Create a file named:
test_environment.py
Add:
import numpy as np
import cv2
print("NumPy:", np.__version__)
print("OpenCV:", cv2.__version__)Run the file using the Run Python File button or from the terminal:
python test_environment.pyIf the imports work, VS Code is using an environment with the required packages.
8. Working with notebooks
Open a .ipynb file in VS Code.
At the top-right of the notebook, choose Select Kernel and select the Python environment associated with:
cv
Run a cell such as:
import sys
print(sys.executable)The printed path should point into the cv environment.
9. Debugging Python
The VS Code debugger lets you pause code, inspect variables, and step through execution. This is often much more useful than adding many print() statements.
Set a breakpoint
Click in the margin to the left of a line number. A red dot indicates a breakpoint.
Start debugging
Press:
F5
If VS Code asks for a debug configuration, choose:
Python File
Debugger controls
The debugger lets you:
- Continue — run until the next breakpoint;
- Step Over — execute the current line without entering called functions;
- Step Into — enter a called function;
- Step Out — finish the current function and return to its caller;
- Restart — restart the debugging session;
- Stop — end the session.
The Variables panel shows local and global variables while execution is paused.
The Debug Console can evaluate Python expressions using the current program state.
10. A useful debugging example
Create:
import numpy as np
image = np.zeros((100, 200, 3), dtype=np.uint8)
image[:, :100, 0] = 255
mean_value = image.mean()
print(mean_value)Set a breakpoint on:
mean_value = image.mean()Start debugging with F5.
While paused, inspect:
image.shapeand:
image.dtypein the Debug Console.
This is especially useful when working with images because shape and data type errors are common.
11. Recommended VS Code workflow
For a typical course programming session:
- Open your project folder in VS Code.
- Verify that Windows users are connected to WSL.
- Open the integrated terminal.
- Run
conda activate cv. - Verify that the selected Python interpreter is
cv. - Pull recent Git changes if applicable.
- Write and test code.
- Use the debugger when behavior is unclear.
- Commit and push your work.
12. Common problems
Notebook imports fail but Python scripts work
The notebook kernel may be different from the selected Python interpreter.
Use Select Kernel in the notebook and choose cv.
Windows user sees Windows paths instead of Linux paths
Make sure the VS Code window is connected to WSL. The bottom-left status area should indicate a WSL connection.
A reliable way to open the correct environment is:
cd ~/cv_projects
code .from an Ubuntu/WSL terminal.
The debugger runs the wrong Python version
Check:
import sys
print(sys.executable)Then reselect the cv interpreter.