0

I thought this would work:

subprocess.run(['pip', 'freeze', '>', 'requirements.txt'])

... but no file appears to have been created. However, the results of pip freeze are listed in stdout.

I then tried:

subprocess.run(['pip', 'freeze', '>', 'requirements.txt'], cwd=pathlib.Path.cwd())

... nothing.

I surmised that using ">" like this doesn't work (although slightly mystified that no error is raised if so), so tried this:

req_txt = pathlib.Path.cwd().joinpath('requirements.txt')
req_txt.touch()
subprocess.run(['pip', 'freeze'], stdout=req_txt)

... this leaves an empty file.

What's the way to do this?

mike rodent
  • 12,285
  • 11
  • 88
  • 123

0 Answers0