If you’re getting started with Python, one of the first and most important steps is to set up a proper development environment. This guide will walk you through two ways to do it: using the command line and using Visual Studio Code (VS Code). Whether you’re a beginner or looking for best practices, this post covers both.
🔧 Command Line Method
✅ Step 1: Install Python
- Windows:
- Download the installer from python.org
- Run the installer and check the box that says “Add Python to PATH” before clicking “Install Now”.
- Linux (Debian/Ubuntu):
sudo apt update
sudo apt install python3 python3-pip python3-venv
✅ Step 2: Create a Project Directory
mkdir my-python-project
cd my-python-project
✅ Step 3: Create a Virtual Environment
python -m venv .venv
Note: Use python
instead of python3
on Windows.
✅ Step 4: Activate the Environment
- Windows:
.venv\Scripts\activate
- Linux:
source .venv/bin/activate
Once activated, you’ll see your environment name (e.g., .venv
) as a prefix in your terminal prompt, like this:
(.venv) user@machine:~/my-python-project$
This prefix indicates that you’re currently working inside the virtual environment.
✅ Step 5: Upgrade pip and Install Packages
python -m pip install --upgrade pip
pip install requests flask
✅ Step 6: Save Requirements
pip freeze > requirements.txt
✅ Step 7: Deactivate (When Done)
deactivate
👨💻 VS Code Method
✅ Step 1: Install VS Code
Download from code.visualstudio.com
✅ Step 2: Install Python Extension
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search “Python” and install the one from Microsoft
✅ Step 3: Open Project Folder
- File > Open Folder… > select your project folder (e.g.,
my-python-project
)
✅ Step 4: Create a Virtual Environment
Open a new terminal inside VS Code:
- Menu: Terminal > New Terminal
- Then run:
python -m venv .venv
✅ Step 5: Select the Python Interpreter
- Press
Ctrl+Shift+P
to open the Command Palette - Type and select:
Python: Select Interpreter
- From the list, choose the interpreter path like:
- Windows:
.venv\Scripts\python.exe
- Linux:
.venv/bin/python
- Windows:
Once selected, the bottom-left status bar will show your environment name (e.g., .venv
).
✅ Step 6: Activate Environment in Terminal
If the environment isn’t automatically activated in the terminal:
- Open
settings.json
(Ctrl+Shift+P → Preferences: Open Settings (JSON)) - Add:
"python.terminal.activateEnvironment": true
✅ Step 7: Run Your Python Code
- Create a new file
app.py
- Add sample code:
print("Hello, Python World!")
- Right-click on the file editor and select “Run Python File in Terminal”
- You should see
(.venv)
as a prefix in the terminal, confirming activation.
📆 Final Thoughts
Setting up your Python environment correctly makes development easier, cleaner, and more scalable. Use a virtual environment for every project to avoid dependency conflicts, and let VS Code’s features enhance your productivity.
Happy coding! 🚀