# Buggy code
def pip_install(
    package_name=None,
    r=None,
    allow_global=False,
    ignore_hashes=False,
    no_deps=True,
    verbose=False,
    block=True,
    index=None,
    pre=False,
    selective_upgrade=False,
    requirements_dir=None,
    extra_indexes=None,
    pypi_mirror=None,
):
    from notpip._internal import logger as piplogger
    from notpip._vendor.pyparsing import ParseException
    from .vendor.requirementslib import Requirement

    if verbose:
        click.echo(
            crayons.normal("Installing {0!r}".format(package_name), bold=True), err=True
        )
        piplogger.setLevel(logging.INFO)
    # Create files for hash mode.
    if not package_name.startswith("-e ") and (not ignore_hashes) and (r is None):
        fd, r = tempfile.mkstemp(
            prefix="pipenv-", suffix="-requirement.txt", dir=requirements_dir
        )
        with os.fdopen(fd, "w") as f:
            f.write(package_name)
    # Install dependencies when a package is a VCS dependency.
    try:
        req = Requirement.from_line(
            package_name.split("--hash")[0].split("--trusted-host")[0]
        ).vcs
    except (ParseException, ValueError) as e:
        click.echo("{0}: {1}".format(crayons.red("WARNING"), e), err=True)
        click.echo(
            "{0}… You will have to reinstall any packages that failed to install.".format(
                crayons.red("ABORTING INSTALL")
            ),
            err=True,
        )
        click.echo(
            "You may have to manually run {0} when you are finished.".format(
                crayons.normal("pipenv lock", bold=True)
            )
        )
        sys.exit(1)
    if req:
        no_deps = False
        # Don't specify a source directory when using --system.
        if not allow_global and ("PIP_SRC" not in os.environ):
            src = "--src {0}".format(
                escape_grouped_arguments(project.virtualenv_src_location)
            )
        else:
            src = ""
    else:
        src = ""

    # Try installing for each source in project.sources.
    if index:
        if not is_valid_url(index):
            index = project.find_source(index).get("url")
        sources = [{"url": index}]
        if extra_indexes:
            if isinstance(extra_indexes, six.string_types):
                extra_indexes = [extra_indexes]
            for idx in extra_indexes:
                try:
                    extra_src = project.find_source(idx).get("url")
                except SourceNotFound:
                    extra_src = idx
                if extra_src != index:
                    sources.append({"url": extra_src})
        else:
            for idx in project.pipfile_sources:
                if idx["url"] != sources[0]["url"]:
                    sources.append({"url": idx["url"]})
    else:
        sources = project.pipfile_sources
    if pypi_mirror:
        sources = [
            create_mirror_source(pypi_mirror) if is_pypi_url(source["url"]) else source
            for source in sources
        ]
    if package_name.startswith("-e "):
        install_reqs = ' -e "{0}"'.format(package_name.split("-e ")[1])
    elif r:
        install_reqs = " -r {0}".format(escape_grouped_arguments(r))
    else:
        install_reqs = ' "{0}"'.format(package_name)
    # Skip hash-checking mode, when appropriate.
    if r:
        with open(r) as f:
            if "--hash" not in f.read():
                ignore_hashes = True
    else:
        if "--hash" not in install_reqs:
            ignore_hashes = True
    verbose_flag = "--verbose" if verbose else ""
    if not ignore_hashes:
        install_reqs += " --require-hashes"
    no_deps = "--no-deps" if no_deps else ""
    pre = "--pre" if pre else ""
    quoted_pip = which_pip(allow_global=allow_global)
    quoted_pip = escape_grouped_arguments(quoted_pip)
    upgrade_strategy = (
        "--upgrade --upgrade-strategy=only-if-needed" if selective_upgrade else ""
    )
    pip_command = "{0} install {4} {5} {6} {7} {3} {1} {2} --exists-action w".format(
        quoted_pip,
        install_reqs,
        " ".join(prepare_pip_source_args(sources)),
        no_deps,
        pre,
        src,
        verbose_flag,
        upgrade_strategy,
    )
    if verbose:
        click.echo("$ {0}".format(pip_command), err=True)
    cache_dir = Path(PIPENV_CACHE_DIR)
    pip_config = {
        "PIP_CACHE_DIR": fs_str(cache_dir.as_posix()),
        "PIP_WHEEL_DIR": fs_str(cache_dir.joinpath("wheels").as_posix()),
        "PIP_DESTINATION_DIR": fs_str(cache_dir.joinpath("pkgs").as_posix()),
    }
    c = delegator.run(pip_command, block=block, env=pip_config)
    return c


