Python Environment Setup
Before you start writing Python code, you need to install Python and set up a proper development environment. This guide covers installation on all major operating systems and introduces essential tools.
Installing Python
Windows
- Visit the official Python website: python.org/downloads
- Download the latest Python 3.x installer
- Important: Check the box "Add Python to PATH" during installation
- Click "Install Now"
Verify the installation by opening Command Prompt:
python --version
# Python 3.12.x
pip --version
# pip 24.x.xmacOS
macOS may come with Python 2 pre-installed, but you need Python 3:
# Install using Homebrew (recommended)
brew install python
# Verify installation
python3 --version
# Python 3.12.xLinux (Ubuntu/Debian)
Most Linux distributions come with Python 3 pre-installed:
# Update package list
sudo apt update
# Install Python 3 and pip
sudo apt install python3 python3-pip
# Verify installation
python3 --version
pip3 --versionChoosing an IDE / Code Editor
| Editor | Best For | Key Features |
|---|---|---|
| VS Code | General development | Free, extensions, integrated terminal |
| PyCharm | Python-specific development | Debugging, refactoring, virtual envs |
| Jupyter Notebook | Data science, learning | Interactive cells, inline output |
| IDLE | Absolute beginners | Comes with Python, simple interface |
| Sublime Text | Lightweight editing | Fast, minimal, extensible |
Recommended: Visual Studio Code with the Python extension is the best all-around choice for Python development.
VS Code Setup
- Download VS Code from code.visualstudio.com
- Install the Python extension by Microsoft
- Install the Pylance extension for enhanced IntelliSense
- Open a terminal in VS Code (
Ctrl+``) and verify Python works
Running Python Code
Interactive Mode (REPL)
Open your terminal and type python (or python3 on macOS/Linux) to enter the interactive mode:
>>> print("Hello from REPL!")
Hello from REPL!
>>> 2 + 3
5
>>> name = "BigXStar"
>>> print(f"Welcome to {name}")
Welcome to BigXStar
>>> exit()The REPL (Read-Eval-Print Loop) is great for quick experiments and testing small snippets.
Script Mode
Create a file called hello.py:
# hello.py
name = input("What is your name? ")
print(f"Hello, {name}! Welcome to Python.")Run it from the terminal:
python hello.py
# What is your name? Alice
# Hello, Alice! Welcome to Python.Virtual Environments
Virtual environments let you isolate project dependencies so different projects can use different library versions.
Creating a Virtual Environment
# Create a virtual environment
python -m venv myproject_env
# Activate it (Windows)
myproject_env\Scripts\activate
# Activate it (macOS/Linux)
source myproject_env/bin/activate
# Your prompt changes to show the active env
(myproject_env) $ python --versionInstalling Packages with pip
# Install a package
pip install requests
# Install a specific version
pip install flask==3.0.0
# Install from requirements file
pip install -r requirements.txt
# List installed packages
pip list
# Save current packages to requirements.txt
pip freeze > requirements.txtDeactivating
deactivateBest Practice: Always use virtual environments for your Python projects to avoid dependency conflicts.
Project Structure
A typical Python project structure looks like this:
my_project/
├── venv/ # Virtual environment (don't commit this)
├── src/
│ ├── __init__.py
│ ├── main.py
│ └── utils.py
├── tests/
│ ├── __init__.py
│ └── test_main.py
├── requirements.txt # Project dependencies
├── README.md
└── .gitignoreSample .gitignore for Python
venv/
__pycache__/
*.pyc
*.pyo
.env
.vscode/
*.egg-info/
dist/
build/Verifying Your Setup
Create a file called setup_check.py and run it to verify everything is working:
# setup_check.py
import sys
import platform
print("=" * 40)
print("Python Environment Check")
print("=" * 40)
print(f"Python Version: {sys.version}")
print(f"Platform: {platform.system()} {platform.release()}")
print(f"Architecture: {platform.machine()}")
print(f"Python Path: {sys.executable}")
print("=" * 40)
print("✓ Your Python environment is ready!")Expected output:
========================================
Python Environment Check
========================================
Python Version: 3.12.x (...)
Platform: Windows 11
Architecture: AMD64
Python Path: C:\Users\...\python.exe
========================================
✓ Your Python environment is ready!Summary
- Download and install Python 3 from python.org
- Always check "Add Python to PATH" on Windows
- Use VS Code with the Python extension for the best development experience
- Use the REPL for quick experiments, script files for real programs
- Always create virtual environments for project isolation
- Use
pipto install and manage packages
Next, we'll learn about Python's basic syntax and how to write clean Python code.