{"id":1076317,"date":"2025-01-08T11:52:15","date_gmt":"2025-01-08T03:52:15","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1076317.html"},"modified":"2025-01-08T11:52:17","modified_gmt":"2025-01-08T03:52:17","slug":"%e5%91%bd%e4%bb%a4%e6%8f%90%e7%a4%ba%e7%ac%a6%e5%a6%82%e4%bd%95%e8%be%93%e5%85%a5python-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1076317.html","title":{"rendered":"\u547d\u4ee4\u63d0\u793a\u7b26\u5982\u4f55\u8f93\u5165python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24180943\/4a5232f3-f198-480e-9801-df14bd306fe5.webp\" alt=\"\u547d\u4ee4\u63d0\u793a\u7b26\u5982\u4f55\u8f93\u5165python\" \/><\/p>\n<p><p> <strong>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u8f93\u5165Python\u7684\u65b9\u6cd5\u6709\uff1a\u5b89\u88c5Python\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c\u3001\u4f7f\u7528Python\u4ea4\u4e92\u6a21\u5f0f\u3002<\/strong> \u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u4e4b\u4e00\u662f\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c\uff0c\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u64cd\u4f5c\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<p><p>\u8981\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165Python\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u4f60\u7684\u8ba1\u7b97\u673a\u5df2\u7ecf\u5b89\u88c5\u4e86Python\uff0c\u5e76\u4e14\u6b63\u786e\u914d\u7f6e\u4e86\u73af\u5883\u53d8\u91cf\u3002\u63a5\u4e0b\u6765\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u63d0\u793a\u7b26\u8fd0\u884cPython\u811a\u672c\uff0c\u4e5f\u53ef\u4ee5\u8fdb\u5165Python\u4ea4\u4e92\u6a21\u5f0f\u8fdb\u884c\u5373\u65f6\u7f16\u7a0b\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5Python<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5728\u7535\u8111\u4e0a\u5b89\u88c5\u4e86Python\u3002\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5Python\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7dPython\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u8bbf\u95ee<a href=\"https:\/\/www.python.org\/\">Python\u5b98\u65b9\u7f51\u9875<\/a>\uff0c\u4e0b\u8f7d\u9002\u7528\u4e8e\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684\u6700\u65b0\u7248\u672c\u3002<\/li>\n<li>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u6839\u636e\u63d0\u793a\u8fdb\u884c\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u65f6\u9009\u4e2d\u201cAdd Python to PATH\u201d\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u5b89\u88c5\u754c\u9762\u4e0a\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u8fd9\u6837\u53ef\u4ee5\u81ea\u52a8\u5c06Python\u6dfb\u52a0\u5230\u7cfb\u7edf\u8def\u5f84\u4e2d\uff0c\u65b9\u4fbf\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u76f4\u63a5\u8c03\u7528Python\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u672a\u52fe\u9009\u201cAdd Python to PATH\u201d\uff0c\u6216\u8005\u9700\u8981\u624b\u52a8\u6dfb\u52a0Python\u8def\u5f84\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u914d\u7f6e\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u627e\u5230Python\u5b89\u88c5\u76ee\u5f55\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u901a\u5e38\u5b89\u88c5\u5728 <code>C:\\Users\\&lt;\u7528\u6237\u540d&gt;\\AppData\\Local\\Programs\\Python\\Python&lt;\u7248\u672c\u53f7&gt;<\/code> \u76ee\u5f55\u4e0b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u8ba1\u7b97\u673a\u201d\u56fe\u6807\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u6309\u94ae\u3002<\/li>\n<li>\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u4e2d\u627e\u5230 <code>Path<\/code> \u53d8\u91cf\uff0c\u70b9\u51fb\u7f16\u8f91\uff0c\u5c06Python\u5b89\u88c5\u76ee\u5f55\u8def\u5f84\u6dfb\u52a0\u8fdb\u53bb\u3002<\/li>\n<li>\u4fdd\u5b58\u5e76\u5173\u95ed\u6240\u6709\u5bf9\u8bdd\u6846\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u4e00\u65e6Python\u6b63\u786e\u5b89\u88c5\u5e76\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u4f60\u53ef\u4ee5\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165Python\u547d\u4ee4\u6765\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u6309 <code>Win + R<\/code> \u6253\u5f00\u8fd0\u884c\u7a97\u53e3\uff0c\u8f93\u5165 <code>cmd<\/code> \u5e76\u6309\u56de\u8f66\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u811a\u672c\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5bfc\u822a\u5230\u5305\u542bPython\u811a\u672c\u7684\u76ee\u5f55\uff0c\u4f8b\u5982 <code>cd C:\\path\\to\\your\\script<\/code>\u3002<\/li>\n<li>\u8f93\u5165 <code>python script_name.py<\/code> \u5e76\u6309\u56de\u8f66\uff0c\u4ee5\u8fd0\u884c\u540d\u4e3a <code>script_name.py<\/code> \u7684Python\u811a\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u4f7f\u7528Python\u4ea4\u4e92\u6a21\u5f0f<\/h3>\n<\/p>\n<p><p>Python\u8fd8\u63d0\u4f9b\u4e86\u4ea4\u4e92\u6a21\u5f0f\uff0c\u8ba9\u4f60\u53ef\u4ee5\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u5e76\u7acb\u5373\u67e5\u770b\u7ed3\u679c\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u6309 <code>Win + R<\/code> \u6253\u5f00\u8fd0\u884c\u7a97\u53e3\uff0c\u8f93\u5165 <code>cmd<\/code> \u5e76\u6309\u56de\u8f66\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8fdb\u5165Python\u4ea4\u4e92\u6a21\u5f0f\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165 <code>python<\/code> \u5e76\u6309\u56de\u8f66\uff0c\u8fdb\u5165Python\u4ea4\u4e92\u6a21\u5f0f\u3002<\/li>\n<li>\u4f60\u4f1a\u770b\u5230Python\u7248\u672c\u4fe1\u606f\u548c\u63d0\u793a\u7b26 <code>&gt;&gt;&gt;<\/code>\uff0c\u8868\u793a\u53ef\u4ee5\u8f93\u5165Python\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8f93\u5165Python\u4ee3\u7801\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728 <code>&gt;&gt;&gt;<\/code> \u63d0\u793a\u7b26\u540e\u8f93\u5165Python\u4ee3\u7801\u5e76\u6309\u56de\u8f66\uff0c\u4f8b\u5982 <code>print(&quot;Hello, World!&quot;)<\/code>\u3002<\/li>\n<li>Python\u4f1a\u7acb\u5373\u6267\u884c\u4ee3\u7801\u5e76\u663e\u793a\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u89e3\u51b3\u5e38\u89c1\u95ee\u9898<\/h3>\n<\/p>\n<p><p><strong>1. Python\u547d\u4ee4\u672a\u627e\u5230\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5982\u679c\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165 <code>python<\/code> \u663e\u793a\u201c\u547d\u4ee4\u672a\u627e\u5230\u201d\uff0c\u53ef\u80fd\u662f\u73af\u5883\u53d8\u91cf\u672a\u6b63\u786e\u914d\u7f6e\u3002\u8bf7\u786e\u4fddPython\u5b89\u88c5\u8def\u5f84\u5df2\u6dfb\u52a0\u5230 <code>Path<\/code> \u53d8\u91cf\u4e2d\u3002<\/li>\n<\/ul>\n<p><p><strong>2. \u7248\u672c\u7ba1\u7406\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u540c\u4e00\u53f0\u8ba1\u7b97\u673a\u4e0a\u53ef\u80fd\u5b89\u88c5\u4e86\u591a\u4e2a\u7248\u672c\u7684Python\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>py<\/code> \u547d\u4ee4\u6765\u9009\u62e9\u7279\u5b9a\u7248\u672c\uff0c\u4f8b\u5982 <code>py -3.9 script_name.py<\/code> \u6765\u8fd0\u884cPython 3.9\u3002<\/li>\n<\/ul>\n<p><p><strong>3. \u865a\u62df\u73af\u5883\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u865a\u62df\u73af\u5883\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\uff0c\u907f\u514d\u5168\u5c40\u5b89\u88c5\u5305\u7684\u51b2\u7a81\u3002\u53ef\u4ee5\u4f7f\u7528 <code>venv<\/code> \u6a21\u5757\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u5e76\u5728\u865a\u62df\u73af\u5883\u4e2d\u8fd0\u884cPython\u811a\u672c\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u5df2\u7ecf\u4e86\u89e3\u4e86\u5982\u4f55\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\u5e76\u8fd0\u884cPython\u3002\u65e0\u8bba\u662f\u8fd0\u884c\u811a\u672c\u8fd8\u662f\u8fdb\u5165\u4ea4\u4e92\u6a21\u5f0f\uff0c\u638c\u63e1\u8fd9\u4e9b\u57fa\u672c\u64cd\u4f5c\u5c06\u6781\u5927\u5730\u63d0\u9ad8\u4f60\u7684\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u68c0\u67e5Python\u662f\u5426\u5df2\u5b89\u88c5\uff1f<\/strong><br \/>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python -V<\/code>\uff0c\u5982\u679cPython\u5df2\u5b89\u88c5\uff0c\u7cfb\u7edf\u4f1a\u663e\u793a\u5f53\u524d\u7684Python\u7248\u672c\u53f7\u3002\u5982\u679c\u672a\u5b89\u88c5\uff0c\u60a8\u5c06\u6536\u5230\u4e00\u6761\u9519\u8bef\u6d88\u606f\uff0c\u8868\u660e\u8be5\u547d\u4ee4\u65e0\u6cd5\u8bc6\u522b\u3002<\/p>\n<p><strong>\u5982\u679c\u547d\u4ee4\u63d0\u793a\u7b26\u65e0\u6cd5\u8bc6\u522bPython\u8be5\u600e\u4e48\u529e\uff1f<\/strong><br \/>\u5982\u679c\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165<code>python<\/code>\u540e\u51fa\u73b0\u201c\u4e0d\u662f\u5185\u90e8\u6216\u5916\u90e8\u547d\u4ee4\u201d\u63d0\u793a\uff0c\u53ef\u80fd\u662f\u56e0\u4e3aPython\u672a\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u91cd\u65b0\u5b89\u88c5Python\u5e76\u786e\u4fdd\u9009\u62e9\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u6216\u624b\u52a8\u5c06Python\u7684\u5b89\u88c5\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n<p><strong>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u5982\u4f55\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u8981\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8fd0\u884cPython\u811a\u672c\uff0c\u8bf7\u4f7f\u7528\u547d\u4ee4<code>python script_name.py<\/code>\uff0c\u5176\u4e2d<code>script_name.py<\/code>\u662f\u60a8\u8981\u6267\u884c\u7684Python\u6587\u4ef6\u7684\u540d\u79f0\u3002\u786e\u4fdd\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u5bfc\u822a\u5230\u5305\u542b\u8be5\u6587\u4ef6\u7684\u76ee\u5f55\uff0c\u6216\u8005\u63d0\u4f9b\u5b8c\u6574\u7684\u6587\u4ef6\u8def\u5f84\u3002\u8fd0\u884c\u540e\uff0cPython\u89e3\u91ca\u5668\u5c06\u6267\u884c\u8be5\u811a\u672c\u5e76\u663e\u793a\u8f93\u51fa\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u8f93\u5165Python\u7684\u65b9\u6cd5\u6709\uff1a\u5b89\u88c5Python\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c\u3001\u4f7f\u7528Py [&hellip;]","protected":false},"author":3,"featured_media":1076323,"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\/1076317"}],"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=1076317"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1076317\/revisions"}],"predecessor-version":[{"id":1076324,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1076317\/revisions\/1076324"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1076323"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1076317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1076317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1076317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}