# Traceback (IOError)
mani@host:~/code/ReportCreator(hotfix/v2.6.3)$pipenv install -e "." -v
Installing -e .…
⠋Installing '-e .'
$ "/home/mani/.local/share/virtualenvs/ReportCreator-PmaoAZkd/bin/pip" install   --verbose    -e "." -i https://pypi.org/simple --extra-index-url ${PIP_EXTRA_INDEX_URL} --exists-action w
Created temporary directory: /tmp/pip-ephem-wheel-cache-xspLxQ
Created temporary directory: /tmp/pip-install-RJPkTE
Looking in indexes: https://pypi.org/simple, https://my.private.pypi.io/secret/index/, --exists-action
Obtaining file:///home/mani/code/ReportCreator
Running setup.py (path:/home/mani/code/ReportCreator/setup.py) egg_info for package from file:///home/mani/code/ReportCreator
Running command python setup.py egg_info
running egg_info
writing requirements to abcreporter.egg-info/requires.txt
writing abcreporter.egg-info/PKG-INFO
writing top-level names to abcreporter.egg-info/top_level.txt
writing dependency_links to abcreporter.egg-info/dependency_links.txt
reading manifest file 'abcreporter.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'abcreporter.egg-info/SOURCES.txt'
Source in /home/mani/code/ReportCreator has version 2.6.3, which satisfies requirement abcreporter==2.6.3 from file:///home/mani/code/ReportCreator
Collecting w
2 location(s) to search for versions of w:
* https://pypi.org/simple/w/
* https://my.private.pypi.io/secret/index/w/
Getting page https://pypi.org/simple/w/
Looking up "https://pypi.org/simple/w/" in the cache
Current age based on date: 1055
Freshness lifetime from max-age: 600
Freshness lifetime from request max-age: 600
Starting new HTTPS connection (1): pypi.org
https://pypi.org:443 "GET /simple/w/ HTTP/1.1" 304 0
Analyzing links from page https://pypi.org/simple/w/
Found link https://files.pythonhosted.org/packages/0d/6f/613f18ccb1fc24d007b72c8215bcf49c445adb720a9d1621ccdf86cf9265/w-0.11.1.tar.gz#sha256=3c9f0bcea99476294aa87092cb6c71a98538a8b1a55203be586378a02394821b (from https://pypi.org/simple/w/), version: 0.11.1
Getting page https://my.private.pypi.io/secret/index/w/
Looking up "https://my.private.pypi.io/secret/index/w/" in the cache
No cache entry available
Starting new HTTPS connection (1): dl.cloudsmith.io
https://dl.cloudsmith.io:443 "GET /my.private.pypi.io/secret/index/w/ HTTP/1.1" 404 None
Status code 404 not in (200, 203, 300, 301)
Could not fetch URL https://my.private.pypi.io/secret/index/w/: 404 Client Error: Not Found for url: https://my.private.pypi.io/secret/index/w/ - skipping
Using version 0.11.1 (newest of versions: 0.11.1)
Created temporary directory: /tmp/pip-unpack-bDSjkY
Looking up "https://files.pythonhosted.org/packages/0d/6f/613f18ccb1fc24d007b72c8215bcf49c445adb720a9d1621ccdf86cf9265/w-0.11.1.tar.gz" in the cache
Ignoring unknown cache-control directive:
Current age based on date: 6901
Ignoring unknown cache-control directive: immutable
Freshness lifetime from max-age: 365000000
The response is "fresh", returning cached response
365000000 > 6901
Using cached https://files.pythonhosted.org/packages/0d/6f/613f18ccb1fc24d007b72c8215bcf49c445adb720a9d1621ccdf86cf9265/w-0.11.1.tar.gz
Downloading from URL https://files.pythonhosted.org/packages/0d/6f/613f18ccb1fc24d007b72c8215bcf49c445adb720a9d1621ccdf86cf9265/w-0.11.1.tar.gz#sha256=3c9f0bcea99476294aa87092cb6c71a98538a8b1a55203be586378a02394821b (from https://pypi.org/simple/w/)
Running setup.py (path:/tmp/pip-install-RJPkTE/w/setup.py) egg_info for package w
Running command python setup.py egg_info
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-RJPkTE/w/setup.py", line 27, in <module>
with open('requirements.txt') as f:
IOError: [Errno 2] No such file or directory: 'requirements.txt'
Cleaning up...
Removing source in /tmp/pip-install-RJPkTE/w
Exception information:
Traceback (most recent call last):
File "/home/mani/.local/share/virtualenvs/ReportCreator-PmaoAZkd/local/lib/python2.7/site-packages/pip/_internal/basecommand.py", line 228, in main
status = self.run(options, args)
File "/home/mani/.local/share/virtualenvs/ReportCreator-PmaoAZkd/local/lib/python2.7/site-packages/pip/_internal/commands/install.py", line 291, in run
resolver.resolve(requirement_set)
File "/home/mani/.local/share/virtualenvs/ReportCreator-PmaoAZkd/local/lib/python2.7/site-packages/pip/_internal/resolve.py", line 103, in resolve
self._resolve_one(requirement_set, req)
File "/home/mani/.local/share/virtualenvs/ReportCreator-PmaoAZkd/local/lib/python2.7/site-packages/pip/_internal/resolve.py", line 257, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/home/mani/.local/share/virtualenvs/ReportCreator-PmaoAZkd/local/lib/python2.7/site-packages/pip/_internal/resolve.py", line 210, in _get_abstract_dist_for
self.require_hashes
File "/home/mani/.local/share/virtualenvs/ReportCreator-PmaoAZkd/local/lib/python2.7/site-packages/pip/_internal/operations/prepare.py", line 324, in prepare_linked_requirement
abstract_dist.prep_for_dist(finder, self.build_isolation)
File "/home/mani/.local/share/virtualenvs/ReportCreator-PmaoAZkd/local/lib/python2.7/site-packages/pip/_internal/operations/prepare.py", line 154, in prep_for_dist
self.req.run_egg_info()
File "/home/mani/.local/share/virtualenvs/ReportCreator-PmaoAZkd/local/lib/python2.7/site-packages/pip/_internal/req/req_install.py", line 486, in run_egg_info
command_desc='python setup.py egg_info')
File "/home/mani/.local/share/virtualenvs/ReportCreator-PmaoAZkd/local/lib/python2.7/site-packages/pip/_internal/utils/misc.py", line 698, in call_subprocess
% (command_desc, proc.returncode, cwd))
InstallationError: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-RJPkTE/w/

