Fix ``pip list`` when there is an invalid PEP 440 version installed

Fixes #2208