# Buggy code
def choose_for(self, package):  # type: (Package) -> Link
    """
    Return the url of the selected archive for a given package.
    """
    links = []
    for link in self._get_links(package):
        if link.is_wheel and not Wheel(link.filename).is_supported_by_environment(
            self._env
        ):
            continue

        if link.ext == ".egg":
            continue

        links.append(link)

    if not links:
        raise RuntimeError(
            "Unable to find installation candidates for {}".format(package)
        )

    # Get the best link
    chosen = max(links, key=lambda link: self._sort_key(package, link))
    if not chosen:
        raise RuntimeError(
            "Unable to find installation candidates for {}".format(package)
        )

    return chosen


# Traceback (UnicodeDecodeError)
$ poetry install -vvv
Using virtualenv: C:\Users\John Smith\AppData\Local\pypoetry\Cache\virtualenvs\dge-bot-jrDf5u8l-py3.7
Installing dependencies from lock file

Finding the necessary packages for the current system

Package operations: 1 install, 0 updates, 0 removals, 168 skipped

• Removing uvloop (0.14.0): Skipped for the following reason: Not currently installed
• Installing idna (2.10): Skipped for the following reason: Already installed
• Installing multidict (4.7.6): Skipped for the following reason: Already installed
• Installing typing-extensions (3.7.4.3): Skipped for the following reason: Already installed
• Installing async-timeout (3.0.1): Skipped for the following reason: Already installed
• Installing attrs (19.3.0): Skipped for the following reason: Already installed
• Installing certifi (2020.6.20): Skipped for the following reason: Already installed
• Installing chardet (3.0.4): Skipped for the following reason: Already installed
• Installing hpack (3.0.0): Skipped for the following reason: Already installed
• Installing hyperframe (5.2.0): Skipped for the following reason: Already installed
• Installing pyasn1 (0.4.8): Skipped for the following reason: Already installed
• Installing urllib3 (1.25.10): Skipped for the following reason: Already installed
• Installing yarl (1.6.0): Skipped for the following reason: Already installed
• Installing aiohttp (3.6.2): Skipped for the following reason: Already installed
• Installing h11 (0.8.1): Skipped for the following reason: Already installed
• Installing h2 (3.2.0): Skipped for the following reason: Already installed
• Installing pyasn1-modules (0.2.8): Skipped for the following reason: Already installed
• Installing requests (2.24.0): Skipped for the following reason: Already installed
• Installing six (1.15.0): Skipped for the following reason: Already installed
• Installing sniffio (1.1.0): Skipped for the following reason: Already installed
• Installing rfc3986 (1.4.0): Skipped for the following reason: Already installed
• Installing zipp (3.2.0): Skipped for the following reason: Already installed
• Installing cachetools (4.1.1): Skipped for the following reason: Already installed
• Installing hstspreload (2020.9.29): Skipped for the following reason: Already installed
• Installing oauthlib (3.1.0): Skipped for the following reason: Already installed
• Installing rsa (4.6): Skipped for the following reason: Already installed
• Installing aiofiles (0.5.0): Skipped for the following reason: Already installed
• Installing google-auth (1.22.0): Skipped for the following reason: Already installed
• Installing httpx (0.9.3): Skipped for the following reason: Already installed
• Installing requests-oauthlib (1.3.0): Skipped for the following reason: Already installed
• Installing websockets (8.1): Skipped for the following reason: Already installed
• Installing httptools (0.1.1): Skipped for the following reason: Already installed
• Installing importlib-metadata (2.0.0): Skipped for the following reason: Already installed
• Installing numpy (1.19.2): Skipped for the following reason: Already installed
• Installing absl-py (0.9.0): Skipped for the following reason: Already installed
• Installing google-auth-oauthlib (0.4.1): Skipped for the following reason: Already installed
• Installing h5py (2.10.0): Skipped for the following reason: Already installed
• Installing markdown (3.2.2): Skipped for the following reason: Already installed
• Installing pycparser (2.20): Skipped for the following reason: Already installed
• Installing python-dateutil (2.8.1): Skipped for the following reason: Already installed
• Installing werkzeug (1.0.1): Skipped for the following reason: Already installed
• Installing grpcio (1.32.0): Skipped for the following reason: Already installed
• Installing jmespath (0.10.0): Skipped for the following reason: Already installed
• Installing protobuf (3.13.0): Skipped for the following reason: Already installed
• Installing pyreadline (2.1): Failed

