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

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

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Reactions: 56
  • Comments: 24 (12 by maintainers)

Most upvoted comments

pip 23.3.1 has been released with the fix for this.

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.

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)

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

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.

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

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.

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

rm -r $(pip cache dir)/selfcheck

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

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