Follow these steps to create a clean, isolated Python workspace and use VS Code to develop and run your scripts.
1. Create a Project Directory
- Open File Explorer and create a new folder, e.g.
C:\Users\You\projects\myapp
. - Right-click inside the folder and choose Open in Terminal (or open Command Prompt and
cd
to it).
2. Create a Virtual Environment
A virtual environment is a self-contained Python runtime (with its own pip
, libraries, etc.), keeping your project’s dependencies isolated.
# In your project directory:
python -m venv .venv
-
Creates a folder
.venv\
with its own Python interpreter and site-packages. -
Keeps global Python installation clean.
3. Activate the Virtual Environment
# Command Prompt (cmd.exe)
.venv\Scripts\activate
-
Your prompt will change to show
(.venv)
-
Now,
pip install
will install packages into.venv
, not system-wide.
4. Install Packages
pip install requests flask
-
Installing inside the venv ensures your project has exactly the right versions.
-
You can freeze dependencies with
pip freeze > requirements.txt
.
5. Create and Run a Python Script
-
Open any text editor.
-
Create a file named
app.py
with your code, e.g.:print("Hello, world!")
-
Save the file in your project folder.
-
In the terminal (with
.venv
active):python app.py
6. Why Use an IDE Like VS Code?
-
Automatic indentation and formatting
-
Syntax highlighting, IntelliSense, linting
-
Integrated terminal and debugger
7. Open Your Project in VS Code
-
Launch VS Code.
-
File → Open Folder… and select your project directory.
-
Go to the Extensions pane (Ctrl+Shift+X), search for Python, and install the official extension.
-
Press Ctrl+Shift+P, type Python: Select Interpreter, and choose the one in
.venv\Scripts\python.exe
.
8. Run Your Script in VS Code
-
Open
app.py
. -
Click the ▶️ Run button at the top right, or press F5.
-
View output in the integrated terminal.