Registry / devops / virtualenv-clone

virtualenv-clone

JSON →
library0.5.7pypypiunverified

virtualenv-clone is a Python package that provides a command-line script to clone existing non-relocatable virtual environments. It handles updating internal paths (like `VIRTUAL_ENV` in `activate` scripts) and shebangs in executables to point to the new location, aiming to make a copied virtualenv functional without reinstalling packages. The current version is 0.5.7, released in September 2021, suggesting a maintenance-level release cadence.

pip install virtualenv-clone
INSTALL
IMPORT
SIG · VIRTUALENV-CLONE
V
virtualenv-clone
devopspythonv0.5.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

This quickstart demonstrates how to create a source virtual environment, install a package into it, then use `virtualenv-clone` to create a functional copy, and finally verify that the cloned environment contains the installed package and is correctly configured.

import os import subprocess import shutil def run_command(cmd, shell=True, check=True): print(f"Executing: {cmd}") result = subprocess.run(cmd, shell=shell, check=check, capture_output=True, text=True) print(result.stdout) if result.stderr: print(f"Stderr: {result.stderr}") return result original_venv_name = "my_original_venv" cloned_venv_name = "my_cloned_venv" # Cleanup any previous runs if os.path.exists(original_venv_name): shutil.rmtree(original_venv_name) if os.path.exists(cloned_venv_name): shutil.rmtree(cloned_venv_name) print("1. Creating original virtual environment...") run_command(f"python -m venv {original_venv_name}") print("2. Activating original virtual environment and installing requests...") # On Windows, activate is in Scripts; on Unix-like, it's in bin activate_script = os.path.join(original_venv_name, 'Scripts', 'activate') if os.name == 'nt' else os.path.join(original_venv_name, 'bin', 'activate') # For cross-platform activation and command execution within venv # Using subprocess.run with full path to python/pip within the venv python_executable = os.path.join(original_venv_name, 'Scripts', 'python') if os.name == 'nt' else os.path.join(original_venv_name, 'bin', 'python') pip_executable = os.path.join(original_venv_name, 'Scripts', 'pip') if os.name == 'nt' else os.path.join(original_venv_name, 'bin', 'pip') run_command(f"{pip_executable} install requests", shell=False) # Use full path, not shell activation print(f"3. Verifying requests in {original_venv_name}...") run_command(f"{python_executable} -c \"import requests; print('requests imported successfully in original venv')\"", shell=False) print(f"4. Cloning {original_venv_name} to {cloned_venv_name}...") # virtualenv-clone is expected to be installed globally or accessible in PATH run_command(f"virtualenv-clone {original_venv_name} {cloned_venv_name}") print(f"5. Activating cloned virtual environment and verifying requests...") cloned_python_executable = os.path.join(cloned_venv_name, 'Scripts', 'python') if os.name == 'nt' else os.path.join(cloned_venv_name, 'bin', 'python') run_command(f"{cloned_python_executable} -c \"import requests; print('requests imported successfully in cloned venv')\"", shell=False) print("Quickstart complete: virtual environment cloned and verified.") # Cleanup print("Cleaning up...") shutil.rmtree(original_venv_name) shutil.rmtree(cloned_venv_name) print("Cleanup complete.")
virtualenv-clone --version
Debug
Known issues
breakingCloning virtual environments across different operating systems or CPU architectures is not supported and will likely result in a broken environment. Paths, binaries, and low-level libraries are specific to the system they were created on. virtualenv-clone primarily addresses relocation within the *same* system.
fix
For cross-platform replication, use `pip freeze > requirements.txt` in the source environment, then create a new virtual environment on the target system and run `pip install -r requirements.txt`.
affects: All versions
gotchaWhile virtualenv-clone aims to handle path rewriting, cloning environments created with different *major* Python versions (e.g., cloning a Python 3.8 venv to a Python 3.9 venv) can lead to unexpected issues or errors, even if the tool theoretically supports both Python versions. It's best used for cloning environments based on the *same* Python executable.
fix
Ensure the target system's base Python version used for the new virtual environment matches the Python version of the original virtual environment.
affects: All versions
deprecatedThe project is currently listed with a 'Development Status :: 3 - Alpha' classifier on PyPI. While functional, this indicates it might not be considered fully stable or production-ready by its maintainers, and future breaking changes, while unlikely given its current maintenance status, could occur.
fix
Be aware that the project is in an alpha state; test thoroughly in your environment. Consider contributing to its development or using `pip freeze` and `pip install -r` for more robust environment replication if this tool proves insufficient.
affects: All versions
gotchavirtualenv-clone is a command-line utility and does not expose a public Python API for direct import and programmatic use. Its functionality is accessed solely via the `virtualenv-clone` command in your shell.
fix
Always use `virtualenv-clone <source_path> <destination_path>` directly from your shell or via `subprocess.run` calls, rather than attempting to `import virtualenv_clone` in Python code.
affects: All versions
Errors
Common errors & fixes
virtualenv-clone: command not found
The `virtualenv-clone` package is not installed, or its executable script is not in the system's PATH.
fix
Install the package using pip: `pip install virtualenv-clone`
virtualenv-clone: error: the following arguments are required: OLD_VIRTUALENV_PATH, NEW_VIRTUALENV_PATH
The `virtualenv-clone` command was executed without providing the required source and destination paths for the virtual environment.
fix
Provide both the path to the existing virtual environment and the desired path for the new cloned environment: `virtualenv-clone /path/to/existing/venv /path/to/new/cloned/venv`
FileNotFoundError: [Errno 2] No such file or directory: '/path/to/old/venv'
The specified `OLD_VIRTUALENV_PATH` does not exist or does not point to a valid, accessible virtual environment directory.
fix
Verify the `OLD_VIRTUALENV_PATH` is correct and refers to an actual existing virtual environment.
FileExistsError: [Errno 17] File exists: '/path/to/new/venv'
The `NEW_VIRTUALENV_PATH` already exists as a directory, and `virtualenv-clone` does not overwrite existing directories by default.
fix
Choose a non-existent path for the new virtual environment, or manually remove the existing directory before cloning: `rm -rf /path/to/new/venv`
virtualenv-clone: error: argument -p/--python-path: expected one argument
The `-p` or `--python-path` option was used without providing the required path to a Python executable for the new virtual environment.
fix
Provide the absolute path to the target Python executable: `virtualenv-clone OLD_VIRTUALENV_PATH NEW_VIRTUALENV_PATH -p /usr/bin/python3`
Upgrade
Version history
0.5.7latest on PyPI · released Sep 7, 2021
Audit
Dependencies
virtualenvrequiredvirtualenv-clone is designed to work with virtual environments created by virtualenv (or venv), and implicitly relies on their structure. While not a direct pip dependency, the utility is meaningless without an existing virtual environment tool.
Agent activity
7 hits · last 30 days
node
6
Resources
virtualenv-clone — pip install virtualenv-clone · libregistry