*Set Up Python Virtual Environment in Visual Studio Code (VS Code) on Windows 11 | VSCode Activate venv*
*Description:*
Want to set up a **Python Virtual Environment (venv) in Visual Studio Code (VS Code) on Windows 11**? 🐍💻 This step-by-step tutorial will guide you through creating, activating, and managing virtual environments in **VS Code**, ensuring smooth development and package isolation.
By the end of this video, you will know how to **set up a virtual environment**, **activate venv**, **install packages**, and **run your Python scripts efficiently in VS Code**. 🚀
---
*🔹 What You’ll Learn in This Video:*
✅ How to *install Python and check the version*
✅ How to *create a Python virtual environment (venv)*
✅ How to *activate and deactivate venv in VS Code*
✅ How to *install Python packages inside the virtual environment*
✅ How to *configure VS Code to automatically use venv*
---
*1️⃣ Prerequisites for Creating a Virtual Environment in VS Code*
Before you begin, make sure you have the following installed on your system:
✔ *Windows 11 (64-bit)*
✔ *Python (3.6 or later)* - [Download Python](https://www.python.org/downloads/)
✔ *Visual Studio Code* - [Download VS Code](https://code.visualstudio.com/)
✔ *Python Extension for VS Code* (Installed from the VS Code Marketplace)
---
*2️⃣ Install Python and Check the Version*
1️⃣ *Check if Python is already installed:*
Open *Command Prompt (cmd)* or *PowerShell* and run:
```bash
python --version
```
or
```bash
python3 --version
```
If Python is installed, you’ll see an output like:
```
Python 3.x.x
```
2️⃣ *If Python is not installed:*
Download and install *Python* from [https://www.python.org/downloads/](https://www.python.org/downloads/).
*Check the box* for *"Add Python to PATH"* during installation!
---
*3️⃣ Create a Python Virtual Environment (venv) in VS Code*
✅ *Step 1: Open VS Code and Create a New Project Folder*
1. Open **Visual Studio Code**.
2. Click on *File → Open Folder* and choose or create a new project folder.
✅ *Step 2: Open the Integrated Terminal*
1. Go to *Terminal → New Terminal* (or press **Ctrl + `**).
2. Ensure you are in the correct project directory.
✅ *Step 3: Create a Virtual Environment*
Run the following command in the terminal:
```bash
python -m venv venv
```
This will create a new *venv* folder inside your project directory.
---
*4️⃣ Activate the Virtual Environment in VS Code*
✅ *For Windows (Command Prompt or PowerShell):*
*Command Prompt (cmd):*
```bash
venv\Scripts\activate
```
*PowerShell:*
```powershell
venv\Scripts\Activate.ps1
```
⚠ If you get a security error, run:
```powershell
Set-ExecutionPolicy Unrestricted -Scope Process
```
✅ *For macOS/Linux:*
```bash
source venv/bin/activate
```
Once activated, your terminal prompt will change to:
```
(venv) C:\Users\YourName\Project
```
This confirms the **virtual environment is active**! 🎉
---
*5️⃣ Install Python Packages Inside the Virtual Environment*
Once the virtual environment is activated, you can install packages using `pip`:
```bash
pip install package_name
```
For example, to install **Flask and NumPy**:
```bash
pip install flask numpy
```
To check installed packages, run:
```bash
pip list
```
---
*6️⃣ Deactivate the Virtual Environment*
To exit the virtual environment, simply run:
```bash
deactivate
```
Your terminal will return to normal, indicating that the virtual environment is no longer active.
---
*7️⃣ Configure VS Code to Automatically Use venv*
1️⃣ *Select the Python Interpreter in VS Code*
Open *Command Palette* (`Ctrl + Shift + P`)
Search for *"Python: Select Interpreter"*
Select the *venv interpreter* (`.venv\Scripts\python.exe`)
2️⃣ *Set venv as Default in VS Code*
To make VS Code automatically detect your virtual environment, add the following setting in `settings.json`:
```json
{
"python.defaultInterpreterPath": "C:\\Users\\YourName\\Project\\venv\\Scripts\\python.exe"
}
```
---
*8️⃣ Running Python Scripts in VS Code with venv*
1. Open a *Python file* (`.py`) in your project folder.
2. Ensure the *venv* interpreter is selected.
3. Run the script using:
*F5 (Run and Debug)*
*Right-click → Run Python File in Terminal*
Manually run in the terminal:
```bash
python script.py
```
*📌 Useful Links:*
🔗 Python Official Website: [https://www.python.org/](https://www.python.org/)
🔗 VS Code Download: [https://code.visualstudio.com/](https://code.visualstudio.com/)
🔗 Virtual Environments in Python: [https://docs.python.org/3/library/ven...]
📌 *Hashtags:*
#Python #VSCode #VirtualEnvironment #PythonDevelopment #Venv #PythonTutorial #VisualStudioCode #Windows11 #PythonProgramming
En esta página del sitio puede ver el video en línea How To Set Up Python Virtual Environment (venv) In Visual Studio Code (VS Code) On Windows 11 de Duración hora minuto segunda en buena calidad , que subió el usuario ProgrammingKnowledge 31 marzo 2025, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 51,573 veces y le gustó 303 a los espectadores. Disfruta viendo!