How to install multiple whl files in cmd

这一生的挚爱 提交于 2021-02-07 19:58:23

问题


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?


回答1:


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

for %x in (dir *.whl) do python -m pip install %x



回答2:


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])



回答3:


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}')



回答4:


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.




回答5:


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

pip install numpy pandas



来源:https://stackoverflow.com/questions/43314517/how-to-install-multiple-whl-files-in-cmd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!