{"id":971883,"date":"2024-12-27T05:38:54","date_gmt":"2024-12-26T21:38:54","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/971883.html"},"modified":"2024-12-27T05:38:56","modified_gmt":"2024-12-26T21:38:56","slug":"cmd-%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8cpython%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/971883.html","title":{"rendered":"cmd \u5982\u4f55\u8fd0\u884cpython\u811a\u672c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24194808\/f0ba3fc7-7188-4b17-bd74-632a4d80281d.webp\" alt=\"cmd \u5982\u4f55\u8fd0\u884cpython\u811a\u672c\" \/><\/p>\n<p><p> \u8981\u5728\u547d\u4ee4\u63d0\u793a\u7b26\uff08cmd\uff09\u4e2d\u8fd0\u884cPython\u811a\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\uff1a<strong>\u9996\u5148\u786e\u4fdd\u5df2\u5b89\u88c5Python\u3001\u4f7f\u7528Python\u547d\u4ee4\u8fd0\u884c\u811a\u672c\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/strong>\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><p><strong>\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/strong><\/p>\n<\/p>\n<p><p>\u8981\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e0b\u8fd0\u884cPython\u811a\u672c\uff0c\u9996\u5148\u9700\u8981\u786e\u4fddPython\u5df2\u6b63\u786e\u5b89\u88c5\u5e76\u4e14\u73af\u5883\u53d8\u91cf\u5df2\u8bbe\u7f6e\u3002\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u5141\u8bb8\u60a8\u4ece\u4efb\u4f55\u76ee\u5f55\u8c03\u7528Python\uff0c\u800c\u4e0d\u9700\u8981\u6307\u5b9aPython\u7684\u5b8c\u6574\u8def\u5f84\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5728Windows\u4e0a\u8bbe\u7f6ePython\u73af\u5883\u53d8\u91cf\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u786e\u8ba4Python\u5b89\u88c5\u8def\u5f84<\/strong>\uff1a\u9996\u5148\uff0c\u786e\u4fddPython\u5df2\u5b89\u88c5\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cPython\u901a\u5e38\u5b89\u88c5\u5728<code>C:\\PythonXX<\/code>\uff0c\u5176\u4e2d<code>XX<\/code>\u8868\u793aPython\u7248\u672c\u53f7\u3002\u4f8b\u5982\uff0cPython 3.9\u53ef\u80fd\u4f1a\u5b89\u88c5\u5728<code>C:\\Python39<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6253\u5f00\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e<\/strong>\uff1a\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u6211\u7684\u7535\u8111\u201d\u56fe\u6807\uff0c\u7136\u540e\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002\u63a5\u7740\uff0c\u9009\u62e9\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u6309\u94ae\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7f16\u8f91\u7cfb\u7edf\u53d8\u91cf<\/strong>\uff1a\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u90e8\u5206\uff0c\u627e\u5230\u5e76\u9009\u62e9\u201cPath\u201d\u53d8\u91cf\uff0c\u7136\u540e\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6dfb\u52a0Python\u8def\u5f84<\/strong>\uff1a\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\u4f8b\u5982<code>C:\\Python39<\/code>\uff09\u3002\u518d\u70b9\u51fb\u201c\u65b0\u5efa\u201d\uff0c\u8f93\u5165Python\u7684Scripts\u76ee\u5f55\u8def\u5f84\uff08\u4f8b\u5982<code>C:\\Python39\\Scripts<\/code>\uff09\uff0c\u8fd9\u662f\u4e3a\u4e86\u786e\u4fdd\u53ef\u4ee5\u8fd0\u884cpip\u7b49\u5de5\u5177\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4fdd\u5b58\u8bbe\u7f6e<\/strong>\uff1a\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u66f4\u6539\uff0c\u5173\u95ed\u6240\u6709\u8bbe\u7f6e\u7a97\u53e3\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u5b8c\u6210\u4e0a\u8ff0\u6b65\u9aa4\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u76f4\u63a5\u8f93\u5165<code>python<\/code>\u6765\u68c0\u67e5\u662f\u5426\u6210\u529f\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u5982\u679c\u663e\u793aPython\u7248\u672c\u4fe1\u606f\uff0c\u5219\u8868\u660e\u8bbe\u7f6e\u6b63\u786e\u3002<\/p>\n<\/p>\n<hr>\n<p><p><strong>\u4e00\u3001\u5b89\u88c5Python<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u8fd0\u884c\u4efb\u4f55Python\u811a\u672c\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u8ba1\u7b97\u673a\u4e0a\u5df2\u5b89\u88c5Python\u3002Python\u7684\u5b89\u88c5\u76f8\u5bf9\u7b80\u5355\uff0c\u60a8\u53ef\u4ee5\u4ece\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%88%E6%82%A8%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%9A%84%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F%E3%80%82%E5%AE%89%E8%A3%85%E8%BF%87%E7%A8%8B%E4%B8%AD%EF%BC%8C%E8%AF%B7%E7%A1%AE%E4%BF%9D%E9%80%89%E6%8B%A9%E2%80%9CAdd\">https:\/\/www.python.org\/downloads\/\uff09\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u7a0b\u5e8f\u3002\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u8bf7\u786e\u4fdd\u9009\u62e9\u201cAdd<\/a> Python to PATH\u201d\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u4f7f\u7528Python\u547d\u4ee4\u3002<\/p>\n<\/p>\n<p><p><strong>\u4e8c\u3001\u7f16\u5199Python\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u8fd0\u884cPython\u811a\u672c\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u7f16\u5199\u4e00\u4e2aPython\u811a\u672c\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982Notepad\u3001Sublime Text\u3001VSCode\u7b49\uff09\u7f16\u5199\u811a\u672c\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u4e3a<code>.py<\/code>\u6269\u5c55\u540d\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>hello.py<\/code>\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4e09\u3001\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26<\/strong><\/p>\n<\/p>\n<p><p>\u8981\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u53ef\u4ee5\u6309\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6309\u4e0bWindows\u952e\uff0c\u5728\u641c\u7d22\u680f\u4e2d\u8f93\u5165\u201ccmd\u201d\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u547d\u4ee4\u63d0\u793a\u7b26\u201d\u4ee5\u6253\u5f00\u3002<\/li>\n<\/ol>\n<p><p><strong>\u56db\u3001\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230\u60a8\u7684Python\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u7684\u811a\u672c\u4f4d\u4e8e<code>C:\\Users\\YourName\\Scripts<\/code>\uff0c\u60a8\u53ef\u4ee5\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">cd C:\\Users\\YourName\\Scripts<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4e94\u3001\u8fd0\u884cPython\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5bfc\u822a\u5230\u6b63\u786e\u7684\u76ee\u5f55\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884cPython\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">python hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4e00\u5207\u8bbe\u7f6e\u6b63\u786e\uff0c\u60a8\u5c06\u770b\u5230\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u51fa<code>Hello, World!<\/code>\u3002<\/p>\n<\/p>\n<p><p><strong>\u516d\u3001\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u8fd0\u884cPython\u811a\u672c\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u201cPython\u4e0d\u662f\u5185\u90e8\u6216\u5916\u90e8\u547d\u4ee4\u201d\u9519\u8bef<\/strong>\uff1a\u5982\u679c\u51fa\u73b0\u6b64\u9519\u8bef\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a\u73af\u5883\u53d8\u91cf\u672a\u6b63\u786e\u8bbe\u7f6e\u3002\u8bf7\u786e\u4fdd\u5df2\u5c06Python\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u811a\u672c\u8fd0\u884c\u540e\u65e0\u8f93\u51fa<\/strong>\uff1a\u8bf7\u68c0\u67e5\u811a\u672c\u4e2d\u662f\u5426\u6709\u8bed\u6cd5\u9519\u8bef\uff0c\u786e\u4fdd\u811a\u672c\u6587\u4ef6\u4e2d\u5305\u542b\u6709\u6548\u7684Python\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4e0d\u540cPython\u7248\u672c\u7684\u517c\u5bb9\u6027\u95ee\u9898<\/strong>\uff1a\u5982\u679c\u60a8\u5b89\u88c5\u4e86\u591a\u4e2a\u7248\u672c\u7684Python\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u517c\u5bb9\u6027\u95ee\u9898\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528<code>python3<\/code>\u547d\u4ee4\u6765\u6307\u5b9a\u4f7f\u7528Python 3\u7248\u672c\u8fd0\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u5e94\u8be5\u80fd\u591f\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u987a\u5229\u8fd0\u884cPython\u811a\u672c\u3002\u719f\u7ec3\u638c\u63e1\u8fd9\u4e9b\u57fa\u672c\u64cd\u4f5c\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u66f4\u52a0\u9ad8\u6548\u5730\u6267\u884c\u548c\u8c03\u8bd5Python\u4ee3\u7801\u3002<\/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 \/>\u8981\u786e\u5b9a\u60a8\u7684\u8ba1\u7b97\u673a\u4e0a\u662f\u5426\u5df2\u5b89\u88c5Python\uff0c\u53ef\u4ee5\u5728CMD\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u3002\u5982\u679cPython\u5df2\u6b63\u786e\u5b89\u88c5\uff0c\u60a8\u5c06\u770b\u5230\u5f53\u524d\u7248\u672c\u53f7\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u7cfb\u7edf\u4f1a\u63d0\u793a\u60a8\u3002<\/p>\n<p><strong>\u600e\u6837\u5728CMD\u4e2d\u5bfc\u822a\u5230Python\u811a\u672c\u6240\u5728\u7684\u6587\u4ef6\u5939\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5728CMD\u4e2d\u5bfc\u822a\u5230Python\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\u3002\u6bd4\u5982\uff0c\u5982\u679c\u60a8\u7684\u811a\u672c\u4f4d\u4e8e<code>C:\\Users\\Username\\Documents\\Scripts<\/code>\uff0c\u60a8\u53ef\u4ee5\u8f93\u5165<code>cd C:\\Users\\Username\\Documents\\Scripts<\/code>\u6765\u8fdb\u5165\u8be5\u6587\u4ef6\u5939\u3002\u786e\u4fdd\u8def\u5f84\u4e0e\u60a8\u7684\u5b9e\u9645\u6587\u4ef6\u4f4d\u7f6e\u76f8\u5339\u914d\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728CMD\u4e2d\u8fd0\u884c\u7279\u5b9a\u7684Python\u811a\u672c\uff1f<\/strong><br \/>\u4e00\u65e6\u60a8\u5728CMD\u4e2d\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u6587\u4ef6\u5939\uff0c\u8fd0\u884cPython\u811a\u672c\u5f88\u7b80\u5355\u3002\u53ea\u9700\u8f93\u5165<code>python script_name.py<\/code>\uff08\u5c06<code>script_name.py<\/code>\u66ff\u6362\u4e3a\u60a8\u7684\u5b9e\u9645\u811a\u672c\u540d\u79f0\uff09\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662fPython 3\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528<code>python3 script_name.py<\/code>\u3002\u786e\u4fdd\u811a\u672c\u540d\u548c\u540e\u7f00\u90fd\u6b63\u786e\u65e0\u8bef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728\u547d\u4ee4\u63d0\u793a\u7b26\uff08cmd\uff09\u4e2d\u8fd0\u884cPython\u811a\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\uff1a\u9996\u5148\u786e\u4fdd\u5df2\u5b89\u88c5Python\u3001\u4f7f\u7528Py [&hellip;]","protected":false},"author":3,"featured_media":971887,"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\/971883"}],"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=971883"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/971883\/revisions"}],"predecessor-version":[{"id":971888,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/971883\/revisions\/971888"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/971887"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=971883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=971883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=971883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}