migrate-env command migrates your bench’s virtual environment to a different Python version, useful when upgrading or changing Python versions.
Usage
Arguments
Python executable or version to migrate to (e.g., python3.11, python3.10, /usr/bin/python3.11)
Options
Skip backing up the existing virtual environment
What It Does
The command performs the following steps:- Validates the target Python version exists and is compatible
- Backs up the current
envdirectory (unless--no-backupis used) - Creates a new virtual environment with the target Python version
- Reinstalls all app dependencies in the new environment
- Verifies the migration was successful
Examples
Migrate to Python 3.11
Migrate to Python 3.10
Migrate Without Backup
Use Specific Python Executable
Complete Migration Workflow
Before Migration
Perform Migration
After Migration
System Upgrade Example
When upgrading Ubuntu/Debian and Python:Backup Location
When backup is enabled (default), the old environment is moved to:Managing Backups
Rollback Failed Migration
If the migration fails:Python Version Requirements
Frappe Version 15
Frappe Version 15
- Minimum: Python 3.10
- Recommended: Python 3.11
- Maximum: Python 3.12
Frappe Version 14
Frappe Version 14
- Minimum: Python 3.7
- Recommended: Python 3.10
- Maximum: Python 3.11
Frappe Version 13
Frappe Version 13
- Minimum: Python 3.6
- Recommended: Python 3.9
- Maximum: Python 3.10
Implementation Details
Location:bench/commands/utils.py:170
The command:
- Validates the Python executable exists
- Creates a timestamped backup of the
envdirectory - Removes the old
envdirectory - Creates a new virtual environment using the specified Python
- Upgrades pip, setuptools, and wheel
- Reinstalls all app requirements from their respective
requirements.txtfiles - Reinstalls bench CLI in editable mode
When to Migrate
Migrate your Python environment when:- OS Upgrade: After upgrading Ubuntu, Debian, or other OS
- Python EOL: When your Python version reaches end-of-life
- Security: To get security fixes in newer Python versions
- Performance: Newer Python versions often have performance improvements
- Compatibility: When Frappe requires a newer Python version
- Development: To test on different Python versions
Performance Considerations
Migration time depends on:
- Number of apps installed
- Network speed (for downloading packages)
- CPU speed (for compiling binary packages)
Troubleshooting
Python Version Not Found
Python Version Not Found
If the Python version doesn’t exist:
Compilation Errors
Compilation Errors
If packages fail to compile:
Permission Errors
Permission Errors
If you get permission errors:
Disk Space Issues
Disk Space Issues
If you run out of disk space:
Best Practices
Test First
Test First
Test the migration on a development bench before production:
Backup Everything
Backup Everything
Always backup before migration:
Schedule Downtime
Schedule Downtime
For production:
- Schedule during low-traffic periods
- Notify users of maintenance
- Have rollback plan ready
- Monitor after migration
Clean Up After Success
Clean Up After Success
After confirming migration worked:
Related Commands
- bench setup requirements - Reinstall Python packages
- bench update - Update bench and apps
bench version- Check current versions