cli icon indicating copy to clipboard operation
cli copied to clipboard

Can't install a plugin because cannot invoke pip

Open philipmw opened this issue 3 years ago • 1 comments

Checklist

  • [x] I've searched for similar issues.
  • [x] I'm using the latest version of HTTPie.

Minimal reproduction code and steps

  1. Run httpie --debug --traceback cli plugins install ~/any/local/path/that-may-not-even-exist

Current result

% httpie --debug --traceback cli plugins install ~/aaaaa
HTTPie 3.2.2
Requests 2.31.0
Pygments 2.16.1
Python 3.12.0 (main, Oct  2 2023, 12:03:24) [Clang 15.0.0 (clang-1500.0.40.1)]
/usr/local/Cellar/httpie/3.2.2_3/libexec/bin/python
Darwin 23.1.0

<Environment {'apply_warnings_filter': <function Environment.apply_warnings_filter at 0x1107f3c40>,
 'args': Namespace(),
 'as_silent': <function Environment.as_silent at 0x1107f3b00>,
 'colors': 256,
 'config': {'default_options': []},
 'config_dir': PosixPath('/Users/pmw/.config/httpie'),
 'devnull': <property object at 0x1107e9850>,
 'is_windows': False,
 'log_error': <function Environment.log_error at 0x1107f3ba0>,
 'program_name': 'httpie',
 'quiet': 0,
 'rich_console': <functools.cached_property object at 0x1107e3290>,
 'rich_error_console': <functools.cached_property object at 0x1107e32f0>,
 'show_displays': True,
 'stderr': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>,
 'stderr_isatty': True,
 'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
 'stdin_encoding': 'utf-8',
 'stdin_isatty': True,
 'stdout': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>,
 'stdout_encoding': 'utf-8',
 'stdout_isatty': True}>

<PluginManager {'adapters': [],
 'auth': [<class 'httpie.plugins.builtin.BasicAuthPlugin'>,
          <class 'httpie.plugins.builtin.DigestAuthPlugin'>,
          <class 'httpie.plugins.builtin.BearerAuthPlugin'>],
 'converters': [],
 'formatters': [<class 'httpie.output.formatters.headers.HeadersFormatter'>,
                <class 'httpie.output.formatters.json.JSONFormatter'>,
                <class 'httpie.output.formatters.xml.XMLFormatter'>,
                <class 'httpie.output.formatters.colors.ColorFormatter'>]}>
Installing /Users/pmw/aaaaa...
Command failed: pip install --prefer-binary --prefix=/Users/pmw/.config/httpie/plugins --no-warn-script-location /Users/pmw/aaaaa
  Can't install '/Users/pmw/aaaaa'

Me trying to debug the issue:

% pip
zsh: command not found: pip

Based on the HTTPie source code, it appears to be doing this:

% python3.12
Python 3.12.0 (main, Oct  2 2023, 12:03:24) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.which("pip")
>>> shutil.which("pip3")
'/usr/local/bin/pip3'
>>>

This works as expected.

Expected result

It finds pip3 (which does exist) and uses it.


Debug output

(already provided above)

philipmw avatar Nov 03 '23 21:11 philipmw

By looking at HTTPie code, this should not happen. I think that the bug is specific to your OS/configured path. Somehow fooling us.

This does not mean HTTPie cannot handle that rare case. In order for us to understand,

Please run the following script, untouched, and return the results here.

from __future__ import annotations

import shutil
import subprocess
from contextlib import suppress


def _discover_system_pip() -> str:
    def _check_pip_version(pip_location: str | None) -> bool:
        if not pip_location:
            print("D")
            return False

        with suppress(subprocess.CalledProcessError):
            stdout = subprocess.check_output([pip_location, "--version"], text=True)
            print(stdout)
            return "python 3" in stdout

    targets = [
        "pip",
        "pip3"
    ]

    for target in targets:
        print("A", target)
        pip_location = shutil.which(target)

        print("B", pip_location)

        if _check_pip_version(pip_location):
            print("C")
            return pip_location

    raise SystemError("Couldn't find 'pip' executable. Please ensure that pip in your system is available.")


if __name__ == "__main__":
    print("debug issue https://github.com/httpie/cli/issues/1539")

    print(_discover_system_pip())

Ousret avatar May 23 '24 04:05 Ousret