# Buggy code
def copy_required_modules(dst_prefix, symlink):
    import imp

    # If we are running under -p, we need to remove the current
    # directory from sys.path temporarily here, so that we
    # definitely get the modules from the site directory of
    # the interpreter we are running under, not the one
    # virtualenv.py is installed under (which might lead to py2/py3
    # incompatibility issues)
    _prev_sys_path = sys.path
    if os.environ.get("VIRTUALENV_INTERPRETER_RUNNING"):
        sys.path = sys.path[1:]
    try:
        for modname in REQUIRED_MODULES:
            if modname in sys.builtin_module_names:
                logger.info("Ignoring built-in bootstrap module: %s" % modname)
                continue
            try:
                f, filename, _ = imp.find_module(modname)
            except ImportError:
                logger.info("Cannot import bootstrap module: %s" % modname)
            else:
                if f is not None:
                    f.close()
                # special-case custom readline.so on OS X, but not for pypy:
                if (
                    modname == "readline"
                    and sys.platform == "darwin"
                    and not (
                        is_pypy or filename.endswith(join("lib-dynload", "readline.so"))
                    )
                ):
                    dst_filename = join(
                        dst_prefix, "lib", "python%s" % sys.version[:3], "readline.so"
                    )
                else:
                    dst_filename = change_prefix(filename, dst_prefix)
                copyfile(filename, dst_filename, symlink)
                if filename.endswith(".pyc"):
                    pyfile = filename[:-1]
                    if os.path.exists(pyfile):
                        copyfile(pyfile, dst_filename[:-1], symlink)
    finally:
        sys.path = _prev_sys_path


# Traceback (AssertionError)
Traceback (most recent call last):
File "virtualenv.py", line 1645, in <module>
main()
File "virtualenv.py", line 556, in main
prompt=options.prompt)
File "virtualenv.py", line 645, in create_environment
site_packages=site_packages, clear=clear))
File "virtualenv.py", line 769, in install_python
copy_required_modules(home_dir)
File "virtualenv.py", line 723, in copy_required_modules
dst_filename = change_prefix(filename, dst_prefix)
File "virtualenv.py", line 708, in change_prefix
(filename, prefixes)
AssertionError: Filename /home/apy/.local/lib/python2.6/site-packages/readline.so does not start with any of these prefixes: ['/opt/ActivePython-2.6']

# Fixed code
def copy_required_modules(dst_prefix, symlink):
    import imp

    # If we are running under -p, we need to remove the current
    # directory from sys.path temporarily here, so that we
    # definitely get the modules from the site directory of
    # the interpreter we are running under, not the one
    # virtualenv.py is installed under (which might lead to py2/py3
    # incompatibility issues)
    _prev_sys_path = sys.path
    if os.environ.get("VIRTUALENV_INTERPRETER_RUNNING"):
        sys.path = sys.path[1:]
    try:
        for modname in REQUIRED_MODULES:
            if modname in sys.builtin_module_names:
                logger.info("Ignoring built-in bootstrap module: %s" % modname)
                continue
            try:
                f, filename, _ = imp.find_module(modname)
            except ImportError:
                logger.info("Cannot import bootstrap module: %s" % modname)
            else:
                if f is not None:
                    f.close()
                # special-case custom readline.so on OS X, but not for pypy:
                if (
                    modname == "readline"
                    and sys.platform == "darwin"
                    and not (
                        is_pypy or filename.endswith(join("lib-dynload", "readline.so"))
                    )
                ):
                    dst_filename = join(
                        dst_prefix, "lib", "python%s" % sys.version[:3], "readline.so"
                    )
                elif modname == "readline" and sys.platform == "win32":
                    # special-case for Windows, where readline is not a
                    # standard module, though it may have been installed in
                    # site-packages by a third-party package
                    pass
                else:
                    dst_filename = change_prefix(filename, dst_prefix)
                copyfile(filename, dst_filename, symlink)
                if filename.endswith(".pyc"):
                    pyfile = filename[:-1]
                    if os.path.exists(pyfile):
                        copyfile(pyfile, dst_filename[:-1], symlink)
    finally:
        sys.path = _prev_sys_path