question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pip list --format json output ends with \x1b[0m -> JSONdecode error

See original GitHub issue

Description

Using version 22.0.3 the output of pip list ends with \x1b[0m. (version 21.3.1 does not have this issue) For pip list this is not the problem, but pip list --format json has the same behaiour. -> json.decoder.JSONDecodeError: Extra data

The following options do not change the behaviour.

  • –disable-pip-version-check
  • –no-python-version-warning
  • –no-color

Expected behavior

pip list --format json should end with a line seperator.

pip version

22.0.3

Python version

3.9.7

OS

Win10

How to Reproduce

import json
import subprocess
json.loads(subprocess.check_output(("pip", "list", "--format", "json"))

Output

json.decoder.JSONDecodeError: Extra data

Code of Conduct

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
willmcgugancommented, Feb 4, 2022

@pradyunsg Can’t think of any reason it would, but I wouldn’t rule it out 100%. I’ll see if I can replicate this.

0reactions
da1910commented, Mar 23, 2022

This is also causing problems with pip-audit, any attempt to actually parse the json causes errors.

I am happy to help diagnose the issue. At the moment my workaround is to stick with pip 21.3.1 which does not have this issue.

I can confirm that subprocess is called with stdout = PIPE, I can also provide environment information etc if required.

Also from what I can tell the options passed to rich are correct, style ends up set to None as I would expect.

Win 11

  • Windows 11 Enterprise
  • 10.0.22000
  • Build 22000
Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Handle JSON Decode Error when nothing returned
Unfortunately, json. loads throws a TypeError when the JSON object isn't a str, bytes, or bytearray. This bit me recently because I had...
Read more >
Python JSON tricks: how to deal with JSONDecodeError
Trick 1: You should use double quotes for keys and values, otherwise you will have the JSONDecodeError error:
Read more >
pipdeptree - PyPI
pipdeptree is a command line utility for displaying the installed python packages in form of a dependency tree. It works for packages installed...
Read more >
pip list - pip documentation v22.3.1
Select the output format among: columns (default), freeze, or json. --not-required#. List packages that are not dependencies of installed packages.
Read more >
Check all installed Python packages with pip list/freeze
If the output format is columns or json , the currently installed version and the latest version are output together. $ pip list...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found