Python Environment Setup | Install on Windows & Mac and Get Started

Python Environment Setup | Install on Windows & Mac and Get Started

이 글의 핵심

Practical guide to Python environment setup: install Python, use pip and virtual environments, pick an editor, and run your first program.

Introduction: Start coding in Python

Python is straightforward to install. You will walk through Windows and macOS (with Linux notes), pip, virtual environments, editors, and a sensible project layout so each project stays isolated—like giving every app its own toolbox instead of one global junk drawer.

You will learn:

  • Installing Python (official installer, Homebrew, pyenv overview)
  • Python 3, and why 3.9+ is a good baseline
  • pip, requirements.txt, Poetry
  • Virtual environments: venv, virtualenv, conda
  • Editors: VS Code, PyCharm
  • Practical layout: src/, tests/, .gitignore
  • Running your first program

Table of contents

  1. Installing Python
  2. Using pip
  3. Virtual environments
  4. VS Code
  5. PyCharm
  6. Project layout
  7. Your first program
  8. Summary

1. Installing Python

Windows

  1. Download the latest Python 3 from python.org/downloads.
  2. Run the installer.
  3. Check “Add Python to PATH”—this is critical so python and pip work in the terminal.
  4. Choose Install Now or customize paths if needed.
  5. Verify:
python --version
pip --version

If Python is not on PATH, add the install and Scripts directories (e.g. ...\Python312\ and ...\Python312\Scripts\) under Environment Variables → Path, then open a new terminal.

macOS (Homebrew)

brew install python
python3 --version
pip3 --version

On macOS, python3/pip3 are common. Align versions with your team via pyenv or a pinned .python-version file.

Linux (Debian/Ubuntu)

sudo apt update
sudo apt install python3 python3-pip python3-venv
python3 --version
pip3 --version

Distro packages may lag; for servers, prefer venv per app and avoid global pip install when possible.


2. pip

pip installs packages from PyPI.

pip install requests
pip install requests==2.28.0
pip install --upgrade requests
pip uninstall requests
pip list
pip show requests

requirements.txt

pip freeze > requirements.txt
pip install -r requirements.txt

Example:

requests==2.28.0
flask==2.3.0
pandas==2.0.0

Poetry (optional)

Poetry manages dependencies and lockfiles via pyproject.toml / poetry.lock. Good for libraries and services when your team standardizes on it.

pip install poetry
poetry new my-package
cd my-package
poetry add requests
poetry install
poetry shell

3. Virtual environments

A virtual environment is an isolated Python environment per project (similar in spirit to node_modules).

Why: Project A needs Django 3; project B needs Django 4—both can coexist.

Create and activate (venv)

# Windows
python -m venv venv
venv\Scripts\Activate.ps1

# macOS / Linux
python3 -m venv venv
source venv/bin/activate

When active, your prompt often shows (venv). Then pip install affects only this environment.

deactivate

Typical workflow

mkdir my_project && cd my_project
python -m venv venv
source venv/bin/activate   # or Windows activate script
pip install --upgrade pip
pip install flask requests
pip freeze > requirements.txt
deactivate

conda (Anaconda/Miniconda) is strong when you need non-Python binaries and scientific stacks aligned in one toolchain.

conda create -n myenv python=3.12
conda activate myenv

Rule of thumb: web and general apps → venv + pip; heavy data/GPU stacks → consider conda.


4. VS Code

  1. Install from code.visualstudio.com.
  2. Install the Python extension (Microsoft; Pylance often comes with it).
  3. Python: Select Interpreter → choose ./venv/.../python.

Recommended settings (excerpt):

{
  "editor.formatOnSave": true,
  "python.terminal.activateEnvironment": true,
  "python.analysis.typeCheckingMode": "basic"
}

Install Black (or Ruff) in your venv for formatting.


5. PyCharm

PyCharm is a full IDE: refactoring, debugger, tests, DB tools. Community Edition is free. Create a project with a virtualenv or Poetry interpreter; Settings → Project → Python Interpreter matches VS Code’s interpreter choice.


6. Project layout

my_project/
├── src/
│   └── my_package/
│       ├── __init__.py
│       └── main.py
├── tests/
│   └── test_my_module.py
├── pyproject.toml
├── requirements.txt
├── README.md
├── .gitignore
└── venv/          # not committed
  • src/: clear import roots; often used with editable installs (pip install -e .).
  • tests/: run with pytest tests/.
  • .gitignore: ignore venv/, __pycache__/, .env, IDE folders.

7. Your first program

REPL

python
>>> print("Hello, Python!")
>>> exit()

Script file

# hello.py
print("Hello, Python!")
import sys
print(sys.version)
name = "Alice"
print(f"Hello, {name}")
python hello.py

VS Code

Open hello.py, use Run Python File in Terminal or F5 for debugging. Set breakpoints in the gutter.


Tips and pitfalls

  • Always prefer venv (or conda) over sudo pip install on system Python.
  • Freeze dependencies when sharing: pip freeze > requirements.txt.
  • Windows PowerShell: if activation fails, run Set-ExecutionPolicy RemoteSigned -Scope CurrentUser.
  • SSL / proxy errors with pip: try --trusted-host for PyPI hosts, upgrade pip, or configure corporate proxy.

Troubleshooting (quick)

IssueIdea
python not foundReinstall with PATH, or use full path / py launcher on Windows
Permission denied on pipUse a venv or pip install --user
Wrong packages after installActivate the correct venv; check which python / where python
Broken venvdeactivate, delete venv, recreate, pip install -r requirements.txt

Hands-on examples

Simple calculator (calculator.py)

def add(a, b):
    """Add two numbers."""
    return a + b

def subtract(a, b):
    return a - b

def multiply(a, b):
    return a * b

def divide(a, b):
    if b == 0:
        return "Error: division by zero"
    return a / b

def main():
    print("=" * 40)
    print("Simple calculator")
    print("=" * 40)
    num1 = float(input("First number: "))
    op = input("Operator (+, -, *, /): ")
    num2 = float(input("Second number: "))
    if op == "+":
        result = add(num1, num2)
    elif op == "-":
        result = subtract(num1, num2)
    elif op == "*":
        result = multiply(num1, num2)
    elif op == "/":
        result = divide(num1, num2)
    else:
        result = "Invalid operator"
    print(f"\nResult: {num1} {op} {num2} = {result}")

if __name__ == "__main__":
    main()

Sample .gitignore

venv/
.venv/
__pycache__/
*.pyc
.env
.idea/

Advanced pointers

  • pyenv: install and switch multiple Python versions per project.
  • Docker: FROM python:3.12-slim, COPY requirements.txt, RUN pip install -r requirements.txt.
  • CI: GitHub Actions actions/setup-python with a matrix of Python versions.

Summary

  1. Install Python 3 from python.org or a package manager; ensure PATH on Windows.
  2. Use pip + requirements.txt; consider Poetry for stricter workflows.
  3. Use python -m venv and activate before installing packages.
  4. Use VS Code or PyCharm with the interpreter pointing at your venv.
  5. Structure repos with src/, tests/, .gitignore.

Next steps


Official resources