Error:  An error occurred while installing -e .!
Url '--exists-action/w/' is ignored. It is either a non-existing path or lacks a specific scheme.
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-RJPkTE/w/

This is likely caused by a bug in -e .. Report this to its maintainers.

# Fixed code
def pip_install(
    package_name=None,
    r=None,
    allow_global=False,
    ignore_hashes=False,
    no_deps=True,
    verbose=False,
    block=True,
    index=None,
    pre=False,
    selective_upgrade=False,
    requirements_dir=None,
    extra_indexes=None,
    pypi_mirror=None,
):
    from notpip._internal import logger as piplogger
    from notpip._vendor.pyparsing import ParseException
    from .vendor.requirementslib import Requirement

    if verbose:
        click.echo(
            crayons.normal("Installing {0!r}".format(package_name), bold=True), err=True
        )
        piplogger.setLevel(logging.INFO)
    # Create files for hash mode.
    if not package_name.startswith("-e ") and (not ignore_hashes) and (r is None):
        fd, r = tempfile.mkstemp(
            prefix="pipenv-", suffix="-requirement.txt", dir=requirements_dir
        )
        with os.fdopen(fd, "w") as f:
            f.write(package_name)
    # Install dependencies when a package is a VCS dependency.
    try:
        req = Requirement.from_line(
            package_name.split("--hash")[0].split("--trusted-host")[0]
        ).vcs
    except (ParseException, ValueError) as e:
        click.echo("{0}: {1}".format(crayons.red("WARNING"), e), err=True)
        click.echo(
            "{0}… You will have to reinstall any packages that failed to install.".format(
                crayons.red("ABORTING INSTALL")
            ),
            err=True,
        )
        click.echo(
            "You may have to manually run {0} when you are finished.".format(
                crayons.normal("pipenv lock", bold=True)
            )
        )
        sys.exit(1)
    if req:
        no_deps = False
        # Don't specify a source directory when using --system.
        if not allow_global and ("PIP_SRC" not in os.environ):
            src = "--src {0}".format(
                escape_grouped_arguments(project.virtualenv_src_location)
            )
        else:
            src = ""
    else:
        src = ""

    # Try installing for each source in project.sources.
    if index:
        if not is_valid_url(index):
            index = project.find_source(index).get("url")
        sources = [{"url": index}]
        if extra_indexes:
            if isinstance(extra_indexes, six.string_types):
                extra_indexes = [extra_indexes]
            for idx in extra_indexes:
                try:
                    extra_src = project.find_source(idx).get("url")
                except SourceNotFound:
                    extra_src = idx
                if extra_src != index:
                    sources.append({"url": extra_src})
        else:
            for idx in project.pipfile_sources:
                if idx["url"] != sources[0]["url"]:
                    sources.append({"url": idx["url"]})
    else:
        sources = project.pipfile_sources
    if pypi_mirror:
        sources = [
            create_mirror_source(pypi_mirror) if is_pypi_url(source["url"]) else source
            for source in sources
        ]
    if package_name.startswith("-e "):
        install_reqs = ' -e "{0}"'.format(package_name.split("-e ")[1])
    elif r:
        install_reqs = " -r {0}".format(escape_grouped_arguments(r))
    else:
        install_reqs = ' "{0}"'.format(package_name)
    # Skip hash-checking mode, when appropriate.
    if r:
        with open(r) as f:
            if "--hash" not in f.read():
                ignore_hashes = True
    else:
        if "--hash" not in install_reqs:
            ignore_hashes = True
    verbose_flag = "--verbose" if verbose else ""
    if not ignore_hashes:
        install_reqs += " --require-hashes"
    no_deps = "--no-deps" if no_deps else ""
    pre = "--pre" if pre else ""
    quoted_pip = which_pip(allow_global=allow_global)
    quoted_pip = escape_grouped_arguments(quoted_pip)
    upgrade_strategy = (
        "--upgrade --upgrade-strategy=only-if-needed" if selective_upgrade else ""
    )
    pip_command = "{0} install {4} {5} {6} {7} --exists-action w {3} {1} {2}".format(
        quoted_pip,
        install_reqs,
        " ".join(prepare_pip_source_args(sources)),
        no_deps,
        pre,
        src,
        verbose_flag,
        upgrade_strategy,
    )
    if verbose:
        click.echo("$ {0}".format(pip_command), err=True)
    cache_dir = Path(PIPENV_CACHE_DIR)
    pip_config = {
        "PIP_CACHE_DIR": fs_str(cache_dir.as_posix()),
        "PIP_WHEEL_DIR": fs_str(cache_dir.joinpath("wheels").as_posix()),
        "PIP_DESTINATION_DIR": fs_str(cache_dir.joinpath("pkgs").as_posix()),
    }
    c = delegator.run(pip_command, block=block, env=pip_config)
    return c