pip backup requirements lib in original env

 Standard Virtual Environment (venv or virtualenv)

The "original" and most common way to back up a virtual environment is not to copy the folder itself (which often breaks due to hardcoded paths), but to "freeze" its state into a list of dependencies.
  • Export (Backup): Run this command inside your activated environment.
    bash
    pip freeze > requirements.txt
    
    請謹慎使用程式碼。
    This creates a file named requirements.txt containing every package and its exact version.
  • Restore: To recreate the environment elsewhere, create a new venv and run:
    bash
    pip install -r requirements.txt
    
    請謹慎使用程式碼。

留言