The Ultimate Python Virtual Environment Manager and Script Runner ๐โจ
PyRunner simplifies Python development by intelligently managing virtual environments, dependencies, and script execution. Say goodbye to manual environment setup and hello to effortless Python development!
- ๐ง Auto-detection of configuration files
- ๐ Hot reloading with file watching
- ๐ Parallel dependency installation
- ๐พ Intelligent caching - only updates what changed
- ๐ Lock files for reproducible builds
- ๐ฏ One-command execution -
pyrunner run script.py - ๐ Interactive shells within environments
- ๐ Configuration profiles (dev/test/prod)
- ๐ Auto-fix corrupted environments
- ๐ฅ Health diagnostics for all environments
- ๐ Environment analytics and cleanup suggestions
- ๐ญ Environment cloning and templates
- ๐ Smart error messages with solutions
- ๐ฆ Package management (install/remove/update)
# Download PyRunner
git clone https://github.com/emaldos/PyRunner.git
cd PyRunner
# Make it executable
chmod +x pyrunner.py
# Add to system PATH (use PyRunner anywhere)
sudo ln -s $(pwd)/pyrunner.py /usr/local/bin/pyrunner# Download the script
wget https://raw.githubusercontent.com/emaldos/PyRunner/main/pyrunner.py
# Make executable
chmod +x pyrunner.py
# Copy to system directory
sudo cp pyrunner.py /usr/local/bin/pyrunner# Add to ~/.bashrc or ~/.zshrc
echo 'alias pyrunner="/path/to/pyrunner.py"' >> ~/.bashrc
source ~/.bashrc# Install required system packages
sudo apt update
sudo apt install python3-pip python3-venv python3-yaml
# Install Python dependencies for hot reloading
pip3 install watchdog pyyamlpyrunner --version
# Should output: PyRunner 2.0.0# Just run it! PyRunner handles everything
pyrunner run your_script.py
# Or with dependencies
pyrunner run app.py flask requests
# With hot reloading for development
pyrunner run server.py --watchThat's it! ๐ PyRunner automatically:
- โ Creates virtual environment
- โ Installs dependencies
- โ Runs your script
- โ Caches everything for next time
# Auto-detect configuration and run
pyrunner run script.py
# Specify packages if no config file exists
pyrunner run app.py flask pandas numpy
# Use specific environment
pyrunner run script.py --env my_environment
# Use configuration profile
pyrunner run app.py --profile production
# Enable hot reloading (auto-restart on file changes)
pyrunner run server.py --watch# Add packages to environment
pyrunner install flask
pyrunner install "requests>=2.25.0"
pyrunner install numpy pandas matplotlib
# Add to specific environment
pyrunner install flask --env web_development
# Remove packages
pyrunner remove unused-package
pyrunner remove old-library --env specific_env# Launch interactive shell in environment
pyrunner shell my_env
pyrunner shell /path/to/environment
# List all environments with details
pyrunner --list-envs# Check all environments
pyrunner doctor
# Check specific environment
pyrunner doctor my_env
# Auto-fix environment issues
pyrunner --fix-env corrupted_env
# Quick health check
pyrunner --health-check
# Validate environment integrity
pyrunner --validate-env my_env# Traditional mode with full control
pyrunner -f script.py -c requirements.txt
# Specify custom environment location
pyrunner -f script.py -c requirements.txt --env /path/to/environment
# Legacy location parameter (still supported)
pyrunner -f script.py -c requirements.txt --location my_env# Background execution with PID tracking
pyrunner -f server.py -c requirements.txt --pid
# Pass arguments to target script
pyrunner -f app.py -c requirements.txt -e "[--port 8000 --debug]"
pyrunner -f script.py -c requirements.txt -e "arg1 arg2 --flag"
# Force dependency update
pyrunner -f script.py -c requirements.txt --force-update
# Enable hot reloading
pyrunner -f app.py -c requirements.txt --watch
pyrunner -f server.py -c requirements.txt --watch-deps
# Debug mode with verbose errors
pyrunner -f script.py -c requirements.txt --debug# Enable logging with default location
pyrunner -f script.py -c requirements.txt --log
# Specify log directory
pyrunner -f script.py -c requirements.txt --log ./logs/
# Specify log directory and filename
pyrunner -f script.py -c requirements.txt --log ./logs/ app.log# Creates environment in current directory as "script_env"
pyrunner -f script.py -c requirements.txt
# Creates: ./script_env/# Relative path
pyrunner -f script.py -c requirements.txt --env my_custom_env
# Creates: ./my_custom_env/
# Absolute path
pyrunner -f script.py -c requirements.txt --env /opt/python_envs/web_app
# Creates: /opt/python_envs/web_app/
# Home directory
pyrunner -f script.py -c requirements.txt --env ~/environments/data_science
# Creates: /home/user/environments/data_science/
# Relative to parent directory
pyrunner -f script.py -c requirements.txt --env ../shared_envs/api_backend
# Creates: ../shared_envs/api_backend/# Multiple scripts sharing the same environment
pyrunner -f api_server.py -c web_requirements.txt --env /shared/web_stack
pyrunner -f background_worker.py -c web_requirements.txt --env /shared/web_stack
pyrunner -f database_migrator.py -c web_requirements.txt --env /shared/web_stack# By project type
pyrunner -f webapp.py -c requirements.txt --env ~/envs/web_development/
pyrunner -f analysis.py -c requirements.txt --env ~/envs/data_science/
pyrunner -f scanner.py -c requirements.txt --env ~/envs/security_tools/
# Centralized management
pyrunner -f script1.py -c req.txt --env /opt/python_environments/project_alpha
pyrunner -f script2.py -c req.txt --env /opt/python_environments/project_beta
# Team environments
pyrunner -f team_script.py -c requirements.txt --env /mnt/shared/team_envs/backend# Clone environment
pyrunner --clone-env source_environment target_environment
pyrunner --clone-env /path/to/source /path/to/target
# Reset (delete and recreate) environment
pyrunner --reset my_environment
pyrunner --reset /path/to/environment
# Cleanup unused environments (older than X days)
pyrunner --cleanup-envs 30
pyrunner --cleanup-envs 7# List all environments with statistics
pyrunner --list-envs
# Validate specific environment
pyrunner --validate-env my_environment
# Get detailed environment information
pyrunner doctor my_environment# Watch Python script for changes
pyrunner run app.py --watch
pyrunner -f server.py -c requirements.txt --watch
# Also watch dependency files
pyrunner run app.py --watch-deps
pyrunner -f app.py -c requirements.txt --watch-deps- ๐ Python script files โ Auto-restart script
- ๐ฆ requirements.txt โ Update dependencies + restart
- โ๏ธ config.yaml โ Reload configuration + restart
# When you save the Python script:
๐ Script changed: app.py
โน๏ธ Stopping current process...
๐ Restarting script...
โ
Script restarted (PID: 12345)
# When you modify requirements.txt:
๐ฆ Dependencies changed: requirements.txt
โน๏ธ Stopping current process...
๐ฆ Updating dependencies...
โ
Dependencies updated
๐ Restarting script...
โ
Script restarted (PID: 12346)# Basic requirements.txt
flask>=2.0.0
requests
pandas
numpy>=1.20.0
gunicorn# config.yaml
python_version: "3.11"
dependencies:
- "flask>=2.0.0"
- "requests"
- "pandas"
dev_dependencies:
- "pytest"
- "black"
- "mypy"
environment_variables:
DATABASE_URL: "postgresql://localhost/mydb"
SECRET_KEY: "your-secret-key"
DEBUG: "true"# config.yaml
python_version: "3.11"
# Profile-based configuration
profiles:
development:
dependencies:
- "flask[dev]"
- "pytest"
- "black"
- "mypy"
- "flask-debugtoolbar"
env_vars:
DEBUG: "true"
LOG_LEVEL: "debug"
DATABASE_URL: "sqlite:///dev.db"
testing:
dependencies:
- "flask"
- "pytest"
- "coverage"
- "pytest-cov"
env_vars:
TESTING: "true"
DATABASE_URL: "sqlite:///:memory:"
production:
dependencies:
- "flask"
- "gunicorn"
- "psycopg2-binary"
- "redis"
env_vars:
DEBUG: "false"
LOG_LEVEL: "info"
DATABASE_URL: "postgresql://prod_server/mydb"
# Active profile (change this to switch environments)
active_profile: "development"
# Base dependencies (always installed regardless of profile)
dependencies:
- "requests"
- "python-dotenv"
# Additional development dependencies
dev_dependencies:
- "ipython"
- "jupyter"
# Global environment variables
environment_variables:
SECRET_KEY: "global-secret-key"
APP_NAME: "MyApplication"
# Hot reloading configuration
hot_reload: true
# Use environment template
template: "./templates/web_template"
# External requirements file (optional)
requirements_file: "./additional_requirements.txt"# Use development profile
pyrunner run app.py --profile development
# Use production profile
pyrunner run app.py --profile production
# Use testing profile
pyrunner run tests.py --profile testing
# Traditional syntax with profiles
pyrunner -f app.py -c config.yaml --profile production- ๐ Easy switching between environments
- ๐ฆ Different dependencies per environment
- ๐ Environment-specific variables
- โก No config file changes needed
- ๐ฏ Targeted configurations for specific use cases
PyRunner provides intelligent error messages with actionable solutions:
โ Error: Failed to install flask==2.3.0
๐ Context: my_project_env
๐ก Suggestions:
โข There's a dependency version conflict
โข Try: pyrunner --fix-env my_project_env to resolve conflicts
โข Or use: --force-update to override version constraintsโ Error: Script file not found: /path/to/script.py
๐ Context: /path/to/script.py
๐ก Suggestions:
โข Check if the file exists: ls -la /path/to/script.py
โข Make sure you're in the correct directory
โข Use absolute path if the script is in another directory# Enable verbose debugging
pyrunner run script.py --debug
pyrunner -f script.py -c requirements.txt --debug
# Debug mode shows:
# - Full error tracebacks
# - Detailed dependency resolution
# - Environment validation steps
# - Configuration parsing detailspyrunner doctor
# Output example:
๐ฅ PyRunner Health Check
==================================================
๐จ Critical Issues:
โข web_env: Python executable missing
โข old_env: Environment directory missing
โ ๏ธ Warnings:
โข data_env: Dependency conflicts detected
โข ml_env: Could not check dependencies
๐ก Suggestions:
โข web_env: Large environment (245.2MB) - consider cleanup
โข old_env: Unused for 45 days - consider removalpyrunner doctor my_environment
# Output example:
๐ Diagnosing environment: my_environment
โ
Environment directory exists
โ
Python executable found and functional
โ
Pip executable found
โ ๏ธ Dependency conflicts detected
๐ก Run: pyrunner --fix-env my_environment# Automatically fix common issues
pyrunner --fix-env corrupted_environment
# Auto-fix performs:
# - Recreates corrupted Python executables
# - Fixes dependency conflicts
# - Cleans pip cache
# - Repairs metadata filespyrunner --list-envs
# Output:
Name Size (MB) Dependencies Scripts Last Used
---------------------------------------------------------------------------
web_app_env 45.2 12 3 2025-08-20
shared_env 78.1 25 5 2025-08-19
ml_project_env 156.7 45 2 2025-08-15
data_science_env 234.5 67 8 2025-08-10
old_test_env 12.3 5 1 2025-07-01# Clean environments unused for 30+ days
pyrunner --cleanup-envs 30
# Clean environments unused for 7+ days
pyrunner --cleanup-envs 7
# Output example:
Cleaned up 2 unused environments: old_test_env, abandoned_project_envpyrunner --validate-env my_environment
# Output:
โ
Environment my_environment is valid and healthy.
Size: 78.1 MB
Dependencies: 25
Scripts: 5 (app.py, worker.py, migrate.py, test.py, cli.py)
Last used: 2025-08-19 14:30PyRunner automatically generates requirements.lock files for reproducible builds:
{
"generated_at": 1692547200,
"python_version": "3.11",
"entries": [
{
"name": "flask",
"version": "2.3.2",
"hash": "",
"dependencies": []
},
{
"name": "requests",
"version": "2.31.0",
"hash": "",
"dependencies": []
}
]
}- โ Exact version reproduction across environments
- โ Faster subsequent installs (uses cached versions)
- โ Dependency conflict detection
- โ Build reproducibility for team development
# First run: Installs all dependencies, generates lock file
pyrunner -f app.py -c requirements.txt
# Subsequent runs: Uses lock file for faster installation
pyrunner -f app.py -c requirements.txt
# Force regenerate lock file
pyrunner -f app.py -c requirements.txt --force-update# Clone existing environment
pyrunner --clone-env source_environment target_environment
# Clone with absolute paths
pyrunner --clone-env /opt/envs/web_template /opt/envs/new_project
# Clone for team development
pyrunner --clone-env master_environment team_member_environment# config.yaml
template: "./templates/web_development_template"
dependencies:
- "additional-package"
# The template environment is cloned and then additional packages are installed# 1. Create a perfect environment
pyrunner -f setup_script.py -c base_requirements.txt --env perfect_web_env
# 2. Clone it as a template
pyrunner --clone-env perfect_web_env ./templates/web_template
# 3. Use template for new projects
pyrunner -f new_project.py -c config.yaml # config.yaml references the template# Isolated environments for security tools
pyrunner -f port_scanner.py -c security_requirements.txt --env /opt/security_envs/reconnaissance
pyrunner -f sql_injection_test.py -c webapp_testing.txt --env /opt/security_envs/web_testing
pyrunner -f network_analyzer.py -c network_tools.txt --env /opt/security_envs/network_analysis# Quick setup for CTF challenges
pyrunner run crypto_solver.py pycrypto gmpy2 sage
# Binary analysis environment
pyrunner -f reverse_engineer.py -c binary_analysis.txt --env /opt/ctf_envs/reverse_engineering
# Web exploitation environment
pyrunner -f web_exploit.py -c web_security.txt --env /opt/ctf_envs/web_exploitation- ๐ก๏ธ Tool isolation - Keep different security tools separate
- ๐ Fast deployment - Quick environment setup for specific tasks
- ๐ Reproducible setups - Same environment across team members
- ๐ Environment tracking - Monitor tool environments and usage
| Command | Description | Example |
|---|---|---|
run |
Smart run with auto-detection | pyrunner run app.py |
run --watch |
Run with hot reloading | pyrunner run server.py --watch |
run --profile |
Run with specific profile | pyrunner run app.py --profile prod |
install |
Add package to environment | pyrunner install flask |
remove |
Remove package from environment | pyrunner remove flask |
shell |
Launch shell in environment | pyrunner shell my_env |
doctor |
Diagnose environment issues | pyrunner doctor my_env |
| Flag | Description | Example |
|---|---|---|
-f, --file |
Python script to run | pyrunner -f script.py |
-c, --config |
Configuration file | pyrunner -c requirements.txt |
--env |
Environment path | pyrunner --env /path/to/env |
-e, --extra |
Arguments for target script | pyrunner -e "[--port 8000]" |
-p, --pid |
Background execution | pyrunner -p |
--watch |
Enable hot reloading | pyrunner --watch |
--watch-deps |
Watch dependency files | pyrunner --watch-deps |
--force-update |
Force dependency update | pyrunner --force-update |
--debug |
Verbose error messages | pyrunner --debug |
| Flag | Description | Example |
|---|---|---|
--list-envs |
List all environments | pyrunner --list-envs |
--cleanup-envs |
Clean old environments | pyrunner --cleanup-envs 30 |
--clone-env |
Clone environment | pyrunner --clone-env src dst |
--validate-env |
Validate environment | pyrunner --validate-env my_env |
--fix-env |
Auto-fix environment | pyrunner --fix-env my_env |
--reset |
Reset environment | pyrunner --reset my_env |
--health-check |
Quick health check | pyrunner --health-check |
| Flag | Description | Example |
|---|---|---|
--log |
Enable logging (default location) | pyrunner --log |
--log DIR |
Log to specific directory | pyrunner --log ./logs/ |
--log DIR FILE |
Log to specific file | pyrunner --log ./logs/ app.log |
# Organize by project type
~/environments/
โโโ web_development/
โโโ data_science/
โโโ machine_learning/
โโโ security_tools/
# Use descriptive environment names
pyrunner --env ~/environments/web_development/ecommerce_api
pyrunner --env ~/environments/data_science/customer_analysis# 1. Development with hot reloading
pyrunner run app.py --profile development --watch
# 2. Testing with separate environment
pyrunner run tests.py --profile testing
# 3. Production deployment
pyrunner run app.py --profile production --pid# Add new packages during development
pyrunner install new-package --env development_env
# Update all dependencies
pyrunner -f app.py -c requirements.txt --force-update
# Check for dependency conflicts
pyrunner doctor my_env# Regular health checks
pyrunner --health-check
# Clean up old environments monthly
pyrunner --cleanup-envs 30
# Validate critical environments
pyrunner --validate-env production_env# Team shared environments
pyrunner -f api.py -c requirements.txt --env /shared/team_envs/backend_api
pyrunner -f worker.py -c requirements.txt --env /shared/team_envs/background_workers
# Environment templates for consistency
pyrunner --clone-env /templates/enterprise_base /projects/new_microservice# Course-specific environments
pyrunner run lesson1.py --env ~/courses/python_basics/
pyrunner run data_analysis.py --env ~/courses/data_science/
# Workshop environments
pyrunner --clone-env workshop_template student_environment# Experiment isolation
pyrunner run experiment_v1.py --env ~/research/experiment_1/
pyrunner run experiment_v2.py --env ~/research/experiment_2/
# Reproducible research
pyrunner -f analysis.py -c research_requirements.txt --force-update# Challenge-specific environments
pyrunner run crypto_challenge.py --env ~/ctf/picoctf/crypto/
pyrunner run web_challenge.py --env ~/ctf/hackthebox/web/
# Tool development
pyrunner run exploit_dev.py --env ~/security_research/exploits/ --watch# Problem: Permission denied when creating environments
# Solution: Check directory permissions or use different location
pyrunner -f script.py -c requirements.txt --env ~/my_envs/project
# Problem: Cannot install packages
# Solution: Don't use sudo with virtual environments
pyrunner install package # โ
Correct
sudo pyrunner install package # โ Wrong# Problem: Package version conflicts
# Solution: Use auto-fix or force update
pyrunner --fix-env my_environment
pyrunner -f script.py -c requirements.txt --force-update# Problem: Environment not working after system update
# Solution: Validate and auto-fix
pyrunner --validate-env my_env
pyrunner --fix-env my_env
# Last resort: Reset environment
pyrunner --reset my_env# Problem: PyRunner command not found
# Solution: Install system dependencies
sudo apt install python3-pip python3-venv python3-yaml
pip3 install watchdog pyyaml
# Problem: Hot reloading not working
# Solution: Install watchdog
pip3 install watchdog- Enable debug mode:
pyrunner run script.py --debug - Check environment health:
pyrunner doctor my_env - Validate installation:
pyrunner --validate-env my_env - Check system dependencies:
python3 -m venv --help - Review configuration: Check your
requirements.txtorconfig.yaml
We welcome contributions! Here's how to get started:
- ๐ด Fork the repository
- ๐ฅ Clone your fork:
git clone https://github.com/your-username/PyRunner.git - ๐ฟ Create a feature branch:
git checkout -b feature/amazing-feature - โ๏ธ Make your changes
- ๐งช Test your changes thoroughly
- ๐ Commit your changes:
git commit -m 'Add amazing feature' - ๐ค Push to the branch:
git push origin feature/amazing-feature - ๐ฏ Open a Pull Request
Found a bug? Please open an issue with:
- ๐ Clear description of the problem
- ๐ Steps to reproduce the issue
- ๐ป System information (OS, Python version)
- ๐ Configuration files (if relevant)
- ๐ผ๏ธ Screenshots or error messages
Have an idea? We'd love to hear it! Open an issue with:
- ๐ฏ Clear description of the feature
- ๐ญ Use case and benefits
- ๐ง Implementation suggestions (optional)
- ๐ Priority level (nice-to-have vs critical)
# Clone the repository
git clone https://github.com/emaldos/PyRunner.git
cd PyRunner
# Install development dependencies
pip3 install watchdog pyyaml pytest black mypy
# Run tests
python3 -m pytest tests/
# Format code
black pyrunner.py
# Type checking
mypy pyrunner.pyThis project is licensed under the MIT License - see the LICENSE file for details.
- ๐ Python community for the amazing ecosystem
- ๐ฆ pip and venv for providing the foundation
- ๐ฅ Contributors who make PyRunner better every day
- ๐ก Users who provide valuable feedback and ideas
- ๐ก๏ธ Security community for testing and validation
- ๐ README: Complete usage guide (this document)
- ๐ก Examples: Check the examples throughout this guide
- ๐ฏ Command Reference: See the complete command reference section
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ง Direct Contact: Open an issue for questions
- ๐ Community: Join discussions and help others
- ๐ Homepage: GitHub Repository
- ๐ **Issues