5

I find the new version pip(package installer for Python) has a colorful progress bar to show the downloading progress. How can I do that?

Like this: enter image description here

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
PinkR1ver
  • 402
  • 1
  • 4
  • 13

3 Answers3

10

pip itself is using the rich package! In particular, their progress bar docs show this example:

from rich.progress import track

for n in track(range(n), description="Processing..."):
    do_work(n)
Lucas Saldyt
  • 359
  • 2
  • 13
3
import time 
from rich.progress import track

for n in track(range(20), description="Processing..."):
    time.sleep(n)

enter image description here

Rich is installed with latest pip, but incase you are missing it:

pip install rich
ckloan
  • 154
  • 1
  • 8
1

The following simple code uses pip own progress bar controls.

import time

from pip._internal.cli.progress_bars import get_download_progress_renderer


if __name__ == "__main__":
    chunks = []
    b = get_download_progress_renderer(bar_type="on",size=100)
    for i in range(100):
        chunks.append(range(i))
        for bb in b(chunks):
            time.sleep(.1)

The output will look something like this... enter image description here

Hezi Shahmoon
  • 388
  • 1
  • 7