I am using pip V22 to install a few packages and I would like to get from the json report (pip install --report -) just the version number and the requirements so as to keep this in a requirements file.
I am not familiar at all with json so please forgive me.
I tried json.loads(report_stdout) and I get error
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
the stdout comes from a subprocess. I tried utf-8 enconding or binary and I always ge the same error!..
Thank you for you answer. I looked into the pip V22 documentation and it says that the option --report - sends the report to stdout:
–report
Generate a JSON file describing what pip did to install the provided requirements. Can be used in combination with --dry-run and --ignore-installed to ‘resolve’ the requirements. When - is used as file name it writes to stdout.
Very strange; if I do include --quiet --report - and --dry-run , I do get a json report but it contains only the report about the pip package, not the report about the installed packages or would be installed packages!..
Yes but I am using subprocess to call pip install from a python script. Is this a deviant use for pip?
Also I used the debug function of my IDE .
If you confirm this not a deviant use I will produce a reproducer
yes exactlly this is what I was looking for Thank you so much.
I just looked into the idea of creating an sqlite database using inspect and sqlitebiter . but sqlitebiter does not like the output of inspect see here incompatibility between pip V22 json output and sqlitebiter · Issue #88 · thombashi/sqlitebiter · GitHub.
Anyhow your proposal is a very nice shortcut.
May I suggest that your tool be referenced into the pip documentation . It would have save me a lot of time. I did google to find an existing package but did not hit yours!..
Glad it’s useful! Not sure if this tool should be mentioned in the docs. At this point, it’s experimental and for a serious project people should use pip-tools which accomplishes the same without relying on pip install --report (or they could use tools like poetry or pdm with their own lockfile formats).