Setting up Python on your local machine is simple, but a few best practices can make development much smoother and easier to maintain.
This guide walks through:
- Installing Python
- Setting up virtual environments
- Configuring VS Code for development
- Managing dependencies with
pip - Running and deploying Python applications
If you're coming from ecosystems like .NET or Node.js, this guide will also clarify how Python handles environments and dependency management.
Installing Python
Download Python from the official website:
π https://www.python.org/downloads/
Steps:
- Download the latest Python 3.x installer for Windows.
- Run the installer.
- Important: Check the option Add Python to PATH.
- Click Install Now.
Adding Python to PATH allows you to run python commands directly from the terminal.
Verifying Installation
Open Command Prompt or PowerShell and run:
python --version
Example output:
Python 3.12.2
Check pip (Pythonβs package manager):
pip --version
Example output:
pip 23.2 from C:\Users\<username>\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip
If both commands work, Python has been installed successfully.
Your First Python Project
Python development usually starts in one of two ways:
- Creating a new project
- Working with an existing repository
Let's start with a new project.
Creating a New Python App
Step 1 β Create a project folder
Example:
my_python_app
Step 2 β Create a virtual environment
python -m venv .venv
This creates an isolated Python environment inside:
.venv/
Step 3 β Activate the virtual environment
Windows:
.venv\Scripts\activate
You should now see:
(.venv)
in the terminal.
Verify activation:
echo %VIRTUAL_ENV%
Step 4 β Install dependencies
Example:
pip install flask requests
Important:
When pip install runs inside an activated virtual environment, packages are installed locally inside .venv, not globally.
Step 5 β Freeze dependencies
pip freeze > requirements.txt
Example:
flask==3.0.1
requests==2.31.0
This file ensures other developers or servers can install the exact same dependency versions.
Working With an Existing Python Project
Most real-world work starts by cloning a repository.
1. Clone the repository
git clone repo-url
2. Create virtual environment
python -m venv .venv
3. Activate environment
.venv\Scripts\activate
4. Install dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt
Example:
(.venv) C:\Users\ankushzn\Desktop\app_backend>pip install -r requirements-dev.txt
5. Run the application
Example:
streamlit run helloworld.py
Virtual Environments
A virtual environment isolates dependencies for a project.
This prevents conflicts between different projects.
Example:
Project A might require:
Django 3
Project B might require:
Django 5
Virtual environments allow both versions to coexist safely.
Important VS Code Extensions
Install Visual Studio Code along with the following extensions.
Python (Microsoft)
Provides core Python support:
- Interpreter selection
- Debugging
- IntelliSense
Pylance
High-performance language server providing:
- Autocomplete
- Type checking
- Import suggestions
- Code navigation
Black
Opinionated code formatter.
Benefits:
- Consistent formatting
- Eliminates style debates
- Automatically formats code on save
isort
Automatically sorts imports.
Before:
import sys
import requests
import os
After:
import os
import sys
import requests
Flake8
Linting tool that detects:
- unused imports
- style issues
- potential mistakes
Python vs Pip
| Tool | Purpose |
|---|---|
| Python | Interpreter that runs .py files |
| pip | Package manager used to install libraries |
Example:
Run Python file:
python app.py
Install dependency:
pip install requests
Why Sometimes You See python3 or pip3
On systems with both Python 2 and Python 3 installed, commands may differ.
| Command | Meaning |
|---|---|
python |
Default Python interpreter |
python3 |
Explicitly Python 3 |
pip |
Package manager for default Python |
pip3 |
Package manager for Python 3 |
Most modern Windows systems map python directly to Python 3.
Python Interpreters
A Python interpreter is simply the python.exe executable that runs Python programs.
You can have multiple interpreters installed:
C:\Python310\python.exe
C:\Python312\python.exe
project.venv\Scripts\python.exe
Each interpreter has its own package environment.
Changing the interpreter simply means telling your IDE or terminal:
Use a different
python.exeto run this project.
In VS Code:
Ctrl + Shift + P β Python: Select Interpreter
Checking Which Python Is Being Used
You can verify the active interpreter using:
where python
Example output:
C:\Users\<username>\project.venv\Scripts\python.exe
C:\Users\<username>\AppData\Local\Programs\Python\Python312\python.exe
The first entry is the one currently used.
Similarly:
where pip
Why Many Engineers Prefer python -m pip
Instead of:
pip install requests
many engineers prefer:
python -m pip install requests
This guarantees the package installs into the same Python environment as the interpreter you invoked.
For example:
python β Python 3.12
pip β Python 3.10
Using python -m pip avoids such mismatches.
Where Python Gets Installed
Typical Windows installation location:
C:\Users\<username>\AppData\Local\Programs\Python\Python312</code>
Important directories:
| Directory | Purpose |
|---|---|
python.exe |
Python interpreter |
Scripts/ |
CLI tools like pip |
Lib/site-packages |
Installed packages |
Where pip Installs Packages
Global installation
C:\Users\<username>\AppData\Local\Programs\Python\Python312\Lib\site-packages
Virtual environment installation
project.venv\Lib\site-packages
How Virtual Environments Work
Running:
python -m venv .venv
creates:
.venv
βββ Include
βββ Lib
β βββ site-packages
βββ Scripts
β βββ python.exe
β βββ pip.exe
β βββ activate
βββ pyvenv.cfg
When the environment is activated:
.venv\Scripts</code>
is added to the beginning of the system PATH, so python and pip resolve to the local environment versions.
Packaging for Deployment
Unlike .NET or Node.js, Python applications are usually deployed by recreating environments.
Typical deployment steps:
Maintain dependency file
requirements.txtCreate environment on server
python -m venv .venvInstall dependencies
pip install -r requirements.txtRun application
python app.pyor
gunicorn app:app
Summary
A solid Python setup usually includes:
- Installing Python from the official website
- Verifying installation with
python --version - Using virtual environments (venv)
- Managing dependencies with requirements.txt
- Installing helpful VS Code extensions
- Using
python -m pipto avoid environment issues
Following these practices keeps Python projects clean, reproducible, and easy to maintain.
