Vs code
What is VS Code? π»
Visual Studio Code (VS Code) is a free, lightweight, and powerful code editor developed by Microsoft. It supports multiple programming languages (Python, JavaScript, Java, etc.) with:
- β IntelliSense (smart code completion) π‘
- β Built-in Git control π³
- β Debugging tools π
- β Extensions for customization π§©
- β Integrated terminal π₯οΈ
VS Code is cross-platform (Windows, macOS, Linux) and widely used for web development, data science, and general programming. ππβοΈ
How to Install VS Code (Step-by-Step) β¬οΈ
Step 1: Download VS Code π
- Visit the official website: https://code.visualstudio.com
- Download the installer for your OS:
- Windows:
.exeπͺ - macOS:
.dmgπ - Linux:
.deb(Debian/Ubuntu) or.rpm(Fedora) π§
- Windows:
Step 2: Install VS Code π
- For Windows: πͺ
- Run the downloaded
.exefile. βΆοΈ - Follow the setup wizard. β‘οΈ
- Check “Add to PATH” (to launch from Command Prompt). β
- Click “Install” β Launch VS Code. π
- Run the downloaded
- For macOS: π
- Open the
.dmgfile. π - Drag VS Code to the Applications folder. β‘οΈ
- Open Applications β Launch VS Code. π
- Open the
- For Linux (Debian/Ubuntu): π§
- Option 1 (Recommended): Install via terminal: Bash
sudo apt update && sudo apt install codeβ¬οΈ - Option 2: Manual install (for
.deb): Bashsudo dpkg -i ~/Downloads/code_*.deb sudo apt install -f # Fix dependenciesπ¦
- Option 1 (Recommended): Install via terminal: Bash
Step 3: First-Time Setup π οΈ
- Open VS Code β Go to the Extensions tab (
Ctrl+Shift+X/Cmd+Shift+X). π§© - Install these essential extensions:
- Python (by Microsoft) π
- Pylance (for Python IntelliSense) π‘
- Jupyter (for notebooks) π
- Prettier (code formatting) β¨
- Configure Python Interpreter:
- Press
Ctrl+Shift+Pβ Type “Python: Select Interpreter” β Choose your Python (python3orvirtualenv). π
- Press
VS Code Features Youβll Love β€οΈ
- πΉ Live Share: Collaborate in real-time with others. π€
- πΉ Integrated Terminal: Run commands without leaving the editor. π₯οΈ
- πΉ Git Integration: Commit, push, and pull directly from VS Code. π³
- πΉ Custom Themes: Personalize your editor (Dark/Light themes). π¨
Troubleshooting β οΈ
- β VS Code not launching?
- Windows: Reinstall and check “Add to PATH”. πͺ
- Linux: Run
code --verbosein terminal for errors. π§
- β Python extension not working?
- Ensure Python is installed (
python3 --version). π - Reload VS Code after installing extensions. π
- Ensure Python is installed (
VS Code vs. PyCharm π
| Feature | VS Code | PyCharm |
|---|---|---|
| Type | Lightweight code editor | Full-featured Python IDE |
| Speed | Faster startup | Slower (more features) |
| Extensions | Customizable via marketplace | Built-in Python tools |
| Best For | Multi-language developers | Python-only projects |
Export to Sheets
Next Steps βΆοΈ
- Try these shortcuts:
Ctrl+P(Quick file navigation) π- `Ctrl+“ (Toggle terminal) π₯οΈ
- Open a Python file β Press
F5to debug. π
VS Code is perfect for beginners and pros alike! Install it today and boost your workflow. π
How to Run Python Code in VS Code π»
Hereβs a step-by-step guide to running Python scripts in Visual Studio Code (VS Code) on Windows, macOS, or Linux:
1. Install Prerequisites β Before running Python code, ensure you have:
- β Python Installed (Download from python.org) π
- β VS Code Installed (Download from code.visualstudio.com) π¦
- β Python Extension for VS Code (Install from Extensions Marketplace) π§©
2. Open VS Code & Set Up Python βοΈ
- Step 1: Install the Python Extension π§©
- Open VS Code.
- Click the Extensions icon (or press
Ctrl+Shift+X/Cmd+Shift+X). - Search for
"Python"(by Microsoft) β Click Install.
- Step 2: Select Python Interpreter π
- Open a Python file (
.py) or create a new one (File β New File). - Press
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(macOS). - Type
"Python: Select Interpreter"β Choose your Python version. - πΉ If Python isnβt detected, ensure itβs added to
PATH(checkpython --versionin terminal β‘οΈ).
- Open a Python file (
3. Run Python Code βΆοΈ
- Method 1: Run Using the Play Button (Easiest) βΆοΈ
- Open a Python file (e.g.,
hello.py). - Write a simple script:
print("Hello, VS Code!") - Click the βΆοΈ Run Python button in the top-right corner.
- Output appears in the Terminal (bottom panel) βοΈ.
- Open a Python file (e.g.,
- Method 2: Run in Terminal π»
- Open the Terminal (
Ctrl+`` /Ctrl+Shift+“). - Navigate to your scriptβs folder:
cd path/to/your_script_folderπ - Run the script:
python hello.py# Windows/macOS/Linux π(or python3 hello.py on Linux/macOS).π§π
- Open the Terminal (
- Method 3: Debug Mode (Advanced) π
- Set a breakpoint (click left gutter next to line numbers π΄).
- Press
F5β Select Python Debugger. - Debugger runs β Inspect variables in the Debug Console π.
4. Run Jupyter Notebooks (For Data Science) π
- Install the Jupyter Extension (from Extensions Marketplace) π§©.
- Create a new
.ipynbfile (File β New File β Jupyter Notebook). - Write Python code in cells β Press
Shift+Enterto run π.
5. Troubleshooting Common Issues π οΈ
| Issue | Solution |
|---|---|
| Python not found | Reinstall Python & check "Add to PATH" π |
| No Python extension | Install the Python extension in VS Code π§© |
| Syntax errors | Check red underlines & hover for details π |
| Terminal not working | Restart VS Code or check default shell (Ctrl+Shift+P β “Terminal: Select Default Shell”) βοΈ |
Export to Sheets
VS Code Python Shortcuts (Boost Productivity!) π
| Shortcut (Windows/Linux) | Shortcut (macOS) | Action |
|---|---|---|
Ctrl+F5 | Cmd+F5 | Run without debugging |
F5 | F5 | Start debugging |
Ctrl+Shift+D | Cmd+Shift+D | Open Debug panel |
Ctrl+Shift+E | Cmd+Shift+E | Toggle Explorer |
Export to Sheets
Final Tips π‘
- Use
# %%to create code cells (like Jupyter) in.pyfiles π. - Format code with
Shift+Alt+F(Windows/Linux) orShift+Option+F(macOS) β¨. - Enable Auto Save (File β Auto Save) to avoid losing changes πΎ.