Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging error when checking for new version of pip. #11309

Closed
1 task done
domdfcoding opened this issue Jul 26, 2022 · 3 comments · Fixed by #11318
Closed
1 task done

Logging error when checking for new version of pip. #11309

domdfcoding opened this issue Jul 26, 2022 · 3 comments · Fixed by #11318
Labels
state: awaiting PR Feature discussed, PR is needed type: bug A confirmed bug or unintended behavior

Comments

@domdfcoding
Copy link
Contributor

Description

When pip (22.1.2) checked for a new version it failed with an error. It's coming from the following function:

def get_best_invocation_for_this_pip() -> str:
"""Try to figure out the best way to invoke pip in the current environment."""
binary_directory = "Scripts" if WINDOWS else "bin"
binary_prefix = os.path.join(sys.prefix, binary_directory)
# Try to use pip[X[.Y]] names, if those executables for this environment are
# the first on PATH with that name.
path_parts = os.path.normcase(os.environ.get("PATH", "")).split(os.pathsep)
exe_are_in_PATH = os.path.normcase(binary_prefix) in path_parts
if exe_are_in_PATH:
for exe_name in _EXECUTABLE_NAMES:
found_executable = shutil.which(exe_name)
if found_executable and os.path.samefile(
found_executable,
os.path.join(binary_prefix, exe_name),
):
return exe_name

The problem call is to os.path.samefile on line 58, where it compares the output of shutil.which('pip') to <sys.prefix>/bin/pip (in my case /usr/bin/pip). However, on my system, pip is installed to the user site-packages directory (so the binary is at /home/domdf/.local/bin/pip).

The solution is to check whether the file exists before calling samefile.

I have Python 3.7 and 3.9 installed to /usr alongside the system's Python 3.8, and the error is present with all three versions.

Expected behavior

Pip checks for a new version without an error.

pip version

22.1.2

Python version

3.9.13

OS

Ubuntu 20.04

How to Reproduce

  1. pip install pip==22.1.2
  2. pip install pip <- Any package will do.

Output

