How can I install packages using pip according to the requirements.txt file from a local directory?

This works for me:

$ pip install -r requirements.txt --no-index --find-links file:///tmp/packages

--no-index – Ignore package index (only looking at --find-links URLs instead).

-f, --find-links <URL> – If a URL or path to an HTML file, then parse for links to archives.

If a local path or file:// URL that’s a directory, then look for archives in the directory listing.ShareImprove this answer Follow edited Jan 28 at 19:58Peter Mortensen 28.9k2121 gold badges9696 silver badges123123 bronze badges answered May 3 ’12 at 10:04 codeape 91.6k2222 gold badges145145 silver badges175175 bronze badges

  • 7 Information on --no-index from command pip help install --no-index Ignore package index (only looking at --find-links URLs instead). Information on --find-links from command pip help install -f, --find-links <url> If a url or path to an html file, then parse for links to archives. If a local path or file:// url that’s a directory, then look for archives in the directory listing. – AWrightIV Apr 3 ’15 at 18:54
  • 1 // , This could be a very elegant solution, especially given the eternal struggle with vendorizing: bitprophet.org/blog/2012/06/07/on-vendorizing – Nathan Basanese Apr 4 ’16 at 6:40
  • One caution with this is you may pip install <some_module> without using requirements.txt but that will not update requirements.txt. An alternative might be updating a docker such that it lists all the pip install commands that are run to install dependencies. – ampersands Feb 22 ’18 at 23:05
  • i tried this python -m pip install -r requirements.txt when inside the activated venv enviroment. things installed smoothly but when i do pip list it does not show that packages, when I am in the active venv or even after deactivate venv. also not able to use that packages. dont know what’s wrong here – Shreyan Mehta Feb 12 ’19 at 9:53
  • 1 Just a heads up: This will work as long as there’s not git+ssh requirement in the requirements.txt. For the git+ssh pip will still try to fetch the package – John Paraskevopoulos Jul 20 ’20 at 15:18

Show 1 more comment 161

For virtualenv to install all files in the requirements.txt file.

  1. cd to the directory where requirements.txt is located
  2. activate your virtualenv
  3. run: pip install -r requirements.txt in your shell

Leave a Comment