{"id":1114337,"date":"2025-01-08T17:56:11","date_gmt":"2025-01-08T09:56:11","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1114337.html"},"modified":"2025-01-08T17:56:14","modified_gmt":"2025-01-08T09:56:14","slug":"python%e8%84%9a%e6%9c%ac%e5%9c%a8%e7%94%b5%e8%84%91%e4%b8%8a%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8c%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1114337.html","title":{"rendered":"python\u811a\u672c\u5728\u7535\u8111\u4e0a\u5982\u4f55\u8fd0\u884c\u7a0b\u5e8f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25075535\/b388c795-ce71-407d-8da5-e6c5f3ab0ea3.webp\" alt=\"python\u811a\u672c\u5728\u7535\u8111\u4e0a\u5982\u4f55\u8fd0\u884c\u7a0b\u5e8f\" \/><\/p>\n<p><p> \u5728\u7535\u8111\u4e0a\u8fd0\u884cPython\u811a\u672c\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5177\u4f53\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u6216VS Code\u3001\u53cc\u51fb\u811a\u672c\u6587\u4ef6\u3001\u901a\u8fc7\u4efb\u52a1\u8c03\u5ea6\u5668\u6216\u5b88\u62a4\u8fdb\u7a0b\u81ea\u52a8\u8fd0\u884c\u7b49\u3002<strong>\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c\u3001\u4f7f\u7528IDE\u8fd0\u884cPython\u811a\u672c<\/strong>\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u901a\u8fc7\u547d\u4ee4\u884c\u548cIDE\u8fd0\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5Python<\/h4>\n<\/p>\n<p><p>\u9996\u5148\u9700\u8981\u786e\u4fdd\u7535\u8111\u4e0a\u5df2\u5b89\u88c5Python\u3002\u53ef\u4ee5\u4ecePython\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.python.org\/%EF%BC%89%E4%B8%8B%E8%BD%BD%E5%B9%B6%E5%AE%89%E8%A3%85%E6%9C%80%E6%96%B0%E7%89%88%E6%9C%AC%E3%80%82%E5%AE%89%E8%A3%85%E6%97%B6%E8%AF%B7%E5%8B%BE%E9%80%89%E2%80%9CAdd\">https:\/\/www.python.org\/\uff09\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u3002\u5b89\u88c5\u65f6\u8bf7\u52fe\u9009\u201cAdd<\/a> Python to PATH\u201d\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u80fd\u76f4\u63a5\u8c03\u7528Python\u547d\u4ee4\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u6253\u5f00\u547d\u4ee4\u884c\u7ec8\u7aef<\/h4>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u6309\u4e0b<code>Win + R<\/code>\u952e\uff0c\u8f93\u5165<code>cmd<\/code>\u540e\u56de\u8f66\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u5728Mac\u548cLinux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u6253\u5f00\u201cTerminal\u201d\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u76ee\u5f55<\/h4>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u7ec8\u7aef\u4e2d\uff0c\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230Python\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u811a\u672c\u4f4d\u4e8e\u684c\u9762\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd Desktop<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u8fd0\u884cPython\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u76ee\u5f55\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884cPython\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python script_name.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>script_name.py<\/code>\u662fPython\u811a\u672c\u7684\u6587\u4ef6\u540d\u3002\u5982\u679c\u811a\u672c\u4e2d\u6709\u8f93\u5165\u53c2\u6570\uff0c\u53ef\u4ee5\u5728\u811a\u672c\u540d\u540e\u9762\u6dfb\u52a0\u53c2\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python script_name.py arg1 arg2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5IDE<\/h4>\n<\/p>\n<p><p>\u5e38\u7528\u7684Python IDE\u5305\u62ecPyCharm\u3001Visual Studio Code\uff08VS Code\uff09\u3001Jupyter Notebook\u7b49\u3002\u53ef\u4ee5\u4ece\u5404\u81ea\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<ul>\n<li>PyCharm\uff1a<a href=\"https:\/\/www.jetbrains.com\/pycharm\/\">https:\/\/www.jetbr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ns.com\/pycharm\/<\/a><\/li>\n<li>Visual Studio Code\uff1a<a href=\"https:\/\/code.visualstudio.com\/\">https:\/\/code.visualstudio.com\/<\/a><\/li>\n<li>Jupyter Notebook\uff1a<a href=\"https:\/\/jupyter.org\/\">https:\/\/jupyter.org\/<\/a><\/li>\n<\/ul>\n<p><h4>2\u3001\u914d\u7f6ePython\u89e3\u91ca\u5668<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5IDE\u540e\uff0c\u9700\u8981\u914d\u7f6ePython\u89e3\u91ca\u5668\uff0c\u4ee5\u4fbfIDE\u80fd\u591f\u8bc6\u522b\u548c\u8fd0\u884cPython\u811a\u672c\u3002\u5728PyCharm\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u201cFile\u201d -&gt; \u201cSettings\u201d -&gt; \u201cProject: [Project Name]\u201d -&gt; \u201cPython Interpreter\u201d\u6765\u914d\u7f6e\u3002\u5728VS Code\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u6309\u4e0b<code>Ctrl + Shift + P<\/code>\uff0c\u8f93\u5165<code>Python: Select Interpreter<\/code>\uff0c\u7136\u540e\u9009\u62e9\u5408\u9002\u7684\u89e3\u91ca\u5668\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u521b\u5efa\u6216\u6253\u5f00Python\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728IDE\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u811a\u672c\u6587\u4ef6\uff0c\u6216\u8005\u6253\u5f00\u73b0\u6709\u7684Python\u811a\u672c\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u5728PyCharm\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u201cFile\u201d -&gt; \u201cNew\u201d -&gt; \u201cPython File\u201d\u521b\u5efa\u65b0\u6587\u4ef6\u3002\u5728VS Code\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u5de6\u4fa7\u7684\u6587\u4ef6\u56fe\u6807\uff0c\u9009\u62e9\u201cNew File\u201d\u521b\u5efa\u65b0\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>4\u3001\u8fd0\u884cPython\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728IDE\u4e2d\u6253\u5f00Python\u811a\u672c\u6587\u4ef6\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u201cRun\u201d\u6309\u94ae\u6216\u4f7f\u7528\u5feb\u6377\u952e\u8fd0\u884c\u811a\u672c\u3002\u4f8b\u5982\uff0c\u5728PyCharm\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u53f3\u4e0a\u89d2\u7684\u7eff\u8272\u4e09\u89d2\u5f62\u6309\u94ae\u8fd0\u884c\u811a\u672c\u3002\u5728VS Code\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u6309\u4e0b<code>F5<\/code>\u952e\u8fd0\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u53cc\u51fb\u811a\u672c\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u901a\u8fc7\u53cc\u51fbPython\u811a\u672c\u6587\u4ef6\u76f4\u63a5\u8fd0\u884c\u811a\u672c\u3002\u9700\u8981\u786e\u4fdd\u6587\u4ef6\u7684\u6269\u5c55\u540d\u662f<code>.py<\/code>\uff0c\u5e76\u4e14\u7cfb\u7edf\u5df2\u6b63\u786e\u914d\u7f6ePython\u89e3\u91ca\u5668\u3002\u53cc\u51fb\u811a\u672c\u6587\u4ef6\u65f6\uff0c\u7cfb\u7edf\u5c06\u81ea\u52a8\u8c03\u7528Python\u89e3\u91ca\u5668\u8fd0\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u901a\u8fc7\u4efb\u52a1\u8c03\u5ea6\u5668\u6216\u5b88\u62a4\u8fdb\u7a0b\u81ea\u52a8\u8fd0\u884c<\/h3>\n<\/p>\n<p><h4>1\u3001Windows\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f<\/h4>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u81ea\u52a8\u8fd0\u884cPython\u811a\u672c\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\uff1a\u6309\u4e0b<code>Win + S<\/code>\u952e\uff0c\u8f93\u5165\u201c\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u201d\u5e76\u6253\u5f00\u3002<\/li>\n<li>\u521b\u5efa\u57fa\u672c\u4efb\u52a1\uff1a\u5728\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u4e2d\uff0c\u70b9\u51fb\u53f3\u4fa7\u7684\u201c\u521b\u5efa\u57fa\u672c\u4efb\u52a1\u201d\u3002<\/li>\n<li>\u8bbe\u7f6e\u4efb\u52a1\u540d\u79f0\u548c\u63cf\u8ff0\uff1a\u8f93\u5165\u4efb\u52a1\u540d\u79f0\u548c\u63cf\u8ff0\uff0c\u7136\u540e\u70b9\u51fb\u201c\u4e0b\u4e00\u6b65\u201d\u3002<\/li>\n<li>\u9009\u62e9\u89e6\u53d1\u5668\uff1a\u9009\u62e9\u4efb\u52a1\u89e6\u53d1\u5668\uff08\u4f8b\u5982\uff0c\u6bcf\u5929\u3001\u6bcf\u5468\u7b49\uff09\uff0c\u7136\u540e\u70b9\u51fb\u201c\u4e0b\u4e00\u6b65\u201d\u3002<\/li>\n<li>\u8bbe\u7f6e\u89e6\u53d1\u5668\u8be6\u7ec6\u4fe1\u606f\uff1a\u6839\u636e\u9700\u8981\u8bbe\u7f6e\u89e6\u53d1\u5668\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u7136\u540e\u70b9\u51fb\u201c\u4e0b\u4e00\u6b65\u201d\u3002<\/li>\n<li>\u9009\u62e9\u64cd\u4f5c\uff1a\u9009\u62e9\u201c\u542f\u52a8\u7a0b\u5e8f\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u4e0b\u4e00\u6b65\u201d\u3002<\/li>\n<li>\u8bbe\u7f6e\u7a0b\u5e8f\u548c\u53c2\u6570\uff1a\u70b9\u51fb\u201c\u6d4f\u89c8\u201d\u6309\u94ae\uff0c\u9009\u62e9Python\u89e3\u91ca\u5668\uff08\u4f8b\u5982\uff0c<code>python.exe<\/code>\uff09\uff0c\u5728\u201c\u6dfb\u52a0\u53c2\u6570\u201d\u5b57\u6bb5\u4e2d\u8f93\u5165\u811a\u672c\u8def\u5f84\uff08\u4f8b\u5982\uff0c<code>C:\\path\\to\\script.py<\/code>\uff09\uff0c\u7136\u540e\u70b9\u51fb\u201c\u4e0b\u4e00\u6b65\u201d\u3002<\/li>\n<li>\u5b8c\u6210\u4efb\u52a1\uff1a\u68c0\u67e5\u4efb\u52a1\u8bbe\u7f6e\uff0c\u786e\u8ba4\u65e0\u8bef\u540e\u70b9\u51fb\u201c\u5b8c\u6210\u201d\u3002<\/li>\n<\/ol>\n<p><h4>2\u3001Linux\u5b88\u62a4\u8fdb\u7a0b<\/h4>\n<\/p>\n<p><p>\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>cron<\/code>\u6216<code>systemd<\/code>\u5b88\u62a4\u8fdb\u7a0b\u81ea\u52a8\u8fd0\u884cPython\u811a\u672c\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528<code>cron<\/code>\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u7ec8\u7aef\u3002<\/li>\n<li>\u7f16\u8f91<code>crontab<\/code>\u6587\u4ef6\uff1a\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8f91<code>crontab<\/code>\u6587\u4ef6\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">crontab -e<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u6dfb\u52a0\u4efb\u52a1\uff1a\u5728<code>crontab<\/code>\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff0c\u8bbe\u7f6e\u4efb\u52a1\u8c03\u5ea6\u548c\u811a\u672c\u8def\u5f84\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">* * * * * \/usr\/bin\/python3 \/path\/to\/script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c\u524d\u4e94\u4e2a\u661f\u53f7\u8868\u793a\u4efb\u52a1\u8c03\u5ea6\u7684\u65f6\u95f4\uff08\u5206\u949f\u3001\u5c0f\u65f6\u3001\u65e5\u671f\u3001\u6708\u4efd\u548c\u661f\u671f\uff09\uff0c<code>\/usr\/bin\/python3<\/code>\u662fPython\u89e3\u91ca\u5668\u8def\u5f84\uff0c<code>\/path\/to\/script.py<\/code>\u662fPython\u811a\u672c\u8def\u5f84\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li>\u4fdd\u5b58\u5e76\u9000\u51fa\uff1a\u4fdd\u5b58<code>crontab<\/code>\u6587\u4ef6\u5e76\u9000\u51fa\u7f16\u8f91\u5668\uff0c\u4efb\u52a1\u5c06\u6309\u7167\u8bbe\u7f6e\u7684\u65f6\u95f4\u81ea\u52a8\u8fd0\u884c\u3002<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u8c03\u8bd5\u548c\u4f18\u5316Python\u811a\u672c<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177<\/h4>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u548c\u8fd0\u884cPython\u811a\u672c\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u548c\u95ee\u9898\u3002\u53ef\u4ee5\u4f7f\u7528IDE\u4e2d\u7684\u8c03\u8bd5\u5de5\u5177\u6765\u67e5\u627e\u548c\u4fee\u590d\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u5728PyCharm\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u8c03\u8bd5\u6309\u94ae\uff08\u7eff\u8272\u866b\u5b50\u56fe\u6807\uff09\u542f\u52a8\u8c03\u8bd5\u6a21\u5f0f\u3002\u5728VS Code\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u6309\u4e0b<code>F5<\/code>\u952e\u542f\u52a8\u8c03\u8bd5\u6a21\u5f0f\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f18\u5316\u811a\u672c\u6027\u80fd<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u63d0\u9ad8Python\u811a\u672c\u7684\u6027\u80fd\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u4f18\u5316\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784<\/strong>\uff1a\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\uff08\u4f8b\u5982\uff0c\u5217\u8868\u3001\u5b57\u5178\u3001\u96c6\u5408\u7b49\uff09\u6765\u5b58\u50a8\u548c\u5904\u7406\u6570\u636e\u3002<\/li>\n<li><strong>\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97<\/strong>\uff1a\u907f\u514d\u91cd\u590d\u8ba1\u7b97\u548c\u4e0d\u5fc5\u8981\u7684\u64cd\u4f5c\uff0c\u5c3d\u91cf\u51cf\u5c11\u5faa\u73af\u548c\u9012\u5f52\u6b21\u6570\u3002<\/li>\n<li><strong>\u4f7f\u7528\u5e76\u884c\u548c\u5f02\u6b65\u7f16\u7a0b<\/strong>\uff1a\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u6216\u9700\u8981\u8fdb\u884c\u5e76\u53d1\u4efb\u52a1\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u7ebf\u7a0b\u3001\u591a\u8fdb\u7a0b\u6216\u5f02\u6b65\u7f16\u7a0b\u6765\u63d0\u9ad8\u6027\u80fd\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>threading<\/code>\u3001<code>multiprocessing<\/code>\u6a21\u5757\u6216<code>asyncio<\/code>\u5e93\u3002<\/li>\n<li><strong>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/strong>\uff1a\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u7b2c\u4e09\u65b9\u5e93\uff08\u4f8b\u5982\uff0cNumPy\u3001Pandas\u3001scikit-learn\u7b49\uff09\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u7b97\u6cd5\u548c\u6570\u636e\u5904\u7406\u65b9\u6cd5\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<li><strong>\u914d\u7f6e\u548c\u8c03\u6574\u89e3\u91ca\u5668<\/strong>\uff1a\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574Python\u89e3\u91ca\u5668\u7684\u914d\u7f6e\u548c\u53c2\u6570\u6765\u4f18\u5316\u6027\u80fd\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pypy<\/code>\u89e3\u91ca\u5668\uff0c\u5b83\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u6bd4\u6807\u51c6\u7684CPython\u89e3\u91ca\u5668\u66f4\u5feb\u3002<\/li>\n<\/ul>\n<p><h3>\u516d\u3001\u5e38\u89c1\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6cd5<\/h3>\n<\/p>\n<p><h4>1\u3001\u811a\u672c\u65e0\u6cd5\u8fd0\u884c<\/h4>\n<\/p>\n<p><p>\u5982\u679cPython\u811a\u672c\u65e0\u6cd5\u8fd0\u884c\uff0c\u53ef\u4ee5\u68c0\u67e5\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u68c0\u67e5Python\u5b89\u88c5<\/strong>\uff1a\u786e\u4fdd\u5df2\u6b63\u786e\u5b89\u88c5Python\uff0c\u5e76\u4e14Python\u89e3\u91ca\u5668\u5df2\u6dfb\u52a0\u5230\u7cfb\u7edf\u8def\u5f84\u4e2d\u3002<\/li>\n<li><strong>\u68c0\u67e5\u811a\u672c\u8def\u5f84<\/strong>\uff1a\u786e\u4fdd\u811a\u672c\u8def\u5f84\u6b63\u786e\uff0c\u5e76\u4e14\u811a\u672c\u6587\u4ef6\u5b58\u5728\u3002<\/li>\n<li><strong>\u68c0\u67e5\u811a\u672c\u6743\u9650<\/strong>\uff1a\u786e\u4fdd\u811a\u672c\u6587\u4ef6\u5177\u6709\u53ef\u6267\u884c\u6743\u9650\u3002\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>chmod<\/code>\u547d\u4ee4\u8bbe\u7f6e\u6743\u9650\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">chmod +x script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u811a\u672c\u62a5\u9519<\/h4>\n<\/p>\n<p><p>\u5982\u679cPython\u811a\u672c\u5728\u8fd0\u884c\u65f6\u62a5\u9519\uff0c\u53ef\u4ee5\u68c0\u67e5\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u68c0\u67e5\u8bed\u6cd5\u9519\u8bef<\/strong>\uff1a\u786e\u4fdd\u811a\u672c\u8bed\u6cd5\u6b63\u786e\uff0c\u5e76\u4e14\u6ca1\u6709\u62fc\u5199\u9519\u8bef\u6216\u7f3a\u5c11\u7684\u7b26\u53f7\u3002<\/li>\n<li><strong>\u68c0\u67e5\u4f9d\u8d56\u5e93<\/strong>\uff1a\u786e\u4fdd\u5df2\u5b89\u88c5\u6240\u6709\u4f9d\u8d56\u5e93\u548c\u6a21\u5757\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u547d\u4ee4\u5b89\u88c5\u4f9d\u8d56\u5e93\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">pip install library_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u68c0\u67e5\u8f93\u5165\u53c2\u6570<\/strong>\uff1a\u786e\u4fdd\u8f93\u5165\u53c2\u6570\u6b63\u786e\uff0c\u5e76\u4e14\u7b26\u5408\u811a\u672c\u8981\u6c42\u3002<\/li>\n<li><strong>\u68c0\u67e5\u73af\u5883\u53d8\u91cf<\/strong>\uff1a\u786e\u4fdd\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u6b63\u786e\uff0c\u5e76\u4e14\u811a\u672c\u80fd\u591f\u8bbf\u95ee\u6240\u9700\u7684\u8d44\u6e90\u548c\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p><h4>3\u3001\u811a\u672c\u6027\u80fd\u4f4e\u4e0b<\/h4>\n<\/p>\n<p><p>\u5982\u679cPython\u811a\u672c\u8fd0\u884c\u901f\u5ea6\u8f83\u6162\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u4f18\u5316\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u5206\u6790\u6027\u80fd\u74f6\u9888<\/strong>\uff1a\u4f7f\u7528\u6027\u80fd\u5206\u6790\u5de5\u5177\uff08\u4f8b\u5982\uff0c<code>cProfile<\/code>\u3001<code>line_profiler<\/code>\u7b49\uff09\u6765\u5206\u6790\u6027\u80fd\u74f6\u9888\uff0c\u5e76\u5b9a\u4f4d\u8017\u65f6\u8f83\u591a\u7684\u90e8\u5206\u3002<\/li>\n<li><strong>\u4f18\u5316\u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784<\/strong>\uff1a\u9009\u62e9\u5408\u9002\u7684\u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784\uff0c\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u3002<\/li>\n<li><strong>\u4f7f\u7528\u7f13\u5b58<\/strong>\uff1a\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u7f13\u5b58\u6765\u5b58\u50a8\u8ba1\u7b97\u7ed3\u679c\uff0c\u907f\u514d\u91cd\u590d\u8ba1\u7b97\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>functools.lru_cache<\/code>\u88c5\u9970\u5668\u3002<\/li>\n<li><strong>\u4f7f\u7528\u5e76\u884c\u548c\u5f02\u6b65\u7f16\u7a0b<\/strong>\uff1a\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u6216\u9700\u8981\u8fdb\u884c\u5e76\u53d1\u4efb\u52a1\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u7ebf\u7a0b\u3001\u591a\u8fdb\u7a0b\u6216\u5f02\u6b65\u7f16\u7a0b\u6765\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728\u7535\u8111\u4e0a\u987a\u5229\u8fd0\u884cPython\u811a\u672c\uff0c\u5e76\u4e14\u63d0\u9ad8\u811a\u672c\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u3002\u65e0\u8bba\u662f\u901a\u8fc7\u547d\u4ee4\u884c\u3001IDE\u3001\u53cc\u51fb\u6587\u4ef6\u8fd8\u662f\u81ea\u52a8\u8c03\u5ea6\u8fd0\u884c\uff0c\u90fd\u9700\u8981\u6ce8\u610f\u811a\u672c\u7684\u6b63\u786e\u914d\u7f6e\u548c\u4f9d\u8d56\u5e93\u7684\u5b89\u88c5\u3002\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u7406\u89e3\u548c\u638c\u63e1Python\u811a\u672c\u7684\u8fd0\u884c\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u7535\u8111\u4e0a\u5b89\u88c5Python\u4ee5\u8fd0\u884c\u811a\u672c\uff1f<\/strong><br \/>\u8981\u5728\u7535\u8111\u4e0a\u8fd0\u884cPython\u811a\u672c\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u60a8\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u3002\u53ef\u4ee5\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff08python.org\uff09\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u6700\u65b0\u7248\u672c\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u8bf7\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u8fd9\u5c06\u4f7f\u60a8\u80fd\u591f\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u8fd0\u884cPython\u547d\u4ee4\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u901a\u8fc7\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08Windows\uff09\u6216\u7ec8\u7aef\uff08Mac\/Linux\uff09\u8f93\u5165<code>python --version<\/code>\u6765\u68c0\u67e5\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Windows\u548cMac\u4e0a\u6267\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u5728Windows\u4e0a\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u63d0\u793a\u7b26\u6765\u8fd0\u884cPython\u811a\u672c\u3002\u5bfc\u822a\u5230\u5305\u542b\u811a\u672c\u7684\u76ee\u5f55\uff0c\u5e76\u4f7f\u7528\u547d\u4ee4<code>python script_name.py<\/code>\uff08\u5c06<code>script_name.py<\/code>\u66ff\u6362\u4e3a\u60a8\u7684\u6587\u4ef6\u540d\uff09\u6765\u6267\u884c\u5b83\u3002\u5bf9\u4e8eMac\u7528\u6237\uff0c\u6253\u5f00\u7ec8\u7aef\uff0c\u8fdb\u5165\u5230\u811a\u672c\u6240\u5728\u7684\u6587\u4ef6\u5939\uff0c\u540c\u6837\u4f7f\u7528<code>python3 script_name.py<\/code>\u547d\u4ee4\u6765\u8fd0\u884c\u811a\u672c\u3002\u786e\u4fdd\u4f7f\u7528\u6b63\u786e\u7684Python\u7248\u672c\u547d\u4ee4\uff0c\u67d0\u4e9b\u7cfb\u7edf\u4e2d\u53ef\u80fd\u9700\u8981\u4f7f\u7528<code>python3<\/code>\u3002<\/p>\n<p><strong>\u5982\u4f55\u8c03\u8bd5\u548c\u67e5\u770bPython\u811a\u672c\u7684\u8f93\u51fa\uff1f<\/strong><br \/>\u5728\u6267\u884cPython\u811a\u672c\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u76f4\u63a5\u67e5\u770b\u8f93\u51fa\u3002\u5982\u679c\u9700\u8981\u8c03\u8bd5\uff0c\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0<code>print()<\/code>\u8bed\u53e5\uff0c\u4ee5\u4fbf\u5728\u63a7\u5236\u53f0\u4e2d\u8f93\u51fa\u53d8\u91cf\u7684\u503c\u548c\u7a0b\u5e8f\u7684\u6267\u884c\u72b6\u6001\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u3001VS Code\u7b49\uff0c\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u5305\u62ec\u65ad\u70b9\u8bbe\u7f6e\u548c\u53d8\u91cf\u76d1\u89c6\uff0c\u5e2e\u52a9\u60a8\u66f4\u65b9\u4fbf\u5730\u8c03\u8bd5\u811a\u672c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728\u7535\u8111\u4e0a\u8fd0\u884cPython\u811a\u672c\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5177\u4f53\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u6216 [&hellip;]","protected":false},"author":3,"featured_media":1114344,"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\/1114337"}],"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=1114337"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1114337\/revisions"}],"predecessor-version":[{"id":1114346,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1114337\/revisions\/1114346"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1114344"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1114337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1114337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1114337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}