{"id":965775,"date":"2024-12-27T04:41:14","date_gmt":"2024-12-26T20:41:14","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/965775.html"},"modified":"2024-12-27T04:41:16","modified_gmt":"2024-12-26T20:41:16","slug":"dos%e4%b8%8b%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8cpython","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/965775.html","title":{"rendered":"dos\u4e0b\u5982\u4f55\u8fd0\u884cpython"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24181917\/f23f6a2b-3874-490d-91d1-835a31fdbce0.webp\" alt=\"dos\u4e0b\u5982\u4f55\u8fd0\u884cpython\" \/><\/p>\n<p><p> <strong>\u5728DOS\u4e0b\u8fd0\u884cPython\u9700\u8981\u786e\u4fddPython\u5df2\u6b63\u786e\u5b89\u88c5\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u6267\u884cPython\u811a\u672c\u3002<\/strong>\u9996\u5148\uff0c\u9700\u8981\u5728\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5Python\uff0c\u5e76\u786e\u4fdd\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u8c03\u7528Python\u547d\u4ee4\u3002\u63a5\u7740\uff0c\u901a\u8fc7\u547d\u4ee4\u884c\u8fdb\u5165\u5b58\u653ePython\u811a\u672c\u7684\u76ee\u5f55\uff0c\u4f7f\u7528\u547d\u4ee4<code>python scriptname.py<\/code>\u6765\u6267\u884c\u811a\u672c\u3002\u6700\u540e\uff0c\u8fd8\u9700\u8981\u786e\u4fddPython\u7248\u672c\u4e0e\u811a\u672c\u517c\u5bb9\uff0c\u5e76\u5b89\u88c5\u6240\u9700\u7684\u4f9d\u8d56\u5e93\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>\u5728DOS\uff08\u5373Windows\u7684\u547d\u4ee4\u63d0\u793a\u7b26\uff09\u4e0b\u8fd0\u884cPython\u7684\u7b2c\u4e00\u6b65\u662f\u786e\u4fddPython\u5df2\u6b63\u786e\u5b89\u88c5\u3002Python\u7684\u5b89\u88c5\u8fc7\u7a0b\u76f8\u5bf9\u7b80\u5355\uff0c\u4f46\u5728\u5b89\u88c5\u65f6\u9700\u8981\u6ce8\u610f\u4e00\u4e9b\u5173\u952e\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<ol>\n<li>\u4e0b\u8f7dPython\u5b89\u88c5\u5305<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4ecePython\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.python.org\/downloads\/%EF%BC%89%E4%B8%8B%E8%BD%BD%E9%80%82%E5%90%88Windows%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%9A%84Python%E5%AE%89%E8%A3%85%E5%8C%85%E3%80%82%E5%BB%BA%E8%AE%AE%E4%B8%8B%E8%BD%BD%E6%9C%80%E6%96%B0%E7%9A%84%E7%A8%B3%E5%AE%9A%E7%89%88%E6%9C%AC%EF%BC%8C%E4%BB%A5%E4%BE%BF%E8%8E%B7%E5%8F%96%E6%9C%80%E6%96%B0%E7%9A%84%E7%89%B9%E6%80%A7%E5%92%8C%E5%AE%89%E5%85%A8%E6%9B%B4%E6%96%B0%E3%80%82\">https:\/\/www.python.org\/downloads\/\uff09\u4e0b\u8f7d\u9002\u5408Windows\u64cd\u4f5c\u7cfb\u7edf\u7684Python\u5b89\u88c5\u5305\u3002\u5efa\u8bae\u4e0b\u8f7d\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u672c\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6700\u65b0\u7684\u7279\u6027\u548c\u5b89\u5168\u66f4\u65b0\u3002<\/a><\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u5b89\u88c5Python<\/li>\n<\/ol>\n<p><p>\u8fd0\u884c\u4e0b\u8f7d\u7684\u5b89\u88c5\u5305\uff0c\u6309\u7167\u5b89\u88c5\u5411\u5bfc\u7684\u6307\u793a\u8fdb\u884c\u5b89\u88c5\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u6709\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u9009\u9879\u9700\u8981\u6ce8\u610f\uff0c\u5373\u201cAdd Python to PATH\u201d\u3002<strong>\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\u53ef\u4ee5\u81ea\u52a8\u5c06Python\u7684\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d<\/strong>\uff0c\u8fd9\u6837\u5728\u547d\u4ee4\u884c\u4e2d\u624d\u80fd\u76f4\u63a5\u4f7f\u7528<code>python<\/code>\u547d\u4ee4\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n<\/p>\n<p><p>\u5982\u679c\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u6ca1\u6709\u52fe\u9009\u201cAdd Python to PATH\u201d\uff0c\u5219\u9700\u8981\u624b\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u7cfb\u7edf\u5c5e\u6027<\/li>\n<\/ol>\n<p><p>\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u8005\u201c\u6211\u7684\u7535\u8111\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\uff0c\u7136\u540e\u70b9\u51fb\u5de6\u4fa7\u7684\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/li>\n<\/ol>\n<p><p>\u5728\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u6309\u94ae\u3002\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u4e0b\u627e\u5230\u201cPath\u201d\u53d8\u91cf\uff0c\u9009\u4e2d\u540e\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u3002\u5728\u201c\u7f16\u8f91\u73af\u5883\u53d8\u91cf\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u65b0\u5efa\u201d\uff0c\u7136\u540e\u8f93\u5165Python\u7684\u5b89\u88c5\u8def\u5f84\uff08\u4f8b\u5982\uff1a<code>C:\\Python39<\/code>\uff09\uff0c\u4ee5\u53caPython\u7684Scripts\u76ee\u5f55\uff08\u4f8b\u5982\uff1a<code>C:\\Python39\\Scripts<\/code>\uff09\u3002\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884cPython<\/p>\n<\/p>\n<p><p>\u914d\u7f6e\u597d\u73af\u5883\u53d8\u91cf\u540e\uff0c\u5373\u53ef\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884cPython\u3002<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26<\/li>\n<\/ol>\n<p><p>\u6309\u4e0b\u201cWin + R\u201d\u952e\uff0c\u8f93\u5165\u201ccmd\u201d\uff0c\u7136\u540e\u6309\u56de\u8f66\u952e\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u7a97\u53e3\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u8fdb\u5165\u811a\u672c\u76ee\u5f55<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u8fdb\u5165\u5b58\u653ePython\u811a\u672c\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u811a\u672c\u5b58\u653e\u5728\u201cD:\\Scripts\u201d\u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u5165\u8be5\u76ee\u5f55\uff1a<\/p>\n<\/p>\n<p><pre><code>cd D:\\Scripts<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u8fd0\u884cPython\u811a\u672c<\/li>\n<\/ol>\n<p><p>\u5728\u811a\u672c\u76ee\u5f55\u4e0b\uff0c\u4f7f\u7528<code>python scriptname.py<\/code>\u547d\u4ee4\u6765\u8fd0\u884cPython\u811a\u672c\u3002\u5176\u4e2d\u201cscriptname.py\u201d\u662fPython\u811a\u672c\u7684\u6587\u4ef6\u540d\u3002\u4f8b\u5982\uff0c\u8fd0\u884c\u540d\u4e3a\u201chello.py\u201d\u7684\u811a\u672c\uff0c\u53ef\u4ee5\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code>python hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u6b64\u65f6\uff0cPython\u89e3\u91ca\u5668\u5c06\u4f1a\u6267\u884c\u811a\u672c\u4e2d\u7684\u4ee3\u7801<\/strong>\uff0c\u5e76\u5728\u547d\u4ee4\u884c\u7a97\u53e3\u4e2d\u8f93\u51fa\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u786e\u4fddPython\u7248\u672c\u517c\u5bb9<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Python\u65f6\uff0c\u786e\u4fdd\u6240\u7f16\u5199\u7684\u811a\u672c\u4e0e\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\u517c\u5bb9\u975e\u5e38\u91cd\u8981\u3002Python 2\u548cPython 3\u4e4b\u95f4\u5b58\u5728\u4e00\u4e9b\u4e0d\u517c\u5bb9\u7684\u53d8\u5316\uff0c\u56e0\u6b64\u5728\u7f16\u5199\u548c\u8fd0\u884c\u811a\u672c\u65f6\u9700\u8981\u683c\u5916\u6ce8\u610f\u3002<\/p>\n<\/p>\n<ol>\n<li>\u68c0\u67e5Python\u7248\u672c<\/li>\n<\/ol>\n<p><p>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u53ef\u4ee5\u68c0\u67e5\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code>python --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u547d\u4ee4\u5c06\u4f1a\u8f93\u51fa\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\u53f7\uff0c\u4f8b\u5982\u201cPython 3.9.7\u201d\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u811a\u672c\u7684\u517c\u5bb9\u6027<\/li>\n<\/ol>\n<p><p>\u5728\u7f16\u5199Python\u811a\u672c\u65f6\uff0c\u9700\u8981\u6839\u636e\u5f53\u524d\u4f7f\u7528\u7684Python\u7248\u672c\u7f16\u5199\u4ee3\u7801\u3002<strong>\u786e\u4fdd\u811a\u672c\u7684\u8bed\u6cd5\u548c\u4f7f\u7528\u7684\u5e93\u4e0e\u5f53\u524d\u7684Python\u7248\u672c\u517c\u5bb9<\/strong>\uff0c\u5426\u5219\u53ef\u80fd\u4f1a\u5bfc\u81f4\u811a\u672c\u65e0\u6cd5\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u5b89\u88c5\u6240\u9700\u7684\u4f9d\u8d56\u5e93<\/p>\n<\/p>\n<p><p>\u6709\u4e9bPython\u811a\u672c\u9700\u8981\u4f9d\u8d56\u7279\u5b9a\u7684\u5e93\u624d\u80fd\u6b63\u5e38\u8fd0\u884c\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u4f7f\u7528Python\u7684\u5305\u7ba1\u7406\u5de5\u5177<code>pip<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528pip\u5b89\u88c5\u5e93<\/li>\n<\/ol>\n<p><p>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\uff0c\u4f7f\u7528<code>pip install<\/code>\u547d\u4ee4\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002\u4f8b\u5982\uff0c\u5b89\u88c5\u540d\u4e3a\u201crequests\u201d\u7684\u5e93\uff0c\u53ef\u4ee5\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code>pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u786e\u4fdd\u7f51\u7edc\u8fde\u63a5<\/li>\n<\/ol>\n<p><p>\u5728\u5b89\u88c5\u5e93\u65f6\uff0c\u786e\u4fdd\u8ba1\u7b97\u673a\u6709\u826f\u597d\u7684\u7f51\u7edc\u8fde\u63a5\uff0c\u56e0\u4e3a<code>pip<\/code>\u9700\u8981\u4ecePython\u7684\u5b98\u65b9\u5305\u7ba1\u7406\u670d\u52a1\u5668\u4e0b\u8f7d\u6240\u9700\u7684\u5e93\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u5373\u53ef\u5728DOS\u4e0b\u6210\u529f\u8fd0\u884cPython\u811a\u672c\u3002\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c\u4e0d\u4ec5\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u6d4b\u8bd5\u548c\u8c03\u8bd5\u4ee3\u7801\uff0c\u8fd8\u80fd\u5728\u81ea\u52a8\u5316\u4efb\u52a1\u548c\u6570\u636e\u5904\u7406\u7b49\u65b9\u9762\u53d1\u6325\u91cd\u8981\u4f5c\u7528\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728DOS\u4e0b\u5b89\u88c5Python\u4ee5\u4fbf\u8fd0\u884c\uff1f<\/strong><br \/>\u5728DOS\u73af\u5883\u4e2d\u8fd0\u884cPython\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u5148\u5b89\u88c5Python\u3002\u60a8\u53ef\u4ee5\u4ecePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u7248\u672c\u3002\u4e0b\u8f7d\u540e\uff0c\u6309\u7167\u63d0\u793a\u8fdb\u884c\u5b89\u88c5\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u8bf7\u786e\u4fdd\u9009\u62e9\u5c06Python\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u8fd9\u6837\u60a8\u624d\u80fd\u5728DOS\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u8fd0\u884cPython\u3002<\/p>\n<p><strong>\u5728DOS\u4e0b\u8fd0\u884cPython\u811a\u672c\u7684\u547d\u4ee4\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u8981\u5728DOS\u4e0b\u8fd0\u884cPython\u811a\u672c\uff0c\u60a8\u9700\u8981\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u7a97\u53e3\uff0c\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\u3002\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u66f4\u6539\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u7684\u811a\u672c\u5728D\u76d8\u7684\u201cscripts\u201d\u6587\u4ef6\u5939\u4e2d\uff0c\u53ef\u4ee5\u8f93\u5165<code>D:<\/code>\u7136\u540e<code>cd scripts<\/code>\u3002\u63a5\u7740\uff0c\u8f93\u5165<code>python your_script.py<\/code>\u6765\u8fd0\u884c\u811a\u672c\uff0c\u5176\u4e2d<code>your_script.py<\/code>\u662f\u60a8\u8981\u6267\u884c\u7684\u6587\u4ef6\u540d\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728DOS\u4e0b\u8c03\u8bd5Python\u4ee3\u7801\uff1f<\/strong><br \/>\u5728DOS\u4e0b\u8c03\u8bd5Python\u4ee3\u7801\u65f6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>print()<\/code>\u51fd\u6570\u6765\u8f93\u51fa\u53d8\u91cf\u7684\u503c\u6216\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b\u3002\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u8c03\u8bd5\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Python\u81ea\u5e26\u7684\u8c03\u8bd5\u5de5\u5177<code>pdb<\/code>\u3002\u5728\u60a8\u7684Python\u811a\u672c\u4e2d\uff0c\u63d2\u5165<code>import pdb; pdb.set_trace()<\/code>\uff0c\u7136\u540e\u8fd0\u884c\u811a\u672c\u3002\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u60a8\u5c06\u80fd\u591f\u9010\u884c\u6267\u884c\u4ee3\u7801\u5e76\u68c0\u67e5\u53d8\u91cf\u72b6\u6001\uff0c\u5e2e\u52a9\u60a8\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728DOS\u4e0b\u8fd0\u884cPython\u9700\u8981\u786e\u4fddPython\u5df2\u6b63\u786e\u5b89\u88c5\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u6267\u884cPython\u811a\u672c\u3002\u9996\u5148\uff0c [&hellip;]","protected":false},"author":3,"featured_media":965785,"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\/965775"}],"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=965775"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/965775\/revisions"}],"predecessor-version":[{"id":965790,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/965775\/revisions\/965790"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/965785"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=965775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=965775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=965775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}