Stack trace:

7  c:\users\john smith\appdata\local\programs\python\python37\lib\site-packages\poetry\installation\executor.py:180 in _execute_operation
178│
179│             try:
→ 180│                 result = self._do_execute_operation(operation)
181│             except EnvCommandError as e:
182│                 if e.e.returncode == -2:

6  c:\users\john smith\appdata\local\programs\python\python37\lib\site-packages\poetry\installation\executor.py:254 in _do_execute_operation
252│             return 0
253│
→ 254│         result = getattr(self, "_execute_{}".format(method))(operation)
255│
256│         if result != 0:

5  c:\users\john smith\appdata\local\programs\python\python37\lib\site-packages\poetry\installation\executor.py:389 in _execute_install
387│
388│     def _execute_install(self, operation):  # type: (Install) -> None
→ 389│         return self._install(operation)
390│
391│     def _execute_update(self, operation):  # type: (Update) -> None

4  c:\users\john smith\appdata\local\programs\python\python37\lib\site-packages\poetry\installation\executor.py:427 in _install
425│             args.insert(2, "-U")
426│
→ 427│         return self.run_pip(*args)
428│
429│     def _update(self, operation):

3  c:\users\john smith\appdata\local\programs\python\python37\lib\site-packages\poetry\installation\executor.py:278 in run_pip
276│     def run_pip(self, *args, **kwargs):  # type: (...) -> int
277│         try:
→ 278│             self._env.run_pip(*args, **kwargs)
279│         except EnvCommandError as e:
280│             output = decode(e.e.output)

2  c:\users\john smith\appdata\local\programs\python\python37\lib\site-packages\poetry\utils\env.py:916 in run_pip
914│         pip = self.get_pip_command()
915│         cmd = pip + list(args)
→  916│         return self._run(cmd, **kwargs)
917│
918│     def _run(self, cmd, **kwargs):

1  c:\users\john smith\appdata\local\programs\python\python37\lib\site-packages\poetry\utils\env.py:1189 in _run
1187│             self.unset_env("__PYVENV_LAUNCHER__")
1188│
→ 1189│             return super(VirtualEnv, self)._run(cmd, **kwargs)
1190│
1191│     def execute(self, bin, *args, **kwargs):

EnvCommandError

