본문으로 건너뛰기
Previous
Next
Python Environment Setup — Complete Guide

Python Environment Setup — Complete Guide

Python Environment Setup — Complete Guide

이 글의 핵심

Set up Python on Windows/Mac/Linux: install Python 3, pip, venv, VS Code, PyCharm, requirements.txt, Poetry, and a clean project layout for beginners.

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

  • [Python basics: variables, operators, control flow](/en/blog/python-series-02-basic-syntax/
  • [Python data types: list, dict, tuple, set](/en/blog/python-series-03-data-types/
  • [Python functions](/en/blog/python-series-04-functions/

Official resources


  • [Python syntax](/en/blog/python-series-02-basic-syntax/
  • [Python data types](/en/blog/python-series-03-data-types/
  • Python modules (when available in English)

자주 묻는 질문 (FAQ)

Q. 이 내용을 실무에서 언제 쓰나요?

A. Set up Python on Windows/Mac/Linux: install Python 3, pip, venv, VS Code, PyCharm, requirements.txt, Poetry, and a clean… 실무에서는 위 본문의 예제와 선택 가이드를 참고해 적용하면 됩니다.

Q. 선행으로 읽으면 좋은 글은?

A. 각 글 하단의 이전 글 또는 관련 글 링크를 따라가면 순서대로 배울 수 있습니다. Python 시리즈 목차에서 전체 흐름을 확인할 수 있습니다.

Q. 더 깊이 공부하려면?

A. cppreference와 해당 라이브러리 공식 문서를 참고하세요. 글 말미의 참고 자료 링크도 활용하면 좋습니다.


같이 보면 좋은 글 (내부 링크)

이 주제와 연결되는 다른 글입니다.

  • [Python Basics | Variables· Operators](/en/blog/python-series-02-basic-syntax/
  • [Python Data Types | Lists· Dictionaries](/en/blog/python-series-03-data-types/
  • [Arrays and Lists](/en/blog/algorithm-series-01-array-list/
  • [C++ Development Environment Setup: From Compiler Install to](/en/blog/cpp-series-01-environment-setup/

이 글에서 다루는 키워드 (관련 검색어)

Python, Setup, pip, venv, VS Code, PyCharm, Poetry, pyenv, conda, Beginner 등으로 검색하시면 이 글이 도움이 됩니다.