Sam Hooke

Python DEPRECATION warning and pip --no-cache-dir breakage

Today, Python 2.7’s pip started echoing the following:

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.

Simultaneously (and perhaps related, though perhaps coincidentally) Python 2.7’s pip started giving the following error:

  File in "...\lib\site-packages\pip\_internal\cli\", line 176, in main
    status =, args)
  File in "...\lib\site-packages\pip\_internal\commands\", line 346, in run
    session=session, autobuilding=True
  File in "...\lib\site-packages\pip\_internal\", line 848, in build
    assert building_is_possible

Looking at the source, there is a TODO above the the assert building_is_possible line:

        # TODO: This check fails if --no-cache-dir is set. And yet we
        #       might be able to build into the ephemeral cache, surely?
        building_is_possible = self._wheel_dir or (
            autobuilding and self.wheel_cache.cache_dir
        assert building_is_possible

Sure enough, we are using the --no-cache-dir option when we call pip.

Removing the call to --no-cache-dir fixes the AssertionError, however we still need pip to not use cached packages.

As a workaround, we can empty the entire pip cache.

The pip cache has a different location depending upon the OS.

  • Windows: %LOCALAPPDATA%\pip\Cache
  • Linux: ~/.cache/pip
Windows §
DEL /f /s /q %LOCALAPPDATA%\pip\Cache
RMDIR /s /q %LOCALAPPDATA%\pip\Cache

(We call DEL and RMDIR because otherwise we get “The directory is not empty”.)

Linux §
rm -rf ~/.cache/pip

It is unclear whether the DEPRECATION message and the AssertionError from --no-cache-dir are related, but in this case neither pip nor Python 2.7 were upgraded – these both seemingly started on their own accord.