Command "C:\Users\John Smith\AppData\Local\pypoetry\Cache\virtualenvs\dge-bot-jrDf5u8l-py3.7\Scripts\pip.exe" install --no-deps "C:\Users\John Smith\AppData\Local\pypoetry\Cache\artifacts\40\b7\a1\08d80a4ee91ede614be15e9ad0add0d8f7c093a6d2f75c2b1e5239c365\pyreadline-2.1.win32.exe" errored with the following return code 2, and output:
ERROR: Exception:
Traceback (most recent call last):
File "c:\users\john smith\appdata\local\pypoetry\cache\virtualenvs\dge-bot-jrdf5u8l-py3.7\lib\site-packages\pip\_vendor\packaging\requirements.py", line 98, in __init__
req = REQUIREMENT.parseString(requirement_string)
File "c:\users\john smith\appdata\local\pypoetry\cache\virtualenvs\dge-bot-jrdf5u8l-py3.7\lib\site-packages\pip\_vendor\pyparsing.py", line 1955, in parseString
raise exc
File "c:\users\john smith\appdata\local\pypoetry\cache\virtualenvs\dge-bot-jrdf5u8l-py3.7\lib\site-packages\pip\_vendor\pyparsing.py", line 3814, in parseImpl
raise ParseException(instring, loc, self.errmsg, self)
pip._vendor.pyparsing.ParseException: Expected stringEnd, found ':'  (at char 1), (line:1, col:2)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\john smith\appdata\local\pypoetry\cache\virtualenvs\dge-bot-jrdf5u8l-py3.7\lib\site-packages\pip\_internal\req\constructors.py", line 359, in parse_req_from_line
req = Requirement(req_as_string)
File "c:\users\john smith\appdata\local\pypoetry\cache\virtualenvs\dge-bot-jrdf5u8l-py3.7\lib\site-packages\pip\_vendor\packaging\requirements.py", line 102, in __init__
requirement_string[e.loc : e.loc + 8], e.msg
pip._vendor.packaging.requirements.InvalidRequirement: Parse error at "':\\Users\\'": Expected stringEnd

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\john smith\appdata\local\pypoetry\cache\virtualenvs\dge-bot-jrdf5u8l-py3.7\lib\site-packages\pip\_internal\cli\base_command.py", line 228, in _main
status = self.run(options, args)
File "c:\users\john smith\appdata\local\pypoetry\cache\virtualenvs\dge-bot-jrdf5u8l-py3.7\lib\site-packages\pip\_internal\cli\req_command.py", line 182, in wrapper
return func(self, options, args)
File "c:\users\john smith\appdata\local\pypoetry\cache\virtualenvs\dge-bot-jrdf5u8l-py3.7\lib\site-packages\pip\_internal\commands\install.py", line 294, in run
reqs = self.get_requirements(args, options, finder, session)
File "c:\users\john smith\appdata\local\pypoetry\cache\virtualenvs\dge-bot-jrdf5u8l-py3.7\lib\site-packages\pip\_internal\cli\req_command.py", line 319, in get_requirements
user_supplied=True,
File "c:\users\john smith\appdata\local\pypoetry\cache\virtualenvs\dge-bot-jrdf5u8l-py3.7\lib\site-packages\pip\_internal\req\constructors.py", line 409, in install_req_from_line
parts = parse_req_from_line(name, line_source)
File "c:\users\john smith\appdata\local\pypoetry\cache\virtualenvs\dge-bot-jrdf5u8l-py3.7\lib\site-packages\pip\_internal\req\constructors.py", line 363, in parse_req_from_line
add_msg += deduce_helpful_msg(req_as_string)
File "c:\users\john smith\appdata\local\pypoetry\cache\virtualenvs\dge-bot-jrdf5u8l-py3.7\lib\site-packages\pip\_internal\req\constructors.py", line 167, in deduce_helpful_msg
next(parse_requirements(fp.read()))
File "c:\users\john smith\appdata\local\programs\python\python37\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 2: character maps to <undefined>


at c:\users\john smith\appdata\local\programs\python\python37\lib\site-packages\poetry\utils\env.py:948 in _run
944│                 output = subprocess.check_output(
945│                     cmd, stderr=subprocess.STDOUT, **kwargs
946│                 )
947│         except CalledProcessError as e:
→  948│             raise EnvCommandError(e, input=input_)
949│
950│         return decode(output)
951│
952│     def execute(self, bin, *args, **kwargs):

# Fixed code
def choose_for(self, package):  # type: (Package) -> Link
    """
    Return the url of the selected archive for a given package.
    """
    links = []
    for link in self._get_links(package):
        if link.is_wheel and not Wheel(link.filename).is_supported_by_environment(
            self._env
        ):
            continue

        if link.ext in {".egg", ".exe", ".msi", ".rpm", ".srpm"}:
            continue

        links.append(link)

    if not links:
        raise RuntimeError(
            "Unable to find installation candidates for {}".format(package)
        )

    # Get the best link
    chosen = max(links, key=lambda link: self._sort_key(package, link))
    if not chosen:
        raise RuntimeError(
            "Unable to find installation candidates for {}".format(package)
        )

    return chosen