5. Installing and Configuring VS Code
1. Introduction
Visual Studio Code (VS Code) is a lightweight but powerful code editor from Microsoft.
It is widely used for Python development because of its excellent extensions, debugging tools, and integrated terminal.
2. Downloading VS Code
- Open your web browser.
- Go to the official download page: https://code.visualstudio.com/
- Choose your operating system (Windows, macOS, or Linux).
- Download the installer (
.exe,.dmg, or.deb/.rpm).
3. Installing on Windows
- Run the downloaded
.exeinstaller. - Accept the license agreement.
- Choose installation location (default is fine).
- On the "Select Additional Tasks" screen, check:
- ✅ Add to PATH
- ✅ Register as default editor for supported file types
- ✅ Add "Open with Code" to context menu
- Click Install.
4. Installing on macOS
- Open the downloaded
.dmgfile. - Drag Visual Studio Code.app into the Applications folder.
- Open VS Code from Launchpad or Spotlight.
- (Optional) Add
codecommand to PATH:- Open VS Code.
- Press
Cmd + Shift + P, type Shell Command: Install 'code' command in PATH, and press Enter.
5. Installing on Linux
For Ubuntu/Debian:
sudo apt update
sudo apt install ./code_*_amd64.deb
For Fedora/RHEL:
sudo dnf install ./code-*.rpm
For Arch (via AUR):
yay -S visual-studio-code-bin
6. Installing the Python Extension
- Open VS Code.
- Go to the Extensions view (
Ctrl + Shift + XorCmd + Shift + Xon macOS). - Search for Python.
- Install the official Microsoft Python extension.
7. Configuring Python in VS Code
- Open any
.pyfile or create a new one. - If prompted, select your Python interpreter.
- You can also manually set it:
- Open the Command Palette (
Ctrl + Shift + P). - Type Python: Select Interpreter.
- Choose the version you installed earlier.
- Open the Command Palette (
8. Running Your First Program
- Create a new file
hello.py. - Type:
print("Hello from VS Code!")
- Save the file.
- Right-click inside the editor and select Run Python File in Terminal.
- You should see the output in the integrated terminal:
Hello from VS Code!
9. Customizing VS Code
- Themes: Install new themes from Extensions marketplace.
- Fonts: Go to Settings → Font Family.
- Keybindings: Customize shortcuts via Keyboard Shortcuts (
Ctrl + K Ctrl + S). - Extensions: Explore other useful extensions (Pylance, Jupyter, GitLens).
10. Troubleshooting
- Python not detected: Check that Python is installed and added to PATH.
- Multiple Python versions: Ensure the correct interpreter is selected via Python: Select Interpreter.
- Code command not found (macOS/Linux): Reinstall the
codeshell command from Command Palette.
11. Next Steps
✅ You now have VS Code installed and configured with Python.
In the next chapter, we will set up PyCharm, another popular IDE for Python.