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
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.
fixInstall 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.
fixProvide 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.
fixVerify 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.
fixChoose 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.
fixProvide 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.