This guide outlines a modern Python development setup using pyenv and Poetry.
- macOS (Homebrew is used for installation)
- Terminal access
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
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
curl -sSL https://install.python-poetry.org | python3 -
Verify the installation:
poetry --version
- Create a new project directory:
mkdir python101
cd python101
- Set the Python version using pyenv:
pyenv install 3.12.0 # or your desired version
pyenv local 3.12.0
- Initialize a new Poetry project:
poetry init
- Add project dependencies:
poetry add requests # example: adding the requests library
-
Create your main Python file (e.g.,
main.py
) -
Run your project:
poetry run python main.py
- pyenv: Manages Python versions at the system/user level
- Poetry: Manages project dependencies and virtual environments
A typical project structure might look like this:
python101/
├── .python-version
├── pyproject.toml
├── poetry.lock
├── main.py
└── .gitignore
- 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!
- testing
- ruff
- env variables