VS Code Python IDE Setup - Complete Configuration Guide
Visual Studio Code is the most popular Python IDE due to its speed, extensibility, and excellent Python language support through Microsoft's official extension.
This guide covers complete setup including virtual environments, debugging, linting, formatting, testing, and professional workspace configuration.
Follow these steps to transform VS Code into a production-ready Python development environment.
Prerequisites
- Python 3.10+ installed from python.org
- VS Code installed from code.visualstudio.com
- Git installed for version control
- Terminal/Command Prompt access
BASH
# Check Python
python --version
pip --version
# Check VS Code
code --version
# Check Git
git --version
Essential Extensions
JSON
[
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.debugpy",
"ms-python.black-formatter",
"ms-python.isort",
"njpwerner.autodocstring",
"ms-vscode.vscode-json",
"GitHub.copilot",
"ms-vscode.test-adapter-converter"
]
- Python (ms-python.python) - Core functionality
- Pylance - Fast language server and IntelliSense
- Black Formatter - Auto-formatting
- isort - Import sorting
- autoDocstring - Docstring generation
Project Structure
BASH
mkdir my-python-project
cd my-python-project
# Create directories
mkdir src tests docs
# Create virtual environment
python -m venv .venv
# Windows activation
.venv\Scripts\activate
# macOS/Linux activation
source .venv/bin/activate
# Install dev tools
pip install pytest black pylint mypy ruff
pip install -r requirements.txt
pip freeze > requirements.txt
- `.venv/` - Virtual environment
- `src/` - Source code
- `tests/` - Unit tests
- `docs/` - Documentation
.vscode/settings.json Configuration
JSON
{
"python.defaultInterpreterPath": "./.venv/bin/python",
"python.terminal.activateEnvironment": true,
"python.linting.enabled": true,
"python.linting.ruffEnabled": true,
"python.formatting.provider": "black",
"python.formatting.blackArgs": ["--line-length=88"],
"python.sortImports.path": "isort",
"python.sortImports.args": ["--profile=black"],
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll.ruff": "explicit"
},
"files.exclude": {
"**/__pycache__": true,
"**/.pytest_cache": true
},
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["tests"]
}
Debugging (.vscode/launch.json)
JSON
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}",
"envFile": ".env"
},
{
"name": "Python: pytest",
"type": "python",
"request": "launch",
"module": "pytest",
"args": ["tests/", "-v", "--tb=short"],
"console": "integratedTerminal"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/src/manage.py",
"args": ["runserver"]
}
]
}
Custom Tasks (.vscode/tasks.json)
JSON
{
"version": "2.0.0",
"tasks": [
{
"label": "Install Dependencies",
"type": "shell",
"command": "pip",
"args": ["install", "-r", "requirements.txt"],
"group": "build",
"presentation": {"echo": true, "reveal": "silent"}
},
{
"label": "Lint & Format",
"type": "shell",
"command": "ruff",
"args": ["check", ".", "--fix"],
"group": "build"
},
{
"label": "Run Tests",
"type": "shell",
"command": "pytest",
"args": ["tests/", "-v"],
"group": "test"
}
]
}
.gitignore for Python Projects
GITIGNORE
# Byte-compiled / optimized files
__pycache__/
*.py[cod]
*$py.class
# Virtual environments
.venv/
venv/
ENV/
env/
# Testing
.pytest_cache/
.coverage
htmlcov/
.tox/
# IDE
.vscode/settings.json
.idea/
*.swp
*.swo
# OS
.DS_Store
Thumbs.db
# Logs
*.log
# Environment variables
.env
Essential Keyboard Shortcuts
- Ctrl+Shift+P - Command Palette
- Ctrl+` - Integrated Terminal
- F5 - Start Debugging
- Ctrl+F5 - Run Without Debugging
- F9 - Toggle Breakpoint
- Shift+Alt+F - Format Document
- Ctrl+Shift+P → Python: Select Interpreter
Pro Tips & Best Practices
- Always use virtual environments (.venv)
- Select interpreter after opening workspace (Ctrl+Shift+P)
- Use Python profile template for new projects
- Enable format on save for consistent code style
- Configure pytest for test discovery
- Use Ruff for fast linting (replaces pylint + flake8)
- Set up GitHub Copilot for AI code completion
Conclusion
VS Code with proper Python configuration rivals full-featured IDEs like PyCharm while remaining lightweight and fast.
This setup provides IntelliSense, debugging, testing, linting, formatting, and Git integration out of the box.
Create your first .py file and press F5 to start coding with a professional Python development environment!
Codecrown