Skip to content

Latest commit

 

History

History
110 lines (74 loc) · 1.94 KB

readme.md

File metadata and controls

110 lines (74 loc) · 1.94 KB

Modern Python Setup

This guide outlines a modern Python development setup using pyenv and Poetry.

Prerequisites

  • macOS (Homebrew is used for installation)
  • Terminal access

Installation

1. Install Homebrew (if not already installed)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. Install pyenv

brew install pyenv

Add the following to your shell configuration (~/.zshrc or ~/.bash_profile):

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc

3. Install Poetry

curl -sSL https://install.python-poetry.org | python3 -

Verify the installation:

poetry --version

Setting Up a New Project

  1. Create a new project directory:
mkdir python101
cd python101
  1. Set the Python version using pyenv:
pyenv install 3.12.0  # or your desired version
pyenv local 3.12.0
  1. Initialize a new Poetry project:
poetry init
  1. Add project dependencies:
poetry add requests  # example: adding the requests library
  1. Create your main Python file (e.g., main.py)

  2. Run your project:

poetry run python main.py

Understanding pyenv and Poetry

  • pyenv: Manages Python versions at the system/user level
  • Poetry: Manages project dependencies and virtual environments

Project Structure

A typical project structure might look like this:

python101/
├── .python-version
├── pyproject.toml
├── poetry.lock
├── main.py
└── .gitignore

Best Practices

  • Use .gitignore to exclude unnecessary files (e.g., __pycache__/, *.pyc, .venv/)
  • Keep your Python versions up to date with pyenv
  • Regularly update your project dependencies with Poetry

Happy coding!

TODO

  1. testing
  2. ruff
  3. env variables