{"id":1016159,"date":"2024-12-27T12:14:04","date_gmt":"2024-12-27T04:14:04","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1016159.html"},"modified":"2024-12-27T12:14:06","modified_gmt":"2024-12-27T04:14:06","slug":"%e5%9c%a8cmd%e5%a6%82%e4%bd%95%e6%bf%80%e6%b4%bbpython","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1016159.html","title":{"rendered":"\u5728cmd\u5982\u4f55\u6fc0\u6d3bpython"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25095813\/0256be42-5acd-43f7-8c53-c47e58d33e6d.webp\" alt=\"\u5728cmd\u5982\u4f55\u6fc0\u6d3bpython\" \/><\/p>\n<p><p> \u5728Windows\u7684\u547d\u4ee4\u63d0\u793a\u7b26\uff08cmd\uff09\u4e2d\u6fc0\u6d3bPython\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u6765\u5b8c\u6210\uff1a<strong>\u5b89\u88c5Python\u5e76\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528Python\u89e3\u91ca\u5668\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883<\/strong>\u3002\u9996\u5148\uff0c\u786e\u4fddPython\u5df2\u7ecf\u6b63\u786e\u5b89\u88c5\u5e76\u914d\u7f6e\u5728\u4f60\u7684\u8ba1\u7b97\u673a\u4e0a\u3002\u63a5\u4e0b\u6765\uff0c\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728cmd\u4e2d\u6fc0\u6d3b\u548c\u4f7f\u7528Python\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5PYTHON\u5e76\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n<\/p>\n<p><p>\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u8981\u5728cmd\u4e2d\u6210\u529f\u6fc0\u6d3bPython\uff0c\u9996\u5148\u9700\u8981\u786e\u4fddPython\u5df2\u7ecf\u5b89\u88c5\u5728\u4f60\u7684\u8ba1\u7b97\u673a\u4e0a\uff0c\u5e76\u4e14\u73af\u5883\u53d8\u91cf\u5df2\u7ecf\u6b63\u786e\u914d\u7f6e\u3002\u5b89\u88c5Python\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u4ecePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u9002\u5408\u4f60\u7cfb\u7edf\u7248\u672c\u7684\u5b89\u88c5\u5305\uff0c\u5e76\u6309\u7167\u63d0\u793a\u5b8c\u6210\u5b89\u88c5\u5373\u53ef\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u6ce8\u610f\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u8fd9\u4f1a\u81ea\u52a8\u5c06Python\u7684\u53ef\u6267\u884c\u6587\u4ef6\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u5982\u679c\u5b89\u88c5\u65f6\u6ca1\u6709\u52fe\u9009\u6b64\u9009\u9879\uff0c\u53ef\u4ee5\u624b\u52a8\u6dfb\u52a0\u3002\u5177\u4f53\u64cd\u4f5c\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u201c\u63a7\u5236\u9762\u677f\u201d\uff0c\u9009\u62e9\u201c\u7cfb\u7edf\u548c\u5b89\u5168\u201d\uff0c\u518d\u9009\u62e9\u201c\u7cfb\u7edf\u201d\uff0c\u7136\u540e\u70b9\u51fb\u5de6\u4fa7\u7684\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002<\/li>\n<li>\u5728\u7cfb\u7edf\u5c5e\u6027\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u6309\u94ae\u3002<\/li>\n<li>\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u90e8\u5206\uff0c\u627e\u5230\u5e76\u9009\u62e9\u201cPath\u201d\u53d8\u91cf\uff0c\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u3002<\/li>\n<li>\u5728\u201c\u7f16\u8f91\u73af\u5883\u53d8\u91cf\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u65b0\u5efa\u201d\uff0c\u7136\u540e\u8f93\u5165Python\u5b89\u88c5\u76ee\u5f55\u7684\u8def\u5f84\uff08\u901a\u5e38\u662fC:\\PythonXX\uff0c\u5176\u4e2dXX\u4e3aPython\u7248\u672c\u53f7\uff09\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u66f4\u6539\u5e76\u5173\u95ed\u6240\u6709\u7a97\u53e3\u3002<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528PYTHON\u89e3\u91ca\u5668<\/p>\n<\/p>\n<p><p>\u4e00\u65e6Python\u5b89\u88c5\u5e76\u914d\u7f6e\u5b8c\u6bd5\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7cmd\u6765\u6fc0\u6d3bPython\u89e3\u91ca\u5668\u3002Python\u89e3\u91ca\u5668\u662f\u4e00\u4e2a\u53ef\u4ee5\u76f4\u63a5\u6267\u884cPython\u4ee3\u7801\u7684\u4ea4\u4e92\u5f0f\u73af\u5883\u3002\u8981\u5728cmd\u4e2d\u6fc0\u6d3bPython\u89e3\u91ca\u5668\uff0c\u53ea\u9700\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165<code>python<\/code>\u5e76\u6309\u4e0b\u56de\u8f66\u952e\u3002\u5982\u679c\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u6b63\u786e\uff0ccmd\u4f1a\u542f\u52a8Python\u89e3\u91ca\u5668\uff0c\u5e76\u663e\u793aPython\u7248\u672c\u548c\u7248\u6743\u4fe1\u606f\u3002\u4f60\u4f1a\u770b\u5230\u4e00\u4e2a<code>&gt;&gt;&gt;<\/code>\u63d0\u793a\u7b26\uff0c\u8fd9\u8868\u793a\u4f60\u73b0\u5728\u53ef\u4ee5\u8f93\u5165Python\u4ee3\u7801\u8fdb\u884c\u4ea4\u4e92\u5f0f\u7f16\u7a0b\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528Python\u89e3\u91ca\u5668\u7684\u4e00\u4e2a\u597d\u5904\u662f\uff0c\u4f60\u53ef\u4ee5\u7acb\u5373\u6d4b\u8bd5\u548c\u8fd0\u884cPython\u4ee3\u7801\uff0c\u800c\u65e0\u9700\u521b\u5efa\u548c\u4fdd\u5b58Python\u811a\u672c\u6587\u4ef6\u3002\u8fd9\u5bf9\u4e8e\u5b66\u4e60Python\u548c\u5feb\u901f\u9a8c\u8bc1\u4ee3\u7801\u7247\u6bb5\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1Python\u9879\u76ee\u65f6\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5e2e\u52a9\u4f60\u521b\u5efa\u4e00\u4e2a\u4e0e\u7cfb\u7edf\u73af\u5883\u9694\u79bb\u7684Python\u73af\u5883\u3002\u8fd9\u5bf9\u4e8e\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\u548c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5e93\u7248\u672c\u51b2\u7a81\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u9996\u5148\uff0c\u5728cmd\u4e2d\u5bfc\u822a\u5230\u4f60\u7684\u9879\u76ee\u76ee\u5f55\uff0c\u7136\u540e\u8f93\u5165<code>python -m venv env<\/code>\uff0c\u5176\u4e2d<code>env<\/code>\u662f\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\u3002\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>env<\/code>\u7684\u76ee\u5f55\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u865a\u62df\u73af\u5883\u7684\u6240\u6709\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728cmd\u4e2d\u8f93\u5165<code>.\\env\\Scripts\\activate<\/code>\uff0c\u4f60\u4f1a\u770b\u5230\u547d\u4ee4\u63d0\u793a\u7b26\u7684\u524d\u9762\u51fa\u73b0<code>(env)<\/code>\uff0c\u8fd9\u8868\u793a\u865a\u62df\u73af\u5883\u5df2\u7ecf\u6fc0\u6d3b\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u9879\u76ee\u4f9d\u8d56<\/strong>\uff1a\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u6765\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u4f9d\u8d56\u5e93\u3002\u4f8b\u5982\uff0c\u8f93\u5165<code>pip install requests<\/code>\u6765\u5b89\u88c5requests\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5b8c\u6210\u5de5\u4f5c\u540e\uff0c\u8f93\u5165<code>deactivate<\/code>\u6765\u9000\u51fa\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u786e\u4fdd\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\u4e0d\u4f1a\u5f71\u54cd\u5168\u5c40Python\u73af\u5883\uff0c\u4ece\u800c\u63d0\u9ad8\u9879\u76ee\u7684\u53ef\u79fb\u690d\u6027\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5e38\u89c1\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528cmd\u6fc0\u6d3bPython\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u53ca\u5176\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>&#39;python&#39;\u4e0d\u662f\u5185\u90e8\u6216\u5916\u90e8\u547d\u4ee4<\/strong>\uff1a\u8fd9\u901a\u5e38\u662f\u7531\u4e8ePython\u672a\u6b63\u786e\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u8bf7\u68c0\u67e5\u5e76\u786e\u4fddPython\u7684\u5b89\u88c5\u8def\u5f84\u5df2\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u7684<code>Path<\/code>\u4e2d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7248\u672c\u51b2\u7a81<\/strong>\uff1a\u5982\u679c\u4f60\u7684\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5\u4e86\u591a\u4e2a\u7248\u672c\u7684Python\uff0ccmd\u53ef\u80fd\u4f1a\u9ed8\u8ba4\u4f7f\u7528\u65e7\u7248\u672c\u3002\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9aPython\u7248\u672c\u6765\u89e3\u51b3\uff0c\u4f8b\u5982\u4f7f\u7528<code>python3<\/code>\u6765\u8c03\u7528Python 3.x\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6743\u9650\u95ee\u9898<\/strong>\uff1a\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884ccmd\uff0c\u4ee5\u786e\u4fdd\u6709\u8db3\u591f\u7684\u6743\u9650\u6765\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u6216\u5b89\u88c5Python\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\u548c\u6280\u5de7\uff0c\u4f60\u53ef\u4ee5\u5728cmd\u4e2d\u987a\u5229\u6fc0\u6d3bPython\u5e76\u5f00\u59cb\u4f7f\u7528\u5b83\u8fdb\u884c\u7f16\u7a0b\u3002\u5e0c\u671b\u8fd9\u4e9b\u4fe1\u606f\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728cmd\u4e2d\u68c0\u67e5Python\u662f\u5426\u5df2\u5b89\u88c5\uff1f<\/strong><br \/>\u5728cmd\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python -V<\/code>\u53ef\u4ee5\u5feb\u901f\u68c0\u67e5Python\u662f\u5426\u5df2\u5b89\u88c5\u3002\u5982\u679c\u5b89\u88c5\u6210\u529f\uff0c\u7cfb\u7edf\u4f1a\u8fd4\u56dePython\u7684\u7248\u672c\u4fe1\u606f\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u7cfb\u7edf\u5c06\u63d0\u793a\u201c\u672a\u627e\u5230\u547d\u4ee4\u201d\u3002<\/p>\n<p><strong>\u5728cmd\u4e2d\u5982\u4f55\u5b89\u88c5Python\uff1f<\/strong><br \/>\u8981\u5728cmd\u4e2d\u5b89\u88c5Python\uff0c\u60a8\u9700\u8981\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff0c\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u5305\u3002\u5728\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f\uff0c\u5e76\u786e\u4fdd\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u52fe\u9009\u201c\u5c06Python\u6dfb\u52a0\u5230PATH\u201d\u9009\u9879\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u5728cmd\u4e2d\u8f93\u5165<code>python<\/code>\u6765\u542f\u52a8Python\u89e3\u91ca\u5668\u3002<\/p>\n<p><strong>\u5728cmd\u4e2d\u5982\u4f55\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u8981\u5728cmd\u4e2d\u8fd0\u884cPython\u811a\u672c\uff0c\u9996\u5148\u9700\u8981\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\u3002\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5207\u6362\u76ee\u5f55\uff0c\u4f8b\u5982<code>cd C:\\path\\to\\your\\script<\/code>\u3002\u7136\u540e\uff0c\u8f93\u5165<code>python script_name.py<\/code>\uff0c\u5c06<code>script_name.py<\/code>\u66ff\u6362\u4e3a\u60a8\u7684\u811a\u672c\u6587\u4ef6\u540d\uff0c\u6309\u4e0b\u56de\u8f66\u952e\u5373\u53ef\u6267\u884c\u3002\u786e\u4fdd\u5728\u8fd0\u884c\u811a\u672c\u4e4b\u524d\uff0c\u5df2\u7ecf\u5b89\u88c5\u4e86\u76f8\u5e94\u7684Python\u73af\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Windows\u7684\u547d\u4ee4\u63d0\u793a\u7b26\uff08cmd\uff09\u4e2d\u6fc0\u6d3bPython\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u6765\u5b8c\u6210\uff1a\u5b89\u88c5Python\u5e76\u8bbe\u7f6e [&hellip;]","protected":false},"author":3,"featured_media":1016167,"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\/1016159"}],"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=1016159"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1016159\/revisions"}],"predecessor-version":[{"id":1016169,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1016159\/revisions\/1016169"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1016167"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1016159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1016159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1016159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}