Description: VirtualEnv Manager is a Python script that simplifies the management of Python virtual environments within a local directory. With this script, users can create, list, activate, and install dependencies in virtual environments, making it ideal for developers who frequently switch between different Python projects.
- Clear Terminal: Clears the terminal screen for a clean start.
- Virtual Environment Listing: Automatically detects virtual environments within the current directory.
- Virtual Environment Creation: If no virtual environments are found, the script prompts the user to create one.
- Environment Activation: Activates a selected virtual environment for use in the current session.
- Dependency Installation: Installs dependencies from
requirements.txtif found and user-approved.
- Python 3.x is required.
- Access to a terminal or command line.
- The script is compatible with Windows, macOS, and Linux operating systems.
- Clone or download the script into your desired project directory.
- Ensure Python 3.x is installed and accessible in your system path.
-
Run the Script:
- Execute the script using Python from your command line:
python virtualenv_manager.py
- Execute the script using Python from your command line:
-
Clear Terminal:
- The script begins by clearing your terminal screen to provide a clean slate.
-
List or Create Virtual Environments:
- The script checks the current directory for any existing virtual environments. If multiple environments are found, you will be prompted to select one by entering the corresponding number.
- If no environments are detected, you’ll be prompted to create one.
-
Activate Virtual Environment:
- The selected virtual environment is then activated, ready for use in the current session.
-
Install Requirements:
- If a
requirements.txtfile is found in the directory, you’ll be prompted to install the dependencies listed in it. - Enter “yes” or “no” based on your preference.
- If a
clear_host(): Clears the terminal screen based on the operating system.print_colored(text, color): Prints colored text to the terminal, enhancing user interaction.list_virtual_environments(): Scans the directory for virtual environments by checking foractivatescripts in typical directories.create_virtual_environment(): Prompts the user to create a new virtual environment if none are found. Usesvenvby default if no name is provided.activate_virtual_environment(env_name): Attempts to activate the chosen environment by executing the activation script.install_requirements(): Checks for arequirements.txtfile and installs dependencies if confirmed by the user.
# Run the script
python virtualenv_manager.py
# Follow on-screen prompts:
# - Create or select a virtual environment
# - Activate the chosen environment
# - Optionally install dependencies from requirements.txt- Invalid Virtual Environment Name: If the selected virtual environment name is invalid or the activation script is missing, an error message is displayed.
- Dependency Installation Failure: If any dependency fails to install, an error message will be displayed, and the process will halt.
- Invalid User Input: For selections and confirmations, if invalid input is provided, the script will exit with an error message.
- Activation Not Persisting: Due to limitations in subprocess calls, the environment activation may not persist in some shells. It’s recommended to activate manually if needed.
- Permission Errors: If you encounter permission errors, ensure you have the necessary permissions to create and modify files in the current directory.
- Environment Deletion: Add support to delete old or unused virtual environments.
- Enhanced Dependency Management: List installed packages and versioning within the selected environment.