Home > database >  Splatting pip requirements using powershell
Splatting pip requirements using powershell

Time:12-13

I've trying to install my python's project requirements using powershell splatting.

To get the requirements files, I use this command:

Get-ChildItem -Filter "requirements*"

Then I want to install packages, but I dont know how to splat the file list so that something like this:

pip install -r requirements1.txt -r requirements2.txt ... 

CodePudding user response:

You can use the intrinsic .ForEach() method to construct pairs of -r-file-name arguments, relying on the fact that when you pass a collection of arguments to a call to an external program, PowerShell passes the elements of that collection as individual arguments:

$files = Get-ChildItem -Filter "requirements*"

pip install $files.ForEach({ '-r', $_.Name })
  • Related