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
pipRunning 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 --versionExample output:
Python 3.12.2Check pip (Pythonβs package manager):
pip --versionExample output:
pip 23.2 from C:\Users\<username>\AppData\Local\Programs\Python\Python312\Lib\site-packages\pipIf 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_appStep 2 β Create a virtual environment
python -m venv .venvThis creates an isolated Python environment inside:
.venv/Step 3 β Activate the virtual environment
Windows:
.venv\Scripts\activateYou should now see:
(.venv)in the terminal.
Verify activation:
echo %VIRTUAL_ENV%Step 4 β Install dependencies
Example:
pip install flask requestsImportant:
When pip install runs inside an activated virtual environment, packages are installed locally inside .venv, not globally.
Step 5 β Freeze dependencies
pip freeze > requirements.txtExample:
flask==3.0.1
requests==2.31.0This 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-url2. Create virtual environment
python -m venv .venv3. Activate environment
.venv\Scripts\activate4. Install dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txtExample:
(.venv) C:\Users\ankushzn\Desktop\app_backend>pip install -r requirements-dev.txt5. Run the application
Example:
streamlit run helloworld.pyVirtual Environments
A virtual environment isolates dependencies for a project.
This prevents conflicts between different projects.
Example:
Project A might require:
Django 3Project B might require:
Django 5Virtual 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 osAfter:
import os
import sys
import requestsFlake8
Linting tool that detects:
unused imports
style issues
potential mistakes
Python vs Pip
Tool | Purpose |
|---|---|
Python | Interpreter that runs |
pip | Package manager used to install libraries |
Example:
Run Python file:
python app.pyInstall dependency:
pip install requestsWhy Sometimes You See python3 or pip3
On systems with both Python 2 and Python 3 installed, commands may differ.
Command | Meaning |
|---|---|
| Default Python interpreter |
| Explicitly Python 3 |
| Package manager for default Python |
| 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.exeEach 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 InterpreterChecking Which Python Is Being Used
You can verify the active interpreter using:
where pythonExample output:
C:\Users\<username>\project\.venv\Scripts\python.exe
C:\Users\<username>\AppData\Local\Programs\Python\Python312\python.exeThe first entry is the one currently used.
Similarly:
where pipWhy Many Engineers Prefer python -m pip
Instead of:
pip install requestsmany engineers prefer:
python -m pip install requestsThis guarantees the package installs into the same Python environment as the interpreter you invoked.
For example:
python β Python 3.12
pip β Python 3.10Using python -m pip avoids such mismatches.
Where Python Gets Installed
Typical Windows installation location:
C:\Users\<username>\AppData\Local\Programs\Python\Python312\Important directories:
Directory | Purpose |
|---|---|
| Python interpreter |
| CLI tools like pip |
| Installed packages |
Where pip Installs Packages
Global installation
C:\Users\<username>\AppData\Local\Programs\Python\Python312\Lib\site-packagesVirtual environment installation
project\.venv\Lib\site-packagesHow Virtual Environments Work
Running:
python -m venv .venvcreates:
.venv
βββ Include
βββ Lib
β βββ site-packages
βββ Scripts
β βββ python.exe
β βββ pip.exe
β βββ activate
βββ pyvenv.cfgWhen the environment is activated:
.venv\Scripts\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:appSummary
A solid Python setup usually includes:
Installing Python from the official website
Verifying installation with
python --versionUsing virtual environments (
venv)Managing dependencies with
requirements.txtInstalling helpful VS Code extensions
Using
python -m pipto avoid environment issues
Following these practices keeps Python projects clean, reproducible, and easy to maintain.
