{"id":3852,"library":"virtualenv-clone","title":"virtualenv-clone","description":"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.","status":"maintenance","version":"0.5.7","language":"en","source_language":"en","source_url":"https://github.com/edwardgeorge/virtualenv-clone","tags":["virtualenv","venv","clone","environment","python"],"install":[{"cmd":"pip install virtualenv-clone","lang":"bash","label":"Install virtualenv-clone"}],"dependencies":[{"reason":"virtualenv-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.","package":"virtualenv","optional":false}],"imports":[],"quickstart":{"code":"import os\nimport subprocess\nimport shutil\n\ndef run_command(cmd, shell=True, check=True):\n    print(f\"Executing: {cmd}\")\n    result = subprocess.run(cmd, shell=shell, check=check, capture_output=True, text=True)\n    print(result.stdout)\n    if result.stderr:\n        print(f\"Stderr: {result.stderr}\")\n    return result\n\noriginal_venv_name = \"my_original_venv\"\ncloned_venv_name = \"my_cloned_venv\"\n\n# Cleanup any previous runs\nif os.path.exists(original_venv_name):\n    shutil.rmtree(original_venv_name)\nif os.path.exists(cloned_venv_name):\n    shutil.rmtree(cloned_venv_name)\n\nprint(\"1. Creating original virtual environment...\")\nrun_command(f\"python -m venv {original_venv_name}\")\n\nprint(\"2. Activating original virtual environment and installing requests...\")\n# On Windows, activate is in Scripts; on Unix-like, it's in bin\nactivate_script = os.path.join(original_venv_name, 'Scripts', 'activate') if os.name == 'nt' else os.path.join(original_venv_name, 'bin', 'activate')\n\n# For cross-platform activation and command execution within venv\n# Using subprocess.run with full path to python/pip within the venv\npython_executable = os.path.join(original_venv_name, 'Scripts', 'python') if os.name == 'nt' else os.path.join(original_venv_name, 'bin', 'python')\npip_executable = os.path.join(original_venv_name, 'Scripts', 'pip') if os.name == 'nt' else os.path.join(original_venv_name, 'bin', 'pip')\n\nrun_command(f\"{pip_executable} install requests\", shell=False) # Use full path, not shell activation\n\nprint(f\"3. Verifying requests in {original_venv_name}...\")\nrun_command(f\"{python_executable} -c \\\"import requests; print('requests imported successfully in original venv')\\\"\", shell=False)\n\nprint(f\"4. Cloning {original_venv_name} to {cloned_venv_name}...\")\n# virtualenv-clone is expected to be installed globally or accessible in PATH\nrun_command(f\"virtualenv-clone {original_venv_name} {cloned_venv_name}\")\n\nprint(f\"5. Activating cloned virtual environment and verifying requests...\")\ncloned_python_executable = os.path.join(cloned_venv_name, 'Scripts', 'python') if os.name == 'nt' else os.path.join(cloned_venv_name, 'bin', 'python')\n\nrun_command(f\"{cloned_python_executable} -c \\\"import requests; print('requests imported successfully in cloned venv')\\\"\", shell=False)\n\nprint(\"Quickstart complete: virtual environment cloned and verified.\")\n\n# Cleanup\nprint(\"Cleaning up...\")\nshutil.rmtree(original_venv_name)\nshutil.rmtree(cloned_venv_name)\nprint(\"Cleanup complete.\")","lang":"python","description":"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."},"warnings":[{"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`.","message":"Cloning 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.","severity":"breaking","affected_versions":"All versions"},{"fix":"Ensure the target system's base Python version used for the new virtual environment matches the Python version of the original virtual environment.","message":"While 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The 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.","severity":"deprecated","affected_versions":"All versions"},{"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.","message":"virtualenv-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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}