{"id":174743,"date":"2024-05-08T18:37:11","date_gmt":"2024-05-08T10:37:11","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/174743.html"},"modified":"2024-05-08T18:37:16","modified_gmt":"2024-05-08T10:37:16","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85progressbar%e6%a8%a1%e5%9d%97%e5%91%a2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/174743.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u5b89\u88c5progressbar\u6a21\u5757\u5462"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27052408\/671efcb8-e86f-4191-b62d-98b11734644d.webp\" alt=\"python\u4e2d\u5982\u4f55\u5b89\u88c5progressbar\u6a21\u5757\u5462\" \/><\/p>\n<p><p><strong>\u5728Python\u4e2d\u5b89\u88c5progressbar\u6a21\u5757\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u6267\u884c\u3001\u786e\u4fdd\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u548cpip\u3001\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u76f8\u5e94\u7684\u5b89\u88c5\u547d\u4ee4\u3002<\/strong> \u60a8\u9700\u8981\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177\uff08\u5728Windows\u4e2d\u662f\u547d\u4ee4\u63d0\u793a\u7b26\u6216PowerShell\uff0c\u5728MacOS\u6216Linux\u4e2d\u662f\u7ec8\u7aef\uff09\uff0c\u7136\u540e\u8f93\u5165\u5b89\u88c5\u547d\u4ee4\u3002\u5982\u679c\u53ea\u662f\u60f3\u8981\u5b89\u88c5\u57fa\u672c\u7684progressbar\u6a21\u5757\uff0c\u7b80\u5355\u5730\u8fd0\u884c<code>pip install progressbar<\/code>\u901a\u5e38\u5c31\u8db3\u591f\u4e86\u3002\u7136\u800c\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6709\u591a\u4e2a\u7248\u672c\u7684\u8fdb\u5ea6\u6761\u6a21\u5757\u53ef\u7528\uff0c\u5982<code>progressbar2<\/code>\uff0c\u5b83\u662f\u4e00\u4e2a\u66f4\u9ad8\u7ea7\u5e76\u4e14\u5f97\u5230\u66f4\u591a\u7ef4\u62a4\u7684\u7248\u672c\u3002<\/p>\n<\/p>\n<p><p>\u5728\u6267\u884c\u5b89\u88c5\u547d\u4ee4\u4e4b\u540e\uff0cpip\u4f1a\u4ecePython Package Index (PyPI) \u4e0b\u8f7d\u5e76\u5b89\u88c5progressbar\u6a21\u5757\uff0c\u5305\u62ec\u5b83\u7684\u6240\u6709\u4f9d\u8d56\u3002\u8fd9\u662f\u6700\u76f4\u63a5\u548c\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u7528\u6237\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4e86\u89e3\u8fdb\u5ea6\u6761\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u5728\u6df1\u5165\u5b89\u88c5\u6b65\u9aa4\u4e4b\u524d\uff0c\u4e86\u89e3\u4e0d\u540c\u7684\u8fdb\u5ea6\u6761\u6a21\u5757\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u539f\u59cb\u7684<code>progressbar<\/code>\u6a21\u5757\u73b0\u5728\u53ef\u80fd\u5df2\u7ecf\u4e0d\u518d\u6709\u4eba\u7ef4\u62a4\uff0c\u56e0\u6b64\u793e\u533a\u63a8\u8350\u4f7f\u7528<code>progressbar2<\/code>\u3002\u8fd9\u4e2a\u66f4\u65b0\u7684\u7248\u672c\u662f\u4e0e\u539f\u59cb\u7684progressbar\u6a21\u5757API\u517c\u5bb9\u7684\uff0c\u5e76\u4e14\u589e\u52a0\u4e86\u8bb8\u591a\u65b0\u529f\u80fd\u548c\u6539\u8fdb\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u7cfb\u7edf\u73af\u5883\u51c6\u5907<\/h3>\n<\/p>\n<p><p>\u5728\u5b89\u88c5progressbar\u6a21\u5757\u524d\uff0c\u8bf7\u786e\u4fdd\u60a8\u7684\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u548cpip\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c<code>python --version<\/code>\u548c<code>pip --version<\/code>\u6765\u68c0\u67e5\u5b83\u4eec\u7684\u5b89\u88c5\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u901a\u8fc7PIP\u5b89\u88c5progressbar<\/h3>\n<\/p>\n<p><h4>\u5b89\u88c5\u57fa\u672c\u7684progressbar\u6a21\u5757<\/h4>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install progressbar<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u662f\u6700\u7b80\u5355\u7684\u5b89\u88c5\u547d\u4ee4\uff0c\u4f1a\u4ecePyPI\u4e0b\u8f7d\u5e76\u5b89\u88c5progressbar\u6a21\u5757\u3002<\/p>\n<\/p>\n<p><h4>\u5b89\u88c5\u8fdb\u9636\u7684progressbar2\u6a21\u5757<\/h4>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install progressbar2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5b89\u88c5\u66f4\u73b0\u4ee3\u3001\u529f\u80fd\u8f83\u4e3a\u4e30\u5bcc\u7684\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u9a8c\u8bc1\u5b89\u88c5<\/h3>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884cPython\u89e3\u91ca\u5668\uff0c\u5e76\u5c1d\u8bd5\u5bfc\u5165progressbar\u6a21\u5757\u6765\u9a8c\u8bc1\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import progressbar<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u6ca1\u6709\u9519\u8bef\u6d88\u606f\uff0c\u90a3\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u4e86\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u89e3\u51b3\u5b89\u88c5\u4e2d\u53ef\u80fd\u9047\u5230\u7684\u95ee\u9898<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u7531\u4e8e\u7f51\u7edc\u6216\u6743\u9650\u95ee\u9898\uff0c\u5b89\u88c5\u53ef\u80fd\u4f1a\u5931\u8d25\u3002\u9488\u5bf9\u8fd9\u4e9b\u60c5\u51b5\uff0c\u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u76f8\u5e94\u7684\u5904\u7406\uff1a<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u6e05\u534e\u5927\u5b66\u955c\u50cf\u52a0\u901fpip\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u662f\u56e0\u4e3a\u7f51\u7edc\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u56fd\u5185\u7684\u955c\u50cf\u6e90\u6765\u52a0\u901f\u4e0b\u8f7d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install progressbar2 -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4f7f\u7528\u7ba1\u7406\u5458\u6743\u9650\u8fd0\u884c\u5b89\u88c5\u547d\u4ee4<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u662f\u6743\u9650\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u7ba1\u7406\u5458\u6743\u9650\u6765\u8fd0\u884cpip\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><p>\u5728Windows\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install progressbar2 --user<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\uff0c\u5728MacOS\u6216Linux\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">sudo pip install progressbar2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u8fdb\u4e00\u6b65\u5b66\u4e60progressbar\u7684\u4f7f\u7528<\/h3>\n<\/p>\n<p><p>\u4e00\u65e6\u5b89\u88c5\u4e86progressbar\u6a21\u5757\uff0c\u63a5\u4e0b\u6765\u7684\u91cd\u8981\u6b65\u9aa4\u662f\u5b66\u4e60\u5982\u4f55\u5728\u60a8\u7684\u4ee3\u7801\u4e2d\u4f7f\u7528\u5b83\u3002\u5e38\u89c1\u7684\u7528\u6cd5\u662f\u5728\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u5faa\u73af\u4e2d\u663e\u793a\u4e00\u4e2a\u8fdb\u5ea6\u6761\uff0c\u7ed9\u7528\u6237\u63d0\u4f9b\u53cd\u9988\u4ee5\u4fbf\u4e86\u89e3\u8fdb\u5ea6\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u7ed3\u5408\u793a\u4f8b\u4ee3\u7801\u7406\u89e3progressbar\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u6765\u770b\u4e00\u4e2a\u4f7f\u7528<code>progressbar2<\/code>\u6a21\u5757\u7684\u7b80\u5355\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p>import progressbar<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aProgressBar\u5bf9\u8c61<\/strong><\/h2>\n<p>bar = progressbar.ProgressBar(maxval=10, \\<\/p>\n<p>    widgets=[progressbar.Bar(&#039;=&#039;, &#039;[&#039;, &#039;]&#039;), &#039; &#039;, progressbar.Percentage()])<\/p>\n<p>bar.start()  # \u5f00\u59cb\u8fdb\u5ea6\u6761<\/p>\n<p>for i in range(10):<\/p>\n<p>    bar.update(i+1)  # \u66f4\u65b0\u8fdb\u5ea6\u6761\u5230\u5f53\u524d\u7684\u5faa\u73af\u6b21\u6570<\/p>\n<p>    time.sleep(1)  # \u6a21\u62df\u4e00\u4e2a\u8017\u65f61\u79d2\u7684\u4efb\u52a1<\/p>\n<p>bar.finish()  # \u5b8c\u6210\u8fdb\u5ea6\u6761<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u6700\u5927\u503c\u4e3a10\u7684\u8fdb\u5ea6\u6761\uff0c\u968f\u540e\u5728\u4e00\u4e2a\u6a21\u62df\u8017\u65f6\u4efb\u52a1\u7684\u5faa\u73af\u4e2d\uff0c\u4e0d\u65ad\u66f4\u65b0\u8fdb\u5ea6\u6761\u3002\u7528\u6237\u53ef\u4ee5\u770b\u7740\u8fdb\u5ea6\u6761\u6162\u6162\u5730\u4ece\u5de6\u5230\u53f3\u8fdb\u884c\u586b\u5145\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\u548c\u793a\u4f8b\uff0c\u60a8\u5e94\u8be5\u53ef\u4ee5\u987a\u5229\u5730\u5b89\u88c5\u5e76\u5f00\u59cb\u4f7f\u7528Python\u4e2d\u7684progressbar\u6a21\u5757\u4e86\u3002\u5f53\u4f60\u9010\u6e10\u719f\u7ec3\u5176\u7528\u6cd5\u4e4b\u540e\uff0c\u53ef\u4ee5\u521b\u5efa\u51fa\u66f4\u590d\u6742\u3001\u66f4\u7f8e\u89c2\u7684\u8fdb\u5ea6\u6307\u793a\u5668\uff0c\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>Q: \u5982\u4f55\u5728Python\u4e2d\u5b89\u88c5progressbar\u6a21\u5757\uff1f<\/strong><\/p>\n<p>A: \u5b89\u88c5progressbar\u6a21\u5757\u7684\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86pip\uff0cpip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\u3002\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5progressbar\u6a21\u5757\uff1a<\/p>\n<pre><code>pip install progressbar\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fPython3\uff0c\u5219\u9700\u8981\u4f7f\u7528pip3\uff1a<\/p>\n<pre><code>pip3 install progressbar\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u6210\u529f\u5b89\u88c5progressbar\u6a21\u5757\u4e86\u3002<\/p>\n<p><strong>Q: \u6211\u5b89\u88c5\u4e86progressbar\u6a21\u5757\u540e\uff0c\u5982\u4f55\u5728\u6211\u7684Python\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u5b83\uff1f<\/strong><\/p>\n<p>A: \u5b89\u88c5\u5b8cprogressbar\u6a21\u5757\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u4f60\u7684Python\u7a0b\u5e8f\u4e2d\u76f4\u63a5\u5bfc\u5165\u5b83\u5e76\u4f7f\u7528\u5b83\u7684\u529f\u80fd\u3002\u9996\u5148\uff0c\u5728\u4f60\u7684\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5bfc\u5165\u8bed\u53e5\uff1a<\/p>\n<pre><code class=\"language-python\">import progressbar\n<\/code><\/pre>\n<p>\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528progressbar\u6a21\u5757\u63d0\u4f9b\u7684\u4e0d\u540c\u7c7b\u548c\u65b9\u6cd5\u6765\u521b\u5efa\u548c\u7ba1\u7406\u8fdb\u5ea6\u6761\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>ProgressBar()<\/code>\u7c7b\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u8fdb\u5ea6\u6761\uff0c\u7136\u540e\u4f7f\u7528<code>start()<\/code>\u548c<code>update()<\/code>\u65b9\u6cd5\u6765\u663e\u793a\u548c\u66f4\u65b0\u8fdb\u5ea6\u3002<\/p>\n<p>\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728\u4f60\u7684\u7a0b\u5e8f\u4e2d\u6dfb\u52a0\u8fdb\u5ea6\u6761\uff0c\u4f7f\u5f97\u4f60\u7684\u4ee3\u7801\u6267\u884c\u65f6\u53ef\u4ee5\u5b9e\u65f6\u663e\u793a\u8fdb\u5ea6\u3002<\/p>\n<p><strong>Q: \u8fdb\u5ea6\u6761\u53ef\u4ee5\u7528\u6765\u76d1\u6d4b\u54ea\u4e9b\u64cd\u4f5c\u7684\u6267\u884c\u8fdb\u5ea6\uff1f<\/strong><\/p>\n<p>A: \u8fdb\u5ea6\u6761\u53ef\u4ee5\u7528\u6765\u76d1\u6d4b\u4efb\u4f55\u9700\u8981\u8fdb\u884c\u8fed\u4ee3\u6216\u5faa\u73af\u7684\u64cd\u4f5c\u7684\u6267\u884c\u8fdb\u5ea6\u3002\u6bd4\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fdb\u5ea6\u6761\u6765\u663e\u793a\u6587\u4ef6\u7684\u590d\u5236\u6216\u4e0b\u8f7d\u8fdb\u5ea6\uff0c\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u65f6\u7684\u8fdb\u5ea6\uff0c\u6216\u8005\u4efb\u4f55\u9700\u8981\u82b1\u8d39\u8f83\u957f\u65f6\u95f4\u7684\u64cd\u4f5c\u7684\u8fdb\u5ea6\u3002<\/p>\n<p>\u8fdb\u5ea6\u6761\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5b9e\u65f6\u4e86\u89e3\u64cd\u4f5c\u7684\u8fdb\u5c55\uff0c\u5e76\u63d0\u4f9b\u53ef\u89c6\u5316\u7684\u8fdb\u5ea6\u5c55\u793a\uff0c\u8ba9\u4f60\u5bf9\u64cd\u4f5c\u7684\u5b8c\u6210\u65f6\u95f4\u6709\u66f4\u76f4\u89c2\u7684\u611f\u77e5\u3002\u65e0\u8bba\u4f60\u662f\u5728\u5904\u7406\u6587\u4ef6\uff0c\u4e0b\u8f7d\u6570\u636e\uff0c\u8fd8\u662f\u8fdb\u884c\u5176\u4ed6\u8017\u65f6\u7684\u64cd\u4f5c\uff0c\u90fd\u53ef\u4ee5\u501f\u52a9\u8fdb\u5ea6\u6761\u6a21\u5757\u6765\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u548c\u53ef\u89c6\u5316\u6548\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5b89\u88c5progressbar\u6a21\u5757\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u6267\u884c\u3001\u786e\u4fdd\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u548cpip [&hellip;]","protected":false},"author":3,"featured_media":174751,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/174743"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=174743"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/174743\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/174751"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=174743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=174743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=174743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}