{"id":995471,"date":"2024-12-27T09:05:08","date_gmt":"2024-12-27T01:05:08","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/995471.html"},"modified":"2024-12-27T09:05:10","modified_gmt":"2024-12-27T01:05:10","slug":"cmd%e4%b8%ad%e5%a6%82%e4%bd%95%e8%b0%83%e5%87%bapython","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/995471.html","title":{"rendered":"cmd\u4e2d\u5982\u4f55\u8c03\u51fapython"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25072054\/adb9aae3-6c9e-4468-9dff-7dba34ea71b6.webp\" alt=\"cmd\u4e2d\u5982\u4f55\u8c03\u51fapython\" \/><\/p>\n<p><p> <strong>\u5728Windows\u547d\u4ee4\u63d0\u793a\u7b26\uff08CMD\uff09\u4e2d\u8c03\u51faPython\u7684\u65b9\u6cd5\u6709\uff1a\u5b89\u88c5Python\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528<code>python<\/code>\u547d\u4ee4\u3002<\/strong> \u5176\u4e2d\uff0c\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u662f\u786e\u4fdd\u5728\u4efb\u4f55\u547d\u4ee4\u63d0\u793a\u7b26\u7a97\u53e3\u4e2d\u90fd\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>python<\/code>\u547d\u4ee4\u7684\u5173\u952e\u6b65\u9aa4\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728CMD\u4e2d\u8c03\u51faPython\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>\u8981\u5728CMD\u4e2d\u4f7f\u7528Python\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u4f60\u7684\u8ba1\u7b97\u673a\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u3002\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7dPython\u5b89\u88c5\u7a0b\u5e8f<\/strong>\uff1a\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.python.org\/%EF%BC%89%E4%B8%8B%E8%BD%BD%E9%80%82%E7%94%A8%E4%BA%8EWindows%E7%B3%BB%E7%BB%9F%E7%9A%84Python%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F%E3%80%82%E9%80%9A%E5%B8%B8%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%E3%80%82\">https:\/\/www.python.org\/\uff09\u4e0b\u8f7d\u9002\u7528\u4e8eWindows\u7cfb\u7edf\u7684Python\u5b89\u88c5\u7a0b\u5e8f\u3002\u901a\u5e38\u5efa\u8bae\u4e0b\u8f7d\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u672c\u3002<\/a><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f<\/strong>\uff1a\u53cc\u51fb\u4e0b\u8f7d\u7684\u5b89\u88c5\u7a0b\u5e8f\u4ee5\u5f00\u59cb\u5b89\u88c5\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u52a1\u5fc5\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\u3002\u8fd9\u5c06\u81ea\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u4f7f\u5f97Python\u53ef\u4ee5\u5728CMD\u4e2d\u88ab\u8c03\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b8c\u6210\u5b89\u88c5<\/strong>\uff1a\u6309\u7167\u5b89\u88c5\u5411\u5bfc\u7684\u63d0\u793a\u5b8c\u6210\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u5f00\u59cb\u83dc\u5355\u4e2d\u627e\u5230Python\u76f8\u5173\u7684\u5feb\u6377\u65b9\u5f0f\uff0c\u4f8b\u5982IDLE\u548cPython\u547d\u4ee4\u884c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\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\u4e5f\u53ef\u4ee5\u624b\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u7cfb\u7edf\u5c5e\u6027<\/strong>\uff1a\u53f3\u952e\u5355\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u8ba1\u7b97\u673a\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fdb\u5165\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e<\/strong>\uff1a\u5728\u7cfb\u7edf\u5c5e\u6027\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6253\u5f00\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e<\/strong>\uff1a\u5728\u201c\u9ad8\u7ea7\u201d\u9009\u9879\u5361\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u6309\u94ae\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7f16\u8f91PATH\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\u7f16\u8f91\u73af\u5883\u53d8\u91cf\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u65b0\u5efa\u201d\uff0c\u7136\u540e\u8f93\u5165Python\u5b89\u88c5\u76ee\u5f55\u7684\u8def\u5f84\uff08\u4f8b\u5982C:\\Python39\\\uff0c\u5177\u4f53\u8def\u5f84\u6839\u636e\u4f60\u7684\u5b89\u88c5\u4f4d\u7f6e\u800c\u5b9a\uff09\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u8981\u6dfb\u52a0Python\u7684Scripts\u76ee\u5f55\u8def\u5f84\uff08\u4f8b\u5982C:\\Python39\\Scripts\\\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4fdd\u5b58\u5e76\u9000\u51fa<\/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>\u4e09\u3001\u4f7f\u7528<code>python<\/code>\u547d\u4ee4<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00CMD<\/strong>\uff1a\u6309\u4e0bWin + R\u952e\uff0c\u8f93\u5165<code>cmd<\/code>\uff0c\u7136\u540e\u6309Enter\u952e\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u7a97\u53e3\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8f93\u5165Python\u547d\u4ee4<\/strong>\uff1a\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u7a97\u53e3\u4e2d\uff0c\u8f93\u5165<code>python<\/code>\u5e76\u6309Enter\u952e\u3002\u5982\u679c\u4e00\u5207\u914d\u7f6e\u6b63\u786e\uff0cPython\u89e3\u91ca\u5668\u5c06\u542f\u52a8\uff0c\u5e76\u663e\u793aPython\u7248\u672c\u4fe1\u606f\u548c\u63d0\u793a\u7b26\uff08&gt;&gt;&gt;\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6267\u884cPython\u4ee3\u7801<\/strong>\uff1a\u5728\u63d0\u793a\u7b26\u4e0b\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u5e76\u6267\u884c\u3002\u4f8b\u5982\uff0c\u8f93\u5165<code>print(&quot;Hello, World!&quot;)<\/code>\uff0c\u7136\u540e\u6309Enter\u952e\uff0cCMD\u5c06\u8f93\u51fa<code>Hello, World!<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5b89\u88c5\u591a\u4e2a\u7248\u672c\u7684Python<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u5728\u540c\u4e00\u53f0\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5\u591a\u4e2a\u7248\u672c\u7684Python\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528Python Launcher<\/strong>\uff1aPython\u5b89\u88c5\u5305\u901a\u5e38\u5305\u542b\u4e00\u4e2aPython Launcher\uff0c\u5b83\u5141\u8bb8\u4f60\u9009\u62e9\u4e0d\u540c\u7248\u672c\u7684Python\u8fdb\u884c\u542f\u52a8\u3002\u5728CMD\u4e2d\u4f7f\u7528<code>py -2<\/code>\u6216<code>py -3<\/code>\u547d\u4ee4\u5206\u522b\u542f\u52a8Python 2.x\u62163.x\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u4f7f\u7528<code>venv<\/code>\u6a21\u5757\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u53ef\u4ee5\u5728\u540c\u4e00\u53f0\u8ba1\u7b97\u673a\u4e0a\u7ba1\u7406\u591a\u4e2aPython\u9879\u76ee\u53ca\u5176\u4f9d\u8d56\uff0c\u800c\u4e0d\u4f1a\u53d1\u751f\u51b2\u7a81\u3002\u5728CMD\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u865a\u62df\u73af\u5883\u5e76\u6fc0\u6d3b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv myenv<\/p>\n<p>myenv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6307\u5b9a\u8def\u5f84<\/strong>\uff1a\u5728CMD\u4e2d\u76f4\u63a5\u6307\u5b9aPython\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84\u6765\u542f\u52a8\u7279\u5b9a\u7248\u672c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">C:\\Python37\\python.exe<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5e38\u89c1\u95ee\u9898\u89e3\u51b3<\/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\u901a\u5e38\u662f\u56e0\u4e3a\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u4e0d\u6b63\u786e\u3002\u68c0\u67e5\u5e76\u786e\u4fddPython\u7684\u5b89\u88c5\u8def\u5f84\u5df2\u6b63\u786e\u6dfb\u52a0\u5230\u7cfb\u7edfPATH\u4e2d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Python\u7248\u672c\u4e0d\u5339\u914d<\/strong>\uff1a\u5982\u679c\u542f\u52a8\u7684Python\u7248\u672c\u4e0e\u9884\u671f\u4e0d\u7b26\uff0c\u53ef\u80fd\u662f\u56e0\u4e3aPATH\u4e2d\u6709\u591a\u4e2aPython\u8def\u5f84\u3002\u53ef\u4ee5\u901a\u8fc7<code>where python<\/code>\u547d\u4ee4\u67e5\u770b\u6240\u6709\u53ef\u7528\u7684Python\u8def\u5f84\uff0c\u5e76\u6839\u636e\u9700\u8981\u8c03\u6574PATH\u7684\u987a\u5e8f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u547d\u4ee4\u63d0\u793a\u7b26\u65e0\u6cd5\u8bc6\u522bPython\u547d\u4ee4<\/strong>\uff1a\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0cCMD\u53ef\u80fd\u65e0\u6cd5\u8bc6\u522b<code>python<\/code>\u547d\u4ee4\u3002\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528<code>py<\/code>\u547d\u4ee4\u6765\u542f\u52a8Python\uff0c\u8fd9\u901a\u5e38\u80fd\u591f\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u5e94\u8be5\u80fd\u591f\u987a\u5229\u5728Windows CMD\u4e2d\u8c03\u51faPython\u5e76\u6267\u884cPython\u4ee3\u7801\u3002\u786e\u4fdd\u6b63\u786e\u5b89\u88c5\u548c\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u662f\u6210\u529f\u7684\u5173\u952e\u3002\u4f7f\u7528Python Launcher\u548c\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u548c\u9879\u76ee\u4f9d\u8d56\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\u8ba4Python\u662f\u5426\u5df2\u7ecf\u5b89\u88c5\u5728\u60a8\u7684\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u5728CMD\uff08\u547d\u4ee4\u63d0\u793a\u7b26\uff09\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python -V<\/code>\u3002\u5982\u679cPython\u5df2\u5b89\u88c5\uff0c\u5c06\u663e\u793a\u5f53\u524d\u7684Python\u7248\u672c\u4fe1\u606f\u3002\u5982\u679c\u672a\u5b89\u88c5\uff0c\u7cfb\u7edf\u4f1a\u63d0\u793a\u201c\u672a\u627e\u5230\u547d\u4ee4\u201d\u3002<\/p>\n<p><strong>\u5728CMD\u4e2d\u5982\u4f55\u542f\u52a8Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\uff1f<\/strong><br \/>\u5728CMD\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165<code>python<\/code>\u6765\u542f\u52a8Python\u7684\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u3002\u8fd9\u65f6\uff0c\u60a8\u5c06\u770b\u5230Python\u7684\u7248\u672c\u4fe1\u606f\u4ee5\u53ca\u63d0\u793a\u7b26\uff08\u901a\u5e38\u662f<code>&gt;&gt;&gt;<\/code>\uff09\uff0c\u60a8\u53ef\u4ee5\u5728\u6b64\u8f93\u5165Python\u4ee3\u7801\u8fdb\u884c\u6d4b\u8bd5\u548c\u5b9e\u9a8c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728CMD\u4e2d\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u8981\u5728CMD\u4e2d\u8fd0\u884c\u4e00\u4e2aPython\u811a\u672c\uff0c\u60a8\u9700\u8981\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\u3002\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5207\u6362\u5230\u8be5\u76ee\u5f55\u540e\uff0c\u8f93\u5165<code>python script_name.py<\/code>\uff08\u5c06<code>script_name.py<\/code>\u66ff\u6362\u4e3a\u60a8\u7684\u811a\u672c\u6587\u4ef6\u540d\uff09\u5373\u53ef\u6267\u884c\u811a\u672c\u3002\u5982\u679c\u811a\u672c\u8fd0\u884c\u6b63\u5e38\uff0c\u5c06\u663e\u793a\u5176\u8f93\u51fa\u6216\u7ed3\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Windows\u547d\u4ee4\u63d0\u793a\u7b26\uff08CMD\uff09\u4e2d\u8c03\u51faPython\u7684\u65b9\u6cd5\u6709\uff1a\u5b89\u88c5Python\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528pytho [&hellip;]","protected":false},"author":3,"featured_media":995483,"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\/995471"}],"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=995471"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/995471\/revisions"}],"predecessor-version":[{"id":995487,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/995471\/revisions\/995487"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/995483"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=995471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=995471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=995471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}