| name | python-setup |
| description | Python environment setup on your computer for Badger 2350 development. Use when installing Python, setting up virtual environments, installing development tools like mpremote or ampy, or configuring the computer-side development environment for Badger 2350 projects. |
Python Development Environment Setup
Complete guide to setting up Python on your computer for Universe 2025 (Tufty) Badge development, including virtual environments and all necessary tools.
Quick Start (First Time Setup)
If you're brand new and just want to get started quickly:
python3 --version
mkdir ~/badge-projects
cd ~/badge-projects
python3 -m venv venv
source venv/bin/activate
pip install mpremote
mpremote exec "print('Badge connected!')"
If any command fails, continue with the detailed instructions below.
Prerequisites Check
Before starting detailed setup, check what you already have:
python3 --version
pip3 --version
which mpremote
which ampy
which rshell
Install Python
macOS
Option 1: Using Homebrew (Recommended)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python3
python3 --version
pip3 --version
Option 2: Using python.org installer
- Download from https://www.python.org/downloads/
- Run installer
- Check "Add Python to PATH"
- Complete installation
Linux (Ubuntu/Debian)
sudo apt update
sudo apt install python3 python3-pip python3-venv
python3 --version
pip3 --version
Linux (Fedora/RHEL)
sudo dnf install python3 python3-pip
python3 --version
pip3 --version
Windows
Option 1: Using winget (Windows 10/11)
# Install Python
winget install Python.Python.3.11
# Restart terminal, then verify
python --version
pip --version
Option 2: Using python.org installer
- Download from https://www.python.org/downloads/
- Run installer
- IMPORTANT: Check "Add Python to PATH"
- Check "Install pip"
- Complete installation
- Restart terminal
Option 3: Using Microsoft Store
- Open Microsoft Store
- Search for "Python 3.11"
- Install
- Verify in terminal
Create Project Directory
Set up a dedicated directory for Badger 2350 projects:
mkdir -p ~/badger-projects
cd ~/badger-projects
mkdir my-badge-app
cd my-badge-app
Set Up Virtual Environment
Virtual environments isolate project dependencies and prevent conflicts.
Create Virtual Environment
python3 -m venv venv
python3 -m venv .venv
Activate Virtual Environment
macOS/Linux:
source venv/bin/activate
(venv) user@computer:~/badger-projects/my-badge-app$
deactivate
Windows (PowerShell):
# Enable script execution (first time only)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# Activate
venv\Scripts\Activate.ps1
# Deactivate when done
deactivate
Windows (Command Prompt):
# Activate
venv\Scripts\activate.bat
# Deactivate when done
deactivate
Verify Virtual Environment
which python3
where python
Install Badger Development Tools
With virtual environment activated:
Core Tools
pip install mpremote
pip install adafruit-ampy
pip install rshell
pip install esptool
mpremote --version
ampy --version
rshell --version
esptool.py version
Optional Development Tools
pip install thonny
pip install black
pip install pylint
pip install mypy
pip install pytest
pip install pytest-cov
pip install mkdocs
pip install sphinx
Save Dependencies
Create requirements.txt to track dependencies:
pip freeze > requirements.txt
Example requirements.txt:
mpremote==1.20.0
adafruit-ampy==1.1.0
rshell==0.0.32
esptool==4.6.2
black==23.12.1
pylint==3.0.3
pytest==7.4.3
Install from requirements.txt
pip install -r requirements.txt
pip install -r requirements.txt --upgrade
Configure Tools
mpremote Configuration
Create alias for easier use:
macOS/Linux (.bashrc or .zshrc):
alias badge='mpremote connect /dev/tty.usbmodem*'
source ~/.bashrc
badge ls
badge cp main.py :main.py
Windows (PowerShell profile):
# Open profile
notepad $PROFILE
# Add alias
function badge { mpremote connect COM3 @args }
# Reload
. $PROFILE
# Usage
badge ls
ampy Configuration
Set default port to avoid typing it each time:
macOS/Linux:
export AMPY_PORT=/dev/tty.usbmodem*
source ~/.bashrc
Windows:
# Add to PowerShell profile
$env:AMPY_PORT = "COM3"
# Or set permanently
[Environment]::SetEnvironmentVariable("AMPY_PORT", "COM3", "User")
Verify Complete Setup
Run this verification script:
echo "Verifying Badger 2350 Development Setup"
echo "========================================"
if command -v python3 &> /dev/null; then
echo "ā Python: $(python3 --version)"
else
echo "ā Python not found"
exit 1
fi
if command -v pip3 &> /dev/null; then
echo "ā pip: $(pip3 --version)"
else
echo "ā pip not found"
exit 1
fi
if [[ "$VIRTUAL_ENV" != "" ]]; then
echo "ā Virtual environment: active"
else
echo "ā Virtual environment: not active"
fi
tools=(mpremote ampy rshell esptool.py)
for tool in "${tools[@]}"; do
if command -v $tool &> /dev/null; then
echo "ā $tool: installed"
else
echo "ā $tool: not installed"
fi
done
echo "========================================"
echo "Setup verification complete!"
Make executable and run:
chmod +x verify_setup.sh
./verify_setup.sh
Windows PowerShell version:
# verify_setup.ps1
Write-Host "Verifying Badger 2350 Development Setup"
Write-Host "========================================"
# Check Python
if (Get-Command python -ErrorAction SilentlyContinue) {
$version = python --version
Write-Host "ā Python: $version"
} else {
Write-Host "ā Python not found"
exit 1
}
# Check pip
if (Get-Command pip -ErrorAction SilentlyContinue) {
Write-Host "ā pip: installed"
} else {
Write-Host "ā pip not found"
exit 1
}
# Check virtual environment
if ($env:VIRTUAL_ENV) {
Write-Host "ā Virtual environment: active"
} else {
Write-Host "ā Virtual environment: not active"
}
# Check tools
$tools = @("mpremote", "ampy", "rshell", "esptool.py")
foreach ($tool in $tools) {
if (Get-Command $tool -ErrorAction SilentlyContinue) {
Write-Host "ā $tool: installed"
} else {
Write-Host "ā $tool: not installed"
}
}
Write-Host "========================================"
Write-Host "Setup verification complete!"
Test Badge Connection
Once tools are installed, test connection to badge:
ls /dev/tty.usb*
[System.IO.Ports.SerialPort]::getportnames()
mpremote connect /dev/tty.usbmodem* exec "print('Hello from Badger!')"
mpremote connect COM3 exec "print('Hello from Badger!')"
Project Template
Create a standard project structure:
mkdir -p my-badge-app/{lib,assets,data,tests}
cd my-badge-app
touch main.py config.py README.md requirements.txt
touch lib/__init__.py
touch tests/test_main.py
cat > .gitignore <<EOF
# Virtual environment
venv/
.venv/
env/
# Python
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
# IDE
.vscode/
.idea/
*.swp
*.swo
# OS
.DS_Store
Thumbs.db
# Local config
config.local.py
.env
EOF
git init
Project structure:
my-badge-app/
āāā venv/ # Virtual environment (gitignored)
āāā main.py # Main application
āāā config.py # Configuration
āāā requirements.txt # Python dependencies
āāā README.md
āāā .gitignore
āāā lib/ # Reusable modules
ā āāā __init__.py
āāā assets/ # Images, fonts, etc.
āāā data/ # Runtime data
āāā tests/ # Test files
āāā test_main.py
IDE Setup
VS Code (Recommended)
brew install --cask visual-studio-code
sudo snap install code --classic
winget install Microsoft.VisualStudioCode
Recommended Extensions:
- Python (Microsoft)
- Pylance
- Python Debugger
- MicroPython (for syntax)
- GitLens
VS Code Settings (.vscode/settings.json):
{
"python.defaultInterpreterPath": "${workspaceFolder}/venv/bin/python",
"python.formatting.provider": "black",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"editor.formatOnSave": true,
"files.exclude": {
"**/__pycache__": true,
"**/*.pyc": true
}
}
PyCharm
- Download from https://www.jetbrains.com/pycharm/
- Open project directory
- Configure interpreter: Settings ā Project ā Python Interpreter
- Select existing venv or create new one
Thonny (Beginner-Friendly)
pip install thonny
thonny
Configure Thonny for Badger:
- Tools ā Options ā Interpreter
- Select "MicroPython (RP2040)"
- Select correct port
- Click OK
Workflow Scripts
Activate Script
Create activate.sh in project root:
#!/bin/bash
source venv/bin/activate
export BADGE_PORT="/dev/tty.usbmodem*"
echo "Badge development environment activated!"
echo "Python: $(which python3)"
echo "Badge port: $BADGE_PORT"
alias badge='mpremote connect $BADGE_PORT'
alias deploy='./deploy.sh'
echo "Ready to develop!"
Usage:
source activate.sh
Quick Deploy Script
Create deploy.sh:
#!/bin/bash
if [ -z "$BADGE_PORT" ]; then
BADGE_PORT="/dev/tty.usbmodem*"
fi
echo "Deploying to badge..."
mpremote connect $BADGE_PORT cp main.py :main.py
mpremote connect $BADGE_PORT cp config.py :config.py
echo "Deployment complete!"
Make executable:
chmod +x deploy.sh activate.sh
Common Setup Issues
"command not found: python"
macOS/Linux:
python3 --version
alias python=python3
alias pip=pip3
Windows:
# Use python instead of python3
python --version
# If not found, reinstall Python with "Add to PATH" checked
Important: On macOS/Linux, always use python3 and pip3 (not python and pip).
Python not in PATH
macOS/Linux:
export PATH="/usr/local/bin:$PATH"
export PATH="/opt/homebrew/bin:$PATH"
source ~/.bashrc
Windows:
- Reinstall Python with "Add to PATH" checked
- Or manually add to PATH:
- System Properties ā Environment Variables
- Add
C:\Python311 and C:\Python311\Scripts
pip install fails with permissions error
python3 -m venv venv
source venv/bin/activate
pip install mpremote
Virtual environment activation fails (Windows)
# Enable scripts (run as Administrator)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# Then activate normally
venv\Scripts\Activate.ps1
Badge not detected
macOS:
ls /dev/tty.usb*
sudo chmod 666 /dev/tty.usbmodem*
Linux:
sudo usermod -a -G dialout $USER
sudo mpremote connect /dev/ttyACM0
Windows:
- Install USB driver if needed
- Check Device Manager for COM port
- Try different USB ports
mpremote connection fails
mpremote connect /dev/tty.usbmodem14201
mpremote connect list
mpremote exec "print('Hello')"
"can't open file" or "No such file" errors
If you see errors like can't open file 'test_connection.py':
mpremote exec "print('Badge connected!')"
mpremote run my_app/__init__.py
Common missing files on first setup:
test_connection.py - Use mpremote exec for basic testing instead
deploy.sh - Use direct mpremote cp commands instead
- Apps/examples - Create them as you go
Don't let missing scripts block you - use the direct mpremote commands shown in CLAUDE.md and skills.
Update Tools
Keep tools updated:
source venv/bin/activate
pip install --upgrade pip
pip install --upgrade mpremote ampy rshell esptool
pip install -r requirements.txt --upgrade
ā ļø Verify Your Setup
CRITICAL: Always verify your setup is working correctly before starting development.
Complete Verification Checklist
Run through this checklist every time you start a new session:
python3 --version
which python3
mpremote --version
ampy --version
ls /dev/tty.usb*
mpremote connect /dev/tty.usbmodem* exec "print('Hello from Badge!')"
mpremote connect /dev/tty.usbmodem* exec "import badgeware; print('badgeware OK')"
Automated Verification Script
Create verify_setup.sh in your project:
#!/bin/bash
echo "=========================================="
echo "Badger 2350 Environment Verification"
echo "=========================================="
errors=0
if command -v python3 &> /dev/null; then
version=$(python3 --version)
echo "ā Python: $version"
else
echo "ā Python not found"
((errors++))
fi
if [[ "$VIRTUAL_ENV" != "" ]]; then
echo "ā Virtual environment: active ($VIRTUAL_ENV)"
else
echo "ā Virtual environment: not active"
echo " Run: source venv/bin/activate"
((errors++))
fi
if command -v mpremote &> /dev/null; then
echo "ā mpremote: installed"
else
echo "ā mpremote: not installed"
echo " Run: pip install mpremote"
((errors++))
fi
if mpremote connect list 2>&1 | grep -q "usb"; then
echo "ā Badge: detected"
if mpremote exec "print('OK')" 2>&1 | grep -q "OK"; then
echo "ā Badge REPL: working"
else
echo "ā Badge REPL: not responding"
((errors++))
fi
if mpremote exec "import badgeware" 2>&1; then
echo "ā badgeware module: available"
else
echo "ā badgeware module: not found"
((errors++))
fi
else
echo "ā Badge: not detected"
echo " Check USB connection"
((errors++))
fi
echo "=========================================="
if [ $errors -eq 0 ]; then
echo "ā ALL CHECKS PASSED - Ready for development!"
exit 0
else
echo "ā $errors ERROR(S) FOUND - Fix issues before proceeding"
exit 1
fi
Make executable: chmod +x verify_setup.sh
Run this script before every development session: ./verify_setup.sh
What to Do If Verification Fails
| Issue | Solution |
|---|
| Python not found | Reinstall Python, check PATH |
| venv not active | Run source venv/bin/activate |
| Tools not installed | Run pip install -r requirements.txt |
| Badge not detected | Check USB cable, try different port |
| REPL not responding | Restart badge, check for other programs using port |
| badgeware missing | Badge firmware may need reflashing |
Never skip verification - It catches 90% of issues before they become problems.
Best Practices
- Always verify setup first - Run verification script at start of session
- Always use virtual environments - Isolate project dependencies
- Keep requirements.txt updated -
pip freeze > requirements.txt
- Use version control (git) - Track changes
- Document your setup - Update README.md
- Test on clean environment - Verify requirements.txt is complete
- Don't commit venv/ - Add to .gitignore
- Pin versions - Avoid "works on my machine" issues
Next Steps
After setup is complete:
- ā Python installed
- ā Virtual environment created
- ā Tools installed (mpremote, ampy, etc.)
- ā Badge connected and detected
- ā Project structure created
Now you're ready to:
- Flash firmware to badge (see
badger-2350-dev skill)
- Create your first app (see
badger-app-creator skill)
- Connect sensors (see
badger-hardware skill)
Your development environment is ready! š