7

I know how to install *.whl files through cmd (the code is simply python -m pip install *so-and-so-.whl). But since I accidentally deleted my OS and had no backups I found myself in the predicament to reinstall all of my whl files for my work.

This comes up to around 50 files. I can do this manually which is pretty simple, but I was wondering how to do this in a single line. I can't seem to find anything that would allow me to simply type in python -m pip install *so-and-so.whl to find all of the whl files in the directory and install them.

Any ideas?

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Kaelan O'reily
  • 113
  • 1
  • 1
  • 8

5 Answers5

14

In Windows cmd you can use a for loop to do this:

for %x in (dir *.whl) do python -m pip install %x
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
  • 5
    It's just `(*.whl)`, not `(dir *.whl)` (your way will work, other than trying to run `python -m pip install dir`, which naturally fails) – Michael Mrozek Jun 13 '19 at 19:26
6

Another more universal way that works on most OS is to run this using python interpreter:

import glob, pip
for path in glob.glob("c:/path/to/wheel/files/*.whl"):
    pip.main(['install', path])
Taku
  • 31,927
  • 11
  • 74
  • 85
3

In linux, you could do a something like :

for x in `ls /home/pip-packages`; do pip install $x; done

this will install both .whl and tar packages.

karthik101
  • 1,619
  • 4
  • 17
  • 23
2

Pip doesn't support main from v10.0.*

import glob
import subprocess
for path in glob.glob("c:/path/to/wheel/files/*.whl"):
    subprocess.run(f'pip install {path}')
Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
-4

For installing multiple packages on the command line, just pass them as a space-delimited list, e.g.:

pip install numpy pandas

mmenschig
  • 1,088
  • 14
  • 22