$ pip install pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in ./.local/lib/python3.9/site-packages (22.1.2)
--- Logging error ---
Traceback (most recent call last):
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_internal/utils/logging.py", line 177, in emit
    self.console.print(renderable, overflow="ignore", crop=False, style=style)
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_vendor/rich/console.py", line 1752, in print
    extend(render(renderable, render_options))
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_vendor/rich/console.py", line 1390, in render
    for render_output in iter_render:
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_internal/utils/logging.py", line 134, in __rich_console__
    for line in lines:
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_vendor/rich/segment.py", line 245, in split_lines
    for segment in segments:
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_vendor/rich/console.py", line 1368, in render
    renderable = rich_cast(renderable)
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_vendor/rich/protocol.py", line 36, in rich_cast
    renderable = cast_method()
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_internal/self_outdated_check.py", line 130, in __rich__
    pip_cmd = get_best_invocation_for_this_pip()
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_internal/utils/entrypoints.py", line 58, in get_best_invocation_for_this_pip
    if found_executable and os.path.samefile(
  File "/usr/lib/python3.9/genericpath.py", line 101, in samefile
    s2 = os.stat(f2)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/pip'
Call stack:
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/__main__.py", line 31, in <module>
    sys.exit(_main())
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_internal/cli/main.py", line 70, in main
    return command.main(cmd_args)
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 101, in main
    return self._main(args)
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 223, in _main
    self.handle_pip_version_check(options)
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 148, in handle_pip_version_check
    pip_self_version_check(session, options)
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_internal/self_outdated_check.py", line 237, in pip_self_version_check
    logger.info("[present-rich] %s", upgrade_prompt)
  File "/usr/lib/python3.9/logging/__init__.py", line 1446, in info
    self._log(INFO, msg, args, **kwargs)
  File "/usr/lib/python3.9/logging/__init__.py", line 1589, in _log
    self.handle(record)
  File "/usr/lib/python3.9/logging/__init__.py", line 1599, in handle
    self.callHandlers(record)
  File "/usr/lib/python3.9/logging/__init__.py", line 1661, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python3.9/logging/__init__.py", line 952, in handle
    self.emit(record)
  File "/home/domdf/.local/lib/python3.9/site-packages/pip/_internal/utils/logging.py", line 179, in emit
    self.handleError(record)
Message: '[present-rich] %s'
Arguments: (UpgradePrompt(old='22.1.2', new='22.2'),)

Code of Conduct

@domdfcoding domdfcoding added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Jul 26, 2022
@nckturner
Copy link

nckturner commented Jul 27, 2022

Looks like I have the exact same issue.

$ pip3 install --user boto3 awscli

...redacted...

--- Logging error ---
Traceback (most recent call last):
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_internal/utils/logging.py", line 177, in emit
    self.console.print(renderable, overflow="ignore", crop=False, style=style)
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_vendor/rich/console.py", line 1752, in print
    extend(render(renderable, render_options))
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_vendor/rich/console.py", line 1390, in render
    for render_output in iter_render:
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_internal/utils/logging.py", line 134, in __rich_console__
    for line in lines:
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_vendor/rich/segment.py", line 245, in split_lines
    for segment in segments:
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_vendor/rich/console.py", line 1368, in render
    renderable = rich_cast(renderable)
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_vendor/rich/protocol.py", line 36, in rich_cast
    renderable = cast_method()
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_internal/self_outdated_check.py", line 130, in __rich__
    pip_cmd = get_best_invocation_for_this_pip()
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_internal/utils/entrypoints.py", line 58, in get_best_invocation_for_this_pip
    if found_executable and os.path.samefile(
  File "/usr/lib/python3.9/genericpath.py", line 101, in samefile
    s2 = os.stat(f2)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/pip3.9'
Call stack:
  File "/home/nic/.local/bin/pip3", line 8, in <module>
    sys.exit(main())
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_internal/cli/main.py", line 70, in main
    return command.main(cmd_args)
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 101, in main
    return self._main(args)
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 223, in _main
    self.handle_pip_version_check(options)
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 148, in handle_pip_version_check
    pip_self_version_check(session, options)
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_internal/self_outdated_check.py", line 237, in pip_self_version_check
    logger.info("[present-rich] %s", upgrade_prompt)
  File "/usr/lib/python3.9/logging/__init__.py", line 1446, in info
    self._log(INFO, msg, args, **kwargs)
  File "/usr/lib/python3.9/logging/__init__.py", line 1589, in _log
    self.handle(record)
  File "/usr/lib/python3.9/logging/__init__.py", line 1599, in handle
    self.callHandlers(record)
  File "/usr/lib/python3.9/logging/__init__.py", line 1661, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python3.9/logging/__init__.py", line 952, in handle
    self.emit(record)
  File "/home/nic/.local/lib/python3.9/site-packages/pip/_internal/utils/logging.py", line 179, in emit
    self.handleError(record)
Message: '[present-rich] %s'
Arguments: (UpgradePrompt(old='22.1.2', new='22.2.1'),)

@pradyunsg
Copy link
Member

A PR fixing this would be welcome!

@pradyunsg pradyunsg added state: awaiting PR Feature discussed, PR is needed and removed S: needs triage Issues/PRs that need to be triaged labels Jul 27, 2022
@timbrown5
Copy link

As a workaround, you can set pip config set global.disable-pip-version-check true to disable the version check when running pip:
https://stackoverflow.com/questions/46288847/how-to-suppress-pip-upgrade-warning

nmb-paperspace added a commit to zzweig/tensorflow2-graphcore that referenced this issue Aug 4, 2022
 - Add pip install --update pip to avoid logging issue in pip 22.x (pypa/pip#11309 (comment))
 - Add text re Paperspace requirements for consistency with other notebook content
 - Remove reference to Graphcore Bow-IPU under "Build training dataset generator", reference IPU-POD16 (note this assumes the notes about throughput remain true)
nmb-paperspace added a commit to gradient-ai/Graphcore-HuggingFace that referenced this issue Aug 10, 2022
We are using Graphcore's containers with Ubuntu 20.04 and a startup command that includes `PIP_DISABLE_PIP_VERSION_CHECK=1` (pypa/pip#11309 (comment)).

Removing `pip install --upgrade pip` fixes it to 22.2.2, which works correctly, and gives us consistent usage across the notebooks presented.
nmb-paperspace added a commit to gradient-ai/Graphcore-Pytorch that referenced this issue Aug 10, 2022
We are using Graphcore's containers with Ubuntu 20.04 and a startup command that includes `PIP_DISABLE_PIP_VERSION_CHECK=1` (pypa/pip#11309 (comment)).

Removing `pip install --upgrade pip` fixes it to 22.2.2, which works correctly, and gives us consistent usage across the notebooks presented.
nmb-paperspace added a commit to gradient-ai/Graphcore-Tensorflow2 that referenced this issue Aug 10, 2022
We are using Graphcore's containers with Ubuntu 20.04 and a startup command that includes `PIP_DISABLE_PIP_VERSION_CHECK=1` (pypa/pip#11309 (comment)).

Removing `pip install --upgrade pip` fixes it to 22.2.2, which works correctly, and gives us consistent usage across the notebooks presented.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
state: awaiting PR Feature discussed, PR is needed type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants