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

Warning "There was an error checking the latest version of pip" #12357

Closed
1 task done
jgbustos opened this issue Oct 15, 2023 · 24 comments
Closed
1 task done

Warning "There was an error checking the latest version of pip" #12357

jgbustos opened this issue Oct 15, 2023 · 24 comments
Labels
type: bug A confirmed bug or unintended behavior
Milestone

Comments

@jgbustos
Copy link

Description

Pip issues the warning message "WARNING: There was an error checking the latest version of pip" when running "pip list -o" on Python 3.10 running inside Windows 11.

If I run "pip list -o -vv", the following stack trace is generated:

See below for error
Traceback (most recent call last):
  File "C:\Development\Data_Science\Projects\semantic_qa\venv\lib\site-packages\pip\_internal\self_outdated_check.py", line 227, in pip_self_version_check
    upgrade_prompt = _self_version_check_logic(
  File "C:\Development\Data_Science\Projects\semantic_qa\venv\lib\site-packages\pip\_internal\self_outdated_check.py", line 188, in _self_version_check_logic
    remote_version_str = state.get(current_time)
  File "C:\Development\Data_Science\Projects\semantic_qa\venv\lib\site-packages\pip\_internal\self_outdated_check.py", line 76, in get
    last_check = datetime.datetime.fromisoformat(self._state["last_check"])
ValueError: Invalid isoformat string: '2023-10-12T09:17:22Z'

Might this be the underlying cause?
https://www.reddit.com/r/Python/comments/163ugsm/psa_as_of_python_311_datetimefromisoformat/

Expected behavior

No warning message appears

pip version

23.3

Python version

3.10

OS

Windows 11

How to Reproduce

  1. In Windows, create and activate a new virtualenv
  2. Upgrade pip to version 23.3 running "python.exe -m pip install pip==23.3"
  3. Run "pip list -o" and get the WARNING: There was an error checking the latest version of pip.
  4. Run "pip list -o -vv" and get the warning, plus the stack trace

Output

WARNING: There was an error checking the latest version of pip.
See below for error
Traceback (most recent call last):
  File "C:\Development\test_pip\venv\lib\site-packages\pip\_internal\self_outdated_check.py", line 227, in pip_self_version_check
    upgrade_prompt = _self_version_check_logic(
  File "C:\Development\test_pip\venv\lib\site-packages\pip\_internal\self_outdated_check.py", line 188, in _self_version_check_logic
    remote_version_str = state.get(current_time)
  File "C:\Development\test_pip\venv\lib\site-packages\pip\_internal\self_outdated_check.py", line 76, in get
    last_check = datetime.datetime.fromisoformat(self._state["last_check"])
ValueError: Invalid isoformat string: '2023-10-15T23:25:56Z'

Code of Conduct

@jgbustos jgbustos added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Oct 15, 2023
@sbidoul
Copy link
Member

sbidoul commented Oct 16, 2023

This is due to #12006 and was apparently discussed in the PR.

@sbidoul sbidoul added this to the 23.3 milestone Oct 16, 2023
@sbidoul
Copy link
Member

sbidoul commented Oct 16, 2023

I'm assigning this to 23.3 to keep track of it as an issue caused by the release. This does not mean I intent to do a patch release for this at this point.

@sbidoul
Copy link
Member

sbidoul commented Oct 16, 2023

Oh, it seems it was also reported in #12338 5 days ago. I had not noticed that one.

@jiayouzl
Copy link

I have this problem too!

@pradyunsg
Copy link
Member

Hi folks. Please don't add "me too" style comments here. If you are affected by this issue, add a 👍🏽 reaction to the first comment.

@notatallshaw
Copy link
Member

notatallshaw commented Oct 16, 2023

Another case this error happens but isn't described here is when you downgrade from 23.3 to 23.2.1.

Which I had to do today to test an issue I am facing today to see if it's the Pip upgrade or something else, and reading the PR it does look like I predicted this would be an issue.

@SoftologyPro
Copy link

Also, just a pedantic suggestion... If it is a warning, do not put "error" in the message.
I do some error detection when installing Python packages and the "error" text in the warning caused other issues.

@Arisukun
Copy link

Our team is also facing issues due to this, our CICD pipelines are failing. We have to downgrade pip for reasons but when we do, it throws that error message when we are using devops ubuntu agent.
Even when I tried to pin the version to 23.0.1 both in Devops agent and in our "requirements.txt" to install for our internal library, I faced this error message (which is strange as this approach worked when I tried it locally):
image

@sbidoul
Copy link
Member

sbidoul commented Oct 17, 2023

As a workaround, setting a PIP_DISABLE_PIP_VERSION_CHECK=1 environment variable may help.

@notatallshaw
Copy link
Member

As a workaround, setting a PIP_DISABLE_PIP_VERSION_CHECK=1 environment variable may help.

I would recommend in CI/CD pipelines anyway, the chance of this failing is non-zero and not useful when it does.

I think, although haven't checked specifically, the issue when you downgrade is the new datetime format is trying to be parsed by the old parsing logic. I believe running pip cache purge will delete the offending cached version but obviously cleans everything else, you can also go into the Pip cache directory and manually delete the JSON file.

@sbidoul
Copy link
Member

sbidoul commented Oct 17, 2023

This should now be fixed on main, thanks to #12363.

@Arisukun
Copy link

As a workaround, setting a PIP_DISABLE_PIP_VERSION_CHECK=1 environment variable may help.

Thanks, this worked for now as a workaround at least to unblock pipelines.

@owainkenwayucl
Copy link

Another workaround is to delete the pip cache - on Linux this is in ~/.cache/pip. Pip 23.3 works fine with no warning after you do this.

@nschollnetapp
Copy link

Any idea when we can expect a release with this code in it?

@sbidoul
Copy link
Member

sbidoul commented Oct 18, 2023

Any idea when we can expect a release with this code in it?

As there are several easy workarounds I'm not rushing a patch release.

I plan to do one after the fix for #12361 has landed.

@nilslindemann
Copy link

The solution by owainkenwayucl also works inside a venv.

@sbidoul sbidoul closed this as completed Oct 19, 2023
@merwok
Copy link

merwok commented Oct 19, 2023

You can use pip cache info to get details and pip cache purge to clear the cache, no need to hunt for the location 🙂

@derekmahar
Copy link

derekmahar commented Oct 19, 2023

You can use pip cache info to get details and pip cache purge to clear the cache, no need to hunt for the location 🙂

pip cache purge doesn't completely purge my pip cache:

ubuntu@raspberrypi1:~$ pip cache purge
Files removed: 208
ubuntu@raspberrypi1:~$ ls -la ~/.cache/pip/
drwxrwxr-x - ubuntu  8 Aug  2021 http
drwxrwxr-x - ubuntu 16 Oct 09:17 http-v2
drwxrwxr-x - ubuntu 13 Oct 17:27 selfcheck
drwxrwxr-x - ubuntu 10 Sep 14:22 wheels

However, rm -rf ~/.cache/pip does completely purge the cache and it also fixes the pip version check warning (error).

Here are the results of running pip install --upgrade pip first after running pip cache purge and then after running rm -rf ~/.cache/pip:

pip cache purge:

derek@DESKTOP-2F2F59O:~$ pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in /home/derek/.local/lib/python3.10/site-packages (23.3)
WARNING: There was an error checking the latest version of pip.
derek@DESKTOP-2F2F59O:~$ ls -la ~/.cache/pip
drwxr-xr-x - derek 11 Apr 12:06 http
drwxr-xr-x - derek 18 Oct 10:38 http-v2
drwxr-xr-x - derek 13 Oct 17:27 selfcheck
drwxr-xr-x - derek 27 Sep 10:35 wheels
derek@DESKTOP-2F2F59O:~$ pip cache info
Package index page cache location (pip v23.3+): /home/derek/.cache/pip/http-v2
Package index page cache location (older pips): /home/derek/.cache/pip/http
Package index page cache size: 3.0 MB
Number of HTTP files: 190
Locally built wheels location: /home/derek/.cache/pip/wheels
Locally built wheels size: 3.3 kB
Number of locally built wheels: 0
derek@DESKTOP-2F2F59O:~$ pip cache purge
Files removed: 190
derek@DESKTOP-2F2F59O:~$ ls -la ~/.cache/pip
drwxr-xr-x - derek 11 Apr 12:06 http
drwxr-xr-x - derek 18 Oct 10:38 http-v2
drwxr-xr-x - derek 13 Oct 17:27 selfcheck
drwxr-xr-x - derek 27 Sep 10:35 wheels
derek@DESKTOP-2F2F59O:~$ pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in ./.local/lib/python3.10/site-packages (23.3)
WARNING: There was an error checking the latest version of pip.

rm -rf ~/.cache/pip:

derek@DESKTOP-2F2F59O:~$ pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in ./.local/lib/python3.10/site-packages (23.3)
WARNING: There was an error checking the latest version of pip.
derek@DESKTOP-2F2F59O:~$ ls -la ~/.cache/pip
drwxr-xr-x - derek 11 Apr 12:06 http
drwxr-xr-x - derek 18 Oct 10:38 http-v2
drwxr-xr-x - derek 13 Oct 17:27 selfcheck
drwxr-xr-x - derek 27 Sep 10:35 wheels
derek@DESKTOP-2F2F59O:~$ rm -rf ~/.cache/pip
derek@DESKTOP-2F2F59O:~$ ls -la ~/.cache/pip
"/home/derek/.cache/pip": No such file or directory (os error 2)
derek@DESKTOP-2F2F59O:~$ pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in ./.local/lib/python3.10/site-packages (23.3)

@pradyunsg
Copy link
Member

FWIW, the targeted cleanup step here is to delete the selfcheck directory within the cache.

rm -r $(pip cache dir)/selfcheck

@derekmahar
Copy link

FWIW, the targeted cleanup step here is to delete the selfcheck directory within the cache.

Why does this work?

@pradyunsg
Copy link
Member

pradyunsg commented Oct 19, 2023

The underlying issue is that a key-value pair in a JSON object, placed in a JSON file in that directory contains a value that can't be parsed by this version of pip, when it has been generated by a sufficiently old version of pip.

Deleting the directory removes specifically the problematic files, which resolves this issue.

@derekmahar
Copy link

derekmahar commented Oct 19, 2023

FWIW, the targeted cleanup step here is to delete the selfcheck directory within the cache.

Why does this work?

I think I can guess the reason. The state file in the selfcheck directory must have contained an "invalid" ISO date and time format that included a trailing Z time zone.

I no longer have a copy of the original selfcheck state file, but the "new" state file (after removing the pip cache) contains an ISO date and time format that has a trailing "+00:00" time zone that Python 3.10 can interpret:

ubuntu@raspberrypi1:~$ \cat ~/.cache/pip/selfcheck/241e69162522ccf5846a2f42ebc24b17464915a155679666b89a9f31
{"key":"/usr","last_check":"2023-10-19T19:47:38.472420+00:00","pypi_version":"23.3"}

If I replace "+00:00" in this file with "Z", pip again reports the version check warning (error):

derek@DESKTOP-2F2F59O:~$ \cat ~/.cache/pip/selfcheck/241e69162522ccf5846a2f42ebc24b17464915a155679666b89a9f31
{"key":"/usr","last_check":"2023-10-19T20:04:26.937345Z","pypi_version":"23.3"}
derek@DESKTOP-2F2F59O:~$ pip install --upgrade --verbose --verbose pip | tail
WARNING: There was an error checking the latest version of pip.
See below for error
Traceback (most recent call last):
  File "/home/derek/.local/lib/python3.10/site-packages/pip/_internal/self_outdated_check.py", line 227, in pip_self_version_check
    upgrade_prompt = _self_version_check_logic(
  File "/home/derek/.local/lib/python3.10/site-packages/pip/_internal/self_outdated_check.py", line 188, in _self_version_check_logic
    remote_version_str = state.get(current_time)
  File "/home/derek/.local/lib/python3.10/site-packages/pip/_internal/self_outdated_check.py", line 76, in get
    last_check = datetime.datetime.fromisoformat(self._state["last_check"])
ValueError: Invalid isoformat string: '2023-10-19T20:04:26.937345Z'
Removed build tracker: '/tmp/pip-build-tracker-tg0ldpiu'

@sbidoul
Copy link
Member

sbidoul commented Oct 21, 2023

pip 23.3.1 has been released with the fix for this.

@shubhamsaraf26

This comment was marked as off-topic.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 3, 2023
@sbidoul sbidoul unpinned this issue Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

14 participants