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
- Installing Python
- Using pip
- Virtual environments
- VS Code
- PyCharm
- Project layout
- Your first program
- Summary
1. Installing Python
Windows
- Download the latest Python 3 from python.org/downloads.
- Run the installer.
- Check “Add Python to PATH”—this is critical so
pythonandpipwork in the terminal. - Choose Install Now or customize paths if needed.
- 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
- Install from code.visualstudio.com.
- Install the Python extension (Microsoft; Pylance often comes with it).
- 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 withpytest tests/..gitignore: ignorevenv/,__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 installon 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-hostfor PyPI hosts, upgrade pip, or configure corporate proxy.
Troubleshooting (quick)
| Issue | Idea |
|---|---|
python not found | Reinstall with PATH, or use full path / py launcher on Windows |
| Permission denied on pip | Use a venv or pip install --user |
| Wrong packages after install | Activate the correct venv; check which python / where python |
| Broken venv | deactivate, 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-pythonwith a matrix of Python versions.
Summary
- Install Python 3 from python.org or a package manager; ensure PATH on Windows.
- Use pip +
requirements.txt; consider Poetry for stricter workflows. - Use
python -m venvand activate before installing packages. - Use VS Code or PyCharm with the interpreter pointing at your venv.
- Structure repos with
src/,tests/,.gitignore.
Next steps
- Python basics: variables, operators, control flow
- Python data types: list, dict, tuple, set
- Python functions
Official resources
Related posts
- Python syntax
- Python data types
- Python modules (when available in English)