How to Set Up a Python Development Environment on Your Breeze
Python is one of the most versatile programming languages, used for web development, data science, automation, machine learning, and scripting. Setting up a proper Python development environment on your Breeze ensures isolated project dependencies, reproducible builds, and a smooth workflow. This guide covers everything from installing Python to managing virtual environments and deploying applications.
Installing Python
Most Breeze OS templates include Python 3, but you may want a newer version or multiple versions:
# Check existing Python version
python3 --version
# Install Python and essential tools on Ubuntu/Debian
sudo apt update
sudo apt install -y python3 python3-pip python3-venv python3-dev build-essential
# Install on AlmaLinux/Rocky
sudo dnf install -y python3 python3-pip python3-devel gcc
Installing Multiple Python Versions with pyenv
If your projects require different Python versions, use pyenv:
# Install pyenv dependencies
sudo apt install -y make libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev \
xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
# Install pyenv
curl https://pyenv.run | bash
# Add to your shell profile (~/.bashrc or ~/.zshrc)
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# Install and use a specific Python version
pyenv install 3.12.1
pyenv global 3.12.1
python --version # Should show 3.12.1
Working with Virtual Environments
Virtual environments isolate project dependencies so that different projects can use different package versions without conflicts:
# Create a virtual environment
python3 -m venv /home/user/projects/myapp/venv
# Activate the virtual environment
source /home/user/projects/myapp/venv/bin/activate
# Your prompt changes to show the active environment
(venv) user@breeze:~$
# Install packages within the environment
pip install flask gunicorn sqlalchemy
# Freeze dependencies for reproducibility
pip freeze > requirements.txt
# Deactivate when done
deactivate
Managing Dependencies with pip
Best practices for dependency management:
# Always use a requirements file
pip install -r requirements.txt
# Pin exact versions for production
Flask==3.0.0
gunicorn==21.2.0
SQLAlchemy==2.0.23
# Separate development dependencies
pip install -r requirements-dev.txt # pytest, flake8, black, etc.
# Upgrade pip itself regularly
pip install --upgrade pip
Using Poetry for Advanced Dependency Management
Poetry is a modern tool that handles dependency resolution, virtual environments, and packaging:
# Install Poetry
curl -sSL https://install.python-poetry.org | python3 -
# Create a new project
poetry new myproject
cd myproject
# Add dependencies
poetry add flask gunicorn sqlalchemy
poetry add --group dev pytest black flake8
# Install all dependencies
poetry install
# Run commands within the environment
poetry run python app.py
poetry run pytest
Setting Up a Flask Application
Create a basic Flask application structure:
myapp/
├── app/
│ ├── __init__.py
│ ├── routes.py
│ └── models.py
├── tests/
│ └── test_routes.py
├── requirements.txt
├── wsgi.py
└── .env
Running in Production with Gunicorn
Use Gunicorn as your WSGI server for production deployments:
# Install gunicorn in your virtual environment
pip install gunicorn
# Run with sensible defaults
gunicorn --workers 4 --bind 0.0.0.0:8000 wsgi:app
# Create a systemd service for automatic start
sudo tee /etc/systemd/system/myapp.service > /dev/null <<EOF
[Unit]
Description=My Python App
After=network.target
[Service]
User=www-data
Group=www-data
WorkingDirectory=/home/user/projects/myapp
Environment="PATH=/home/user/projects/myapp/venv/bin"
ExecStart=/home/user/projects/myapp/venv/bin/gunicorn --workers 4 --bind 127.0.0.1:8000 wsgi:app
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable myapp
sudo systemctl start myapp
Development Workflow Tips
- Use
.envfiles withpython-dotenvfor environment-specific configuration - Set up pre-commit hooks with
pre-committo enforce code quality - Use
blackfor consistent code formatting andflake8for linting - Write tests with
pytestand aim for meaningful coverage of critical paths - Use
logginginstead ofprint()for application output - Store secrets in environment variables, never in source code