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 ๐พ.