ReviseAlgo Logo

Introduction to Python

Setting Up Python Environment

Installing Python and setting up development environment

Interview: Basic knowledge expected

Last Updated: June 12, 2026 8 min read

Setting up a proper Python development environment is the first step toward productive coding. This covers installation, package management, virtual environments, and editor configuration.

Installing Python

Python runs on all major operating systems. Always install the latest stable release (3.12+ recommended) from python.org or via your system package manager.

Windows

  • Download the installer from python.org/downloads.
  • Critical: Check "Add Python to PATH" during installation — forgetting this is the #1 beginner mistake.
  • Choose "Install Now" for default setup, or "Customize" to select pip, py launcher, and test suite options.
  • Verify in Command Prompt: python --version and pip --version.

macOS

  • macOS ships with a system Python, but it may be outdated. Use Homebrew: brew install python.
  • Homebrew installs Python to /opt/homebrew/bin/python3 and ensures pip3 works out of the box.
  • Alternatively, use pyenv for managing multiple Python versions side-by-side.

Linux (Debian/Ubuntu)

  • Update and install: sudo apt update && sudo apt install python3 python3-pip python3-venv.
  • For the latest version, use the deadsnakes PPA: sudo add-apt-repository ppa:deadsnakes/ppa.

Package Management with pip

pip is Python's official package manager. It installs packages from the Python Package Index (PyPI) which hosts over 500,000 packages.

  • pip install package_name — install a package
  • pip install package==1.2.3 — install a specific version
  • pip install -r requirements.txt — install from a requirements file
  • pip freeze > requirements.txt — save current environment packages
  • pip list — show installed packages
  • pip show package_name — show package details and dependencies

Never pip install globally

Installing packages globally (without a virtual environment) can cause version conflicts between projects and even break system tools. Always use virtual environments for project isolation.

Version Management with pyenv

pyenv lets you install and switch between multiple Python versions on the same machine — essential when working on projects that require different Python versions.

  • pyenv install 3.12.4 — install a specific Python version
  • pyenv global 3.12.4 — set the default Python version
  • pyenv local 3.11.9 — set Python version for current directory (creates .python-version file)
  • pyenv versions — list all installed versions

Common Pitfalls

  • PATH issues on Windows: Forgetting to check "Add Python to PATH" during installation leads to 'python is not recognized' errors.
  • python vs python3: On macOS/Linux, python may point to Python 2. Always use python3 explicitly or configure aliases.
  • Global pip installs: Running pip install without a virtual environment pollutes the global namespace and causes conflicts.
  • Ignoring PEP 668: Modern Linux distros mark the system Python as "externally managed" — use --user flag or virtual environments instead of global installs.

Use Cases

Setting up isolated project environments with venv or virtualenv

Managing multiple Python versions across different projects with pyenv

Reproducible builds using requirements.txt or Pipfile

CI/CD pipeline configuration requiring specific Python versions

Common Mistakes

Not adding Python to PATH during Windows installation

Installing packages globally instead of in virtual environments

Using system Python on macOS/Linux which may be outdated

Not pinning dependency versions leading to non-reproducible builds