import pip

exceptions = ['pip', 'setuptools', 'wheel']

def diff(requirements, installed):
    """
    Calculate which modules should be installed or uninstalled,
    given a set of requirements and a list of installed modules.
    """

    requirements = { r.req.key: r for r in requirements }

    to_be_installed = set()
    to_be_uninstalled = set()

    satisfied = set()

    for module in installed:
        key = module.key

        if key in exceptions:
            pass
        elif key not in requirements:
            to_be_uninstalled.add(module.as_requirement())
        elif module.version in requirements[key].specifier:
            satisfied.add(key)

    for key, requirement in requirements.items():
        if key not in satisfied:
            to_be_installed.add(requirement.req)

    return (to_be_installed, to_be_uninstalled)


def sync(to_be_installed, to_be_uninstalled, verbose=False):
    """
    Install and uninstalls the given sets of modules.
    """

    flags = []

    if not verbose:
        flags.append('-q')

    if to_be_uninstalled:
        pip.main(["uninstall", '-y'] + flags + [str(req) for req in to_be_uninstalled])

    if to_be_installed:
        pip.main(["install"] + flags + [str(req) for req in to_be_installed])

@@ -588,26 +588,8 @@
 lif 
-module.version in 
 requ
@@ -611,16 +611,41 @@
 pecifier
+.contains(module.version)
 :%0A      

Make pip-sync work in pip < 7.0.0