If you run it in PyCharm, in Run window, below the play icon is a cog icon -> under "execution" you can select "Emulate terminal in output console" . This will make the progressbar render properly (also realy usefull if you stuff from the rich libary).
If you clicked this video looking for an already made progress bar that you can use straight away, use the "tdqm" package. It's generic, lightweight, and very good for performance, and comes with time estimation by default!
@@Wald246 os.system attemts to call an external command and it changes the settings of the terminal. It is like calling colorama.init() and it works with a real command like cls. You can use this trick on windows to avoid the use of colorama or other library (of course you'll have to know the escape sequences: \033[0m; - to reset all, \033[ (30-37 | 90-97 - foreground); (40-47 | 100-107 - background)m example: os.system("cls") # or just os.system("") print("\033[94;103m< bright blue on bright yellow >\033[0m < normal text >") And also works in windows 10 CMD (Command Prompt). But calling external commands (specially OS dependent) it is not a good ideea and should stick to colorama.init(). Also I like using the VT escape sequences because there are a lot more than what colorama has, like for moving the cursor around (\033[nA, \033[nB and \033[nC, where n is a natural number), erasing lines (\033[0K and \033[0J) or changiing the terminal title (print("\033]0;My Title\007", end=""))
tqdm is really good loading bar package it adjusts automatically, is performant, easy to use and provide nice infothat also includes performance optimizations so it doesn't slow down your program Example: from tqdm import tqdm import time for x in tqdm(range(100)): time.sleep(0.01) 21%|█████████▍ | 21/100 [00:02
In fact CMD can display colors like a Unix terminal (however it won't render italics or bold or any font transforms), you just need to set a registery key called TerminalLevel to 1 Here is the command to do so reg add HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 00000001
stands for "Carage return" Have a great day - 0x454d505459
This can be done programmatically without affecting the whole system by using windows api functions handle = GetStdHandle(STD_OUTPUT_HANDLE) # ((DWORD) -11) SetConsoleMode(handle, ENABLE_VIRTUAL_TERMINAL_PROCESSING) # (0x0004).
The terminal can be run from PyCharm. The bar in the bottom left hand side that says “Version Control, TODO, Problems, Terminal, Python Packages, Python Console” Click the Terminal tab.
If you are just looking to add a progress bar to your program, you can wrap an iterator in tqdm.tqdm(). It shows iterations per second and expected finish time
in cmd (or windows terminal) you can go thru all subdirectories in one command "cd Desktop\Programming\NeuralNine\Python\Current". Also you can autocomplete subdir name with tab
you can display the progressbars in pycharm by going to the run-config of the script and then enabeling "Emulate terminal in output console" at "Execution"
I made a similar thing in C# in the past but the fun came when having to write code to not make the lines move to different parts of the screen upon console resize.
Perfect just what i was looking for... Btw, do you know how to get the progressbar used in the latest pip3 command. I think that would be a lot cooler.
Very nice thanks, actually i think you can do all that maybe in a cooler way with curses (or cursed dont remember) from standard library , color also for the terminal which has this functionality
I managed to do the same with colorama, curses and sty, this colorama is quite fine aproach, for now i used pydroid and with each one had similar issues, i will try it on linux, curses is most complicated
@@Sinke_100 ah okay nice to know, i finished reading the documentation of curse the day before this video came out, didn’t realize it was more complicated than this
you rock.... trying to keep up with the videos... awesome stuff...👍🏿thanks please cover more of opencv comparing facial images..I already saw the fingerprint example
On line 16 you dont need to make that extra calculation every time in the loop just give enumerate a starting point of one - for i, x in enumerate(numbers, 1): and you are good to go. Same is for len(numbers) you dont want to make it every loop to go and find how long is the list make a var before the loop and use that.Thats all extra calculation that you dont want to do on every loop in real life and slow your code...
Thank you for the great tutorial. I have done this type of progress bar and in some cases used tqdm, which makes life much easier. However, my question is how can I show the progress in asyncio? what I mean is when you trigger the asyncio.run and it is doing the asyncio.gather to actually complete the asynchronous task, how can I show the progress of each task? something like docker which shows the progress of each image download separately.
but it is really educational and informative , this is one of the rare videos showing how to make progress bars. Why should he "reinvent the wheel" of trying to produce the same videos?
This is odd, everything else I've read said that before you can implement progress bars, you have to make your python program multi-threaded and make sure to dedicate your background process to another thread, but you didn't do that, is that incorrect information?
This is super cool. Is there a way to used it when using a pandas function (for example read_excel) where the loop is implemented by the function and not by yourself so you cannot report progress?
First of all, thx about the video. But i need some help to make a function that can display more than 1 progress bar, to use in more than 1 loop and that could be shown even during the program is printing in the console. Could you make a new video showing how to update this function?
Hello, Get video. I was able to get the CMD to display the colors by using the adding the code colorama.init() at the start. And then the yellow and green popped up. Didn't even need to close the CMD window. After adding the one line and rerun the script and the colors appeared. Again thanks,
Using the carriage return to position the cursor at the beginning of the line is good in CMD. But many other terminals places the cursor to a new line when that character is encountered. I think a more consitent way of setting the position of the cursore would be to use the ANSI escape code 0x1B[0G ( en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences )
i remember that it does not work on windows (that escape code only - Cursor Horizontal Absolute). I had to use the trick \033[5C (Cursor Forward) in CMD to sets the cursor position on column 5
It's giving me a Syntax error with this: "numbers [x * 5 for x in range(2000, 3000)]" Copied the code I think pretty much exactly but could be wrong, here's the code: import math def progress_bar(progress, total): precent = 100 * (progress / float(total)) bar = ' ' * int(percent) + '-' * (100 - int(percent)) print(f" |{bar}| {percent:.2f}%", end = " ")
numbers [x * 5 for x in range(2000, 3000)] results = [] progress_bar(0, len(numbers)) for i, x in enumerate(numbers): results.append(math.factorial(x)) progress_bar(i + 1, len(numbers))
this is slightly awful, instead of creating dynamic dependencies for the function's state or an object's state it updates by repeatedly calling somewhere within it. same goes for passing arguments to the parameters, getting the length of the list each time is unnecessary.
chr(9608) for filing bar and chr(9617) for blank
I was eight months late, and all I had to offer was a sad, chr(219) lol
Thanks for the filled in version.
If you run it in PyCharm, in Run window, below the play icon is a cog icon -> under "execution" you can select "Emulate terminal in output console" . This will make the progressbar render properly (also realy usefull if you stuff from the rich libary).
Holy crap thanks for this tip.
If you clicked this video looking for an already made progress bar that you can use straight away, use the "tdqm" package. It's generic, lightweight, and very good for performance, and comes with time estimation by default!
in python 3 the division int / int returns a float automatically. if you want integer division, you can use //.
Just a heads up, you can use os.system("") with an empty string argument to display colors in a cmd prompt
how does that work?
@@Wald246 dont do this
came here to point the exact same thing
@@Wald246 os.system attemts to call an external command and it changes the settings of the terminal. It is like calling colorama.init() and it works with a real command like cls. You can use this trick on windows to avoid the use of colorama or other library (of course you'll have to know the escape sequences:
\033[0m; - to reset all,
\033[ (30-37 | 90-97 - foreground); (40-47 | 100-107 - background)m
example:
os.system("cls") # or just os.system("")
print("\033[94;103m< bright blue on bright yellow >\033[0m < normal text >")
And also works in windows 10 CMD (Command Prompt).
But calling external commands (specially OS dependent) it is not a good ideea and should stick to colorama.init(). Also I like using the VT escape sequences because there are a lot more than what colorama has, like for moving the cursor around (\033[nA, \033[nB and
\033[nC, where n is a natural number), erasing lines (\033[0K and \033[0J) or changiing the terminal title (print("\033]0;My Title\007", end=""))
you can simply do with Ansi code:
print("\33[92mHello, World\33[0m")
All these years I never knew that print(..., end='
') will actually do a carriage return to the same line in a Windows console, lol. THANKS!
That was fun to follow along with, somewhat simple (or at least not overly complicated), and the result looks great! Thanks!
I don´t know how to code yet. First steps on Odin, but I bookmarked the channel.
Thanks a lot for the videos!
tqdm is really good loading bar package it adjusts automatically, is performant, easy to use and provide nice infothat also includes performance optimizations so it doesn't slow down your program
Example:
from tqdm import tqdm
import time
for x in tqdm(range(100)):
time.sleep(0.01)
21%|█████████▍ | 21/100 [00:02
Yes, stick to the stuff written in c/c++ when utlizing Python
Pssst: tqdm means `progress` in Arabic, (taqadam ) in case you ever wondered.
I always thought it was a bunch of random letters, thanks for gifting me with this knowledge.
In fact CMD can display colors like a Unix terminal (however it won't render italics or bold or any font transforms), you just need to set a registery key called TerminalLevel to 1
Here is the command to do so
reg add HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 00000001
stands for "Carage return"
Have a great day
- 0x454d505459
@name undefined.... why you are EMPTY :)
This can be done programmatically without affecting the whole system by using windows api functions
handle = GetStdHandle(STD_OUTPUT_HANDLE) # ((DWORD) -11)
SetConsoleMode(handle, ENABLE_VIRTUAL_TERMINAL_PROCESSING) # (0x0004).
@@vaisakh_km ;)
you do know you can just use os.system("") with an empty string and that'll activate colors in a cmd right?
That moment where i was thinking about this this morning, and now it’s top of my recommendation list .-.
You don't need to do index + 1. enumerate function takes an optional argument `start` that defaults to 0. So you can just do enumerate(iterable, 1)
The terminal can be run from PyCharm.
The bar in the bottom left hand side that says “Version Control, TODO, Problems, Terminal, Python Packages, Python Console”
Click the Terminal tab.
small video and to the point in a simple way, love it! Thanks for this
Had been looking for something like this for a while, your videos are awesome.
Thanks a million for this video! I was just looking for such a solution ... and you saved my day! Thx, thx, thx!
If you are just looking to add a progress bar to your program, you can wrap an iterator in tqdm.tqdm(). It shows iterations per second and expected finish time
@@harrytsang1501 indeed - amazing! Thx for this hint!
in cmd (or windows terminal) you can go thru all subdirectories in one command
"cd Desktop\Programming\NeuralNine\Python\Current". Also you can autocomplete subdir name with tab
I'm assuming you can use this or tqdm and pass it to a GUI library like Tkinter to get a non-command line progress bar?
you can display the progressbars in pycharm by going to the run-config of the script and then enabeling "Emulate terminal in output console" at "Execution"
I made a similar thing in C# in the past but the fun came when having to write code to not make the lines move to different parts of the screen upon console resize.
Perfect just what i was looking for...
Btw, do you know how to get the progressbar used in the latest pip3 command. I think that would be a lot cooler.
Dude, this video was super cool !!
Why are you not using TQDM
Hello, can you show us how to implement graphics in python? Your python videos are great. Many thanks!
Voilà là, vous me faites plaisir
Very nice thanks, actually i think you can do all that maybe in a cooler way with curses (or cursed dont remember) from standard library , color also for the terminal which has this functionality
I managed to do the same with colorama, curses and sty, this colorama is quite fine aproach, for now i used pydroid and with each one had similar issues, i will try it on linux, curses is most complicated
@@Sinke_100 ah okay nice to know, i finished reading the documentation of curse the day before this video came out, didn’t realize it was more complicated than this
I did the same but using escape sequences for colors and cursor movements. So didn't need any external lib.
How is that done?
Bro coming with sick projects 🥵🔥🔥
Thank you that you created for me a skill bar :D
Amazing!
Thank you a loads.
you rock....
trying to keep up with the videos...
awesome stuff...👍🏿thanks
please cover more of opencv comparing facial images..I already saw the fingerprint example
On line 16 you dont need to make that extra calculation every time in the loop just give enumerate a starting point of one - for i, x in enumerate(numbers, 1): and you are good to go. Same is for len(numbers) you dont want to make it every loop to go and find how long is the list make a var before the loop and use that.Thats all extra calculation that you dont want to do on every loop in real life and slow your code...
I like that guy. Already watched the vim videos. 👍🏻
Colorama does work in default cmd but you have to use colorama.init() somewhere in your script first.
Thank you for the great tutorial. I have done this type of progress bar and in some cases used tqdm, which makes life much easier. However, my question is how can I show the progress in asyncio? what I mean is when you trigger the asyncio.run and it is doing the asyncio.gather to actually complete the asynchronous task, how can I show the progress of each task? something like docker which shows the progress of each image download separately.
def progress_bar(progress, total, symbol='█', width=100):
print(f'{symbol * int(width * progress / total):.
What is the difference of this program with the library tqrm ??
tqdm is just way better as you don't have to do any housekeeping yourself, just wrap the interator
Good tutorial, thanks!
fun fact: you can run it in pycharm if you choose to emulate the command prompt in your interpreter configuration
Useful stuff and to the point. I like your style.
it happens when the window doesn't have enough width. change it to maximized mode or move it into a new workspace with enough room
In windows terminal you do not need to call colorama.init()? Btw CMD supports VT sequences and coloured output with colorama.
why not simply use tqdm?.
You may not always want to be dependent on external libs. Or you might want to do it yourself because you need a simple progress bar.
@@nameundefined6265 then why use pandas? Just use list
sir, how to stop a progress bar at a particular value ?
Why do you use "
" at the start of the print and also at the end instead of just using it just with the parameter end="
"? Isn't it the same?
Great videos THX
Great video, thanks. How can do the same for parallel tasks?
Very interesting, thanks! 👍
What if you have a very small terminal that wraps the progress bar? Shouldn't it fit to the terminal?
make a full in detail tutorial about rich library
Hello, If I have to print multiple progress bar? How can I do it?
use tqdm for this
great content, great didactic. Congrats!
You can also use the tqdm library on python for easier progress bars
this should be top com, no need to reinvent the wheel
but it is really educational and informative , this is one of the rare videos showing how to make progress bars. Why should he "reinvent the wheel" of trying to produce the same videos?
NeuralNine ON TOP
Wait you are using windaube ?
Nice! But how about awesome python library - rich? There is a progress bar too.
This is odd, everything else I've read said that before you can implement progress bars, you have to make your python program multi-threaded and make sure to dedicate your background process to another thread, but you didn't do that, is that incorrect information?
I want the percent number to be in middle of the progress bar. How can i do it?
How would you handle a condition where process fails and the progress bar can't reach 100%?
This is super cool. Is there a way to used it when using a pandas function (for example read_excel) where the loop is implemented by the function and not by yourself so you cannot report progress?
use tqmd. You then can use `for i in tqdm(range(10000)):` to automatically get a progress bar.
Could you please make a video on how to download weather i.e. download METAR reports from different station using i.e. ICAO or IATA codes?
Everytime I tried pip install nothing happens. Syntax error: invalid syntax.
Could you explain how to use and what is pyinsxtractor and uncompyle6?
1:55 I haven't seen that been used a lot, I usually do:
(100 / total) * progress
Do you can make video about progress bars in kivy
First of all, thx about the video.
But i need some help to make a function that can display more than 1 progress bar, to use in more than 1 loop and that could be shown even during the program is printing in the console.
Could you make a new video showing how to update this function?
Hello, Get video.
I was able to get the CMD to display the colors by using the adding the code
colorama.init()
at the start. And then the yellow and green popped up. Didn't even need to close the CMD window. After adding the one line and rerun the script and the colors appeared.
Again thanks,
love it!
Rich Library => does the same but quickly
Nice intro.
I see the bar is printed in every loop... why does a new bar print over a previous one?
because he uses the cariage return character "
"
I wish I could give 1000s of likes.
Thank you very much.
What IDE software do you use
pycharm
thank you
does it work on ipython
For me, it is displaying the bar multiple times; not once. Anyway to solve this?
your terminal window is not wide enough
Using the carriage return to position the cursor at the beginning of the line is good in CMD. But many other terminals places the cursor to a new line when that character is encountered. I think a more consitent way of setting the position of the cursore would be to use the ANSI escape code 0x1B[0G ( en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences )
i remember that it does not work on windows (that escape code only - Cursor Horizontal Absolute). I had to use the trick
\033[5C (Cursor Forward) in CMD to sets the cursor position on column 5
It's giving me a Syntax error with this:
"numbers [x * 5 for x in range(2000, 3000)]"
Copied the code I think pretty much exactly but could be wrong, here's the code:
import math
def progress_bar(progress, total):
precent = 100 * (progress / float(total))
bar = ' ' * int(percent) + '-' * (100 - int(percent))
print(f"
|{bar}| {percent:.2f}%", end = "
")
numbers [x * 5 for x in range(2000, 3000)]
results = []
progress_bar(0, len(numbers))
for i, x in enumerate(numbers):
results.append(math.factorial(x))
progress_bar(i + 1, len(numbers))
yeah you are missing an equal sign between numbers and "[x*5...]".
Thank you both, if i get around to finding the file again ill update how it went
next time code whole universe in phyton ;)
lmfao
😂💀
Without any imports.
Great vid, but why not just use ansi color codes
Amazing ! :)
u look like the guy from hxh that fights with coins
It would be soooo much faster if you just used the user’s volume settings as the progress bar.
@Jamie 🏳️🌈 it’s flawless
Great!!!
How in the hell did i reach here...
Fav anyways, who knows in the future.
Well the colours didn't work on cmd but worked in PyCharm terminal for me...
in cmd use colorama.init() just once after the import (or before the first color printing)
tqdm?
Thx.
Nice
ok so wheres the link to the code?
nice, muito bonito ❣❤🩹
My colors do not change
SOURCE CODE PLS
bruh like dude why this brings
ZeroDivisionError
B R U H
Or you could just use the tqdm package 🤷
now try that on Rust
import rich and you are done
tqdm
▨▬▮ squares :)
chr(9608)
this is slightly awful, instead of creating dynamic dependencies for the function's state or an object's state it updates by repeatedly calling somewhere within it. same goes for passing arguments to the parameters, getting the length of the list each time is unnecessary.