{"id":962435,"date":"2024-12-27T04:08:14","date_gmt":"2024-12-26T20:08:14","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/962435.html"},"modified":"2024-12-27T04:08:18","modified_gmt":"2024-12-26T20:08:18","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e5%be%97python%e7%bc%96%e8%af%91%e8%bf%90%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/962435.html","title":{"rendered":"\u5982\u4f55\u4f7f\u5f97python\u7f16\u8bd1\u8fd0\u884c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25104415\/c863c289-0ada-4f07-ad9a-00b8aacdda66.webp\" alt=\"\u5982\u4f55\u4f7f\u5f97python\u7f16\u8bd1\u8fd0\u884c\" \/><\/p>\n<p><p> <strong>\u8981\u4f7fPython\u7f16\u8bd1\u5e76\u8fd0\u884c\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u5b89\u88c5Python\u89e3\u91ca\u5668\u3001\u7f16\u5199Python\u811a\u672c\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884c\u811a\u672c\u3001\u4f7f\u7528IDE\u8fdb\u884c\u5f00\u53d1\u548c\u8c03\u8bd5\u3002<\/strong>\u5b89\u88c5Python\u89e3\u91ca\u5668\u662f\u81f3\u5173\u91cd\u8981\u7684\uff0c\u56e0\u4e3aPython\u662f\u4e00\u79cd\u89e3\u91ca\u6027\u8bed\u8a00\uff0c\u4f9d\u8d56\u4e8e\u89e3\u91ca\u5668\u6765\u6267\u884c\u811a\u672c\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u7f16\u5199Python\u4ee3\u7801\uff0c\u7136\u540e\u901a\u8fc7\u547d\u4ee4\u884c\u6216\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u6765\u8fd0\u884c\u548c\u8c03\u8bd5\u4ee3\u7801\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5Python\u89e3\u91ca\u5668<\/p>\n<\/p>\n<p><p>\u8981\u5f00\u59cb\u4f7f\u7528Python\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5Python\u89e3\u91ca\u5668\u3002Python\u89e3\u91ca\u5668\u53ef\u4ee5\u4ecePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\uff0c\u901a\u5e38\u6709\u4e24\u79cd\u4e3b\u8981\u7248\u672c\uff1aPython 2\u548cPython 3\u3002Python 3\u662f\u6700\u65b0\u7684\u7248\u672c\uff0c\u5e76\u4e14\u662f\u63a8\u8350\u4f7f\u7528\u7684\u7248\u672c\uff0c\u56e0\u4e3a\u5b83\u5305\u542b\u4e86\u8bb8\u591a\u65b0\u7684\u7279\u6027\u548c\u6539\u8fdb\u3002<\/p>\n<\/p>\n<ol>\n<li>\u4e0b\u8f7dPython<\/li>\n<\/ol>\n<p><p>\u8bbf\u95ee<a href=\"https:\/\/www.python.org\/\">Python\u5b98\u65b9\u7f51\u7ad9<\/a>\u5e76\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684Python\u5b89\u88c5\u7a0b\u5e8f\u3002Windows\u3001macOS\u548cLinux\u90fd\u6709\u76f8\u5e94\u7684\u7248\u672c\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u6309\u7167\u63d0\u793a\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u73af\u5883\u53d8\u91cf\u914d\u7f6e<\/li>\n<\/ol>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e0a\uff0c\u5b89\u88c5\u7a0b\u5e8f\u901a\u5e38\u4f1a\u8be2\u95ee\u662f\u5426\u5c06Python\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u52fe\u9009\u6b64\u9009\u9879\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884cPython\u3002\u5982\u679c\u6ca1\u6709\u52fe\u9009\uff0c\u60a8\u9700\u8981\u624b\u52a8\u5c06Python\u7684\u5b89\u88c5\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684<code>PATH<\/code>\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u9a8c\u8bc1\u5b89\u88c5<\/li>\n<\/ol>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6253\u5f00\u547d\u4ee4\u884c\uff08Windows\u7684cmd\u6216PowerShell\uff0cmacOS\u548cLinux\u7684\u7ec8\u7aef\uff09\uff0c\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\uff0c\u5982\u679c\u5b89\u88c5\u6210\u529f\uff0c\u60a8\u5c06\u770b\u5230Python\u7684\u7248\u672c\u53f7\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u7f16\u5199Python\u811a\u672c<\/p>\n<\/p>\n<p><p>\u6709\u4e86Python\u89e3\u91ca\u5668\uff0c\u60a8\u53ef\u4ee5\u5f00\u59cb\u7f16\u5199Python\u4ee3\u7801\u3002Python\u811a\u672c\u662f\u5305\u542bPython\u4ee3\u7801\u7684\u6587\u672c\u6587\u4ef6\uff0c\u901a\u5e38\u4ee5\u201c.py\u201d\u4f5c\u4e3a\u6587\u4ef6\u6269\u5c55\u540d\u3002<\/p>\n<\/p>\n<ol>\n<li>\u9009\u62e9\u6587\u672c\u7f16\u8f91\u5668<\/li>\n<\/ol>\n<p><p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u6587\u672c\u7f16\u8f91\u5668\u6765\u7f16\u5199Python\u4ee3\u7801\uff0c\u5982Notepad++\u3001Sublime Text\u3001Visual Studio Code\u7b49\u3002\u9009\u62e9\u4e00\u4e2a\u60a8\u559c\u6b22\u7684\u7f16\u8f91\u5668\uff0c\u5e76\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u7f16\u5199\u4ee3\u7801<\/li>\n<\/ol>\n<p><p>\u5728\u65b0\u5efa\u7684\u6587\u4ef6\u4e2d\u8f93\u5165\u60a8\u7684Python\u4ee3\u7801\u3002\u4f8b\u5982\uff0c\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u201cHello, World!\u201d\u7a0b\u5e8f\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>\u4fdd\u5b58\u6587\u4ef6\uff0c\u547d\u540d\u4e3a<code>hello.py<\/code>\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884c\u811a\u672c<\/p>\n<\/p>\n<p><p>\u6709\u4e86Python\u811a\u672c\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u6765\u8fd0\u884c\u5b83\u3002<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u547d\u4ee4\u884c<\/li>\n<\/ol>\n<p><p>\u6839\u636e\u60a8\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u6253\u5f00\u76f8\u5e94\u7684\u547d\u4ee4\u884c\u5de5\u5177\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u76ee\u5f55<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230\u60a8\u4fdd\u5b58Python\u811a\u672c\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd path\/to\/your\/script<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u8fd0\u884c\u811a\u672c<\/li>\n<\/ol>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u5728\u67d0\u4e9b\u7cfb\u7edf\u4e0a\u53ef\u80fd\u9700\u8981\u4f7f\u7528<code>python3<\/code>\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u5c06\u770b\u5230\u8f93\u51fa\u201cHello, World!\u201d\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528IDE\u8fdb\u884c\u5f00\u53d1\u548c\u8c03\u8bd5<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u9879\u76ee\uff0c\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002IDE\u901a\u5e38\u63d0\u4f9b\u4ee3\u7801\u7f16\u8f91\u3001\u8c03\u8bd5\u3001\u7248\u672c\u63a7\u5236\u7b49\u529f\u80fd\u3002<\/p>\n<\/p>\n<ol>\n<li>\u9009\u62e9IDE<\/li>\n<\/ol>\n<p><p>\u6709\u8bb8\u591a\u9002\u5408Python\u5f00\u53d1\u7684IDE\uff0c\u5982PyCharm\u3001Visual Studio Code\u3001Jupyter Notebook\u7b49\u3002\u6839\u636e\u60a8\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684IDE\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u521b\u5efa\u9879\u76ee<\/li>\n<\/ol>\n<p><p>\u6253\u5f00IDE\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u9879\u76ee\u3002IDE\u901a\u5e38\u4f1a\u81ea\u52a8\u914d\u7f6ePython\u73af\u5883\uff0c\u4f7f\u60a8\u80fd\u591f\u76f4\u63a5\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u7f16\u5199\u548c\u8fd0\u884c\u4ee3\u7801<\/li>\n<\/ol>\n<p><p>\u5728IDE\u4e2d\u7f16\u5199Python\u4ee3\u7801\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u70b9\u51fb\u201c\u8fd0\u884c\u201d\u6309\u94ae\u6765\u6267\u884c\u4ee3\u7801\u3002IDE\u8fd8\u63d0\u4f9b\u8c03\u8bd5\u5de5\u5177\uff0c\u5e2e\u52a9\u60a8\u8ddf\u8e2a\u548c\u89e3\u51b3\u4ee3\u7801\u4e2d\u7684\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u5e38\u89c1\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6848<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Python\u7684\u8fc7\u7a0b\u4e2d\uff0c\u60a8\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>Python\u7248\u672c\u95ee\u9898<\/strong><\/li>\n<\/ol>\n<p><p>\u786e\u4fdd\u60a8\u4f7f\u7528\u7684Python\u7248\u672c\u4e0e\u60a8\u7684\u4ee3\u7801\u517c\u5bb9\u3002\u67d0\u4e9b\u65e7\u4ee3\u7801\u53ef\u80fd\u9700\u8981Python 2\uff0c\u800c\u5927\u90e8\u5206\u65b0\u4ee3\u7801\u4f7f\u7528Python 3\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u73af\u5883\u53d8\u91cf\u672a\u914d\u7f6e<\/strong><\/li>\n<\/ol>\n<p><p>\u5982\u679c\u547d\u4ee4\u884c\u65e0\u6cd5\u8bc6\u522b<code>python<\/code>\u547d\u4ee4\uff0c\u68c0\u67e5Python\u662f\u5426\u5df2\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5e93\u548c\u6a21\u5757\u672a\u5b89\u88c5<\/strong><\/li>\n<\/ol>\n<p><p>\u4f7f\u7528<code>pip<\/code>\u5de5\u5177\u5b89\u88c5\u6240\u9700\u7684\u5e93\u548c\u6a21\u5757\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u4e00\u4e2a\u540d\u4e3a<code>requests<\/code>\u7684\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u8bed\u6cd5\u9519\u8bef<\/strong><\/li>\n<\/ol>\n<p><p>Python\u5bf9\u7f29\u8fdb\u975e\u5e38\u654f\u611f\uff0c\u786e\u4fdd\u4ee3\u7801\u7684\u7f29\u8fdb\u6b63\u786e\u3002\u6b64\u5916\uff0cPython 3\u4e0ePython 2\u7684\u8bed\u6cd5\u7565\u6709\u4e0d\u540c\uff0c\u6ce8\u610f\u4f7f\u7528\u6b63\u786e\u7684\u8bed\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u9075\u5faa\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u60a8\u5e94\u8be5\u80fd\u591f\u987a\u5229\u5730\u7f16\u8bd1\u5e76\u8fd0\u884cPython\u4ee3\u7801\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u811a\u672c\u8fd8\u662f\u590d\u6742\u7684\u9879\u76ee\uff0cPython\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\u548c\u8d44\u6e90\u6765\u652f\u6301\u60a8\u7684\u5f00\u53d1\u5de5\u4f5c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u6211\u7684\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5Python\u4ee5\u4fbf\u7f16\u8bd1\u548c\u8fd0\u884c\u7a0b\u5e8f\uff1f<\/strong><br \/>\u8981\u5728\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5Python\uff0c\u53ef\u4ee5\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff08python.org\uff09\uff0c\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u6700\u65b0\u7248\u672c\u3002\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u8bf7\u786e\u4fdd\u9009\u62e9\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u65b9\u4fbf\u5730\u8bbf\u95eePython\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python --version<\/code>\u6765\u786e\u8ba4\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<p><strong>\u6211\u53ef\u4ee5\u4f7f\u7528\u54ea\u4e9b\u5de5\u5177\u6765\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\uff1f<\/strong><br \/>\u6709\u591a\u79cd\u5de5\u5177\u53ef\u4ee5\u7528\u6765\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\uff0c\u4f8b\u5982IDLE\uff08Python\u81ea\u5e26\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff09\u3001VS Code\u3001PyCharm\u548cJupyter Notebook\u7b49\u3002\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u901a\u5e38\u53d6\u51b3\u4e8e\u60a8\u7684\u7f16\u7a0b\u9700\u6c42\u4e0e\u4e60\u60ef\u3002\u5982\u679c\u60a8\u662f\u521d\u5b66\u8005\uff0cIDLE\u548cVS Code\u90fd\u662f\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u5b83\u4eec\u754c\u9762\u53cb\u597d\u4e14\u529f\u80fd\u5f3a\u5927\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e2d\u7f16\u8bd1\u548c\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884cPython\u811a\u672c\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\uff0c\u5bfc\u822a\u5230\u5305\u542bPython\u811a\u672c\u7684\u76ee\u5f55\u3002\u7136\u540e\uff0c\u4f7f\u7528\u547d\u4ee4<code>python script_name.py<\/code>\uff08\u5c06\u201cscript_name.py\u201d\u66ff\u6362\u4e3a\u60a8\u7684\u6587\u4ef6\u540d\uff09\u6765\u6267\u884c\u811a\u672c\u3002\u786e\u4fdd\u60a8\u7684\u811a\u672c\u6587\u4ef6\u4ee5\u201c.py\u201d\u7ed3\u5c3e\uff0c\u8fd9\u6837Python\u624d\u80fd\u6b63\u786e\u8bc6\u522b\u5e76\u6267\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u4f7fPython\u7f16\u8bd1\u5e76\u8fd0\u884c\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u5b89\u88c5Python\u89e3\u91ca\u5668\u3001\u7f16\u5199Python\u811a\u672c\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884c\u811a\u672c [&hellip;]","protected":false},"author":3,"featured_media":962442,"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\/962435"}],"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=962435"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/962435\/revisions"}],"predecessor-version":[{"id":962443,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/962435\/revisions\/962443"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/962442"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=962435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=962435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=962435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}