How can I merge multiple python requirements.txt files?

Viewed 49

Before running my python program, I have to install many separated requirements.txt. I developed a script that installs this files but it takes too long, and I think that merging all of them in one requirements.txt would speed up the installation. Maybe I could develop a script that does the merge but I don't know if there is another way.

  • Do you know any solution that merges multiple requirements.txt in one file?
  • Do you think it would improve the performance?

My current code:

#!/bin/bash

for d in /opt/myprogram/mymodules/*/; do
  if [ -f "$d/requirements.txt" ]; then
    echo "Installing $d requirements"
    pip install -r "$d""requirements.txt" --upgrade-strategy only-if-needed
  else
    echo "WARNING! $d has no requirements"
  fi
done
1 Answers

How can I merge multiple python requirements.txt files?

Just cat. cat requirements.txt otherrquitements.txt > mergedrequirements.txt.

Do you think it would improve the performance?

Yes.


You could do:

pip install --upgrade-strategy only-if-needed -r <(sort -u /opt/myprogram/mymodules/*/requirements.txt) 
Related