{"id":1094006,"date":"2025-01-08T14:36:47","date_gmt":"2025-01-08T06:36:47","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1094006.html"},"modified":"2025-01-08T14:36:50","modified_gmt":"2025-01-08T06:36:50","slug":"python%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8c%e4%b8%80%e4%b8%aa%e4%bb%a3%e7%a0%81%e6%96%87%e4%bb%b6-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1094006.html","title":{"rendered":"python\u5982\u4f55\u8fd0\u884c\u4e00\u4e2a\u4ee3\u7801\u6587\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24210333\/44e7b758-6571-4053-8126-338cae9d46f0.webp\" alt=\"python\u5982\u4f55\u8fd0\u884c\u4e00\u4e2a\u4ee3\u7801\u6587\u4ef6\" \/><\/p>\n<p><p> <strong>\u8981\u8fd0\u884c\u4e00\u4e2aPython\u4ee3\u7801\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u4f7f\u7528\u811a\u672c\u6267\u884c\u5668\u3001\u4f7f\u7528\u5728\u7ebf\u8fd0\u884c\u73af\u5883\u3002<\/strong> \u5176\u4e2d\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u662f\u6700\u5e38\u89c1\u548c\u6700\u57fa\u672c\u7684\u65b9\u6cd5\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884cPython\u4ee3\u7801\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u547d\u4ee4\u884c<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884cPython\u4ee3\u7801\u6587\u4ef6\u662f\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u89e3\u91ca\u5668\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165 <code>python --version<\/code> \u6216 <code>python3 --version<\/code> \u6765\u68c0\u67e5\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u4f60\u9700\u8981\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5Python\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728Windows\u7cfb\u7edf\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u201c\u547d\u4ee4\u63d0\u793a\u7b26\u201d\u6216\u8005\u201cPowerShell\u201d\u3002<\/li>\n<li>\u5728macOS\u6216\u8005Linux\u7cfb\u7edf\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u201c\u7ec8\u7aef\u201d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5bfc\u822a\u5230\u4ee3\u7801\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528 <code>cd<\/code> \u547d\u4ee4\u6765\u6539\u53d8\u5f53\u524d\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4ee3\u7801\u6587\u4ef6\u4f4d\u4e8e\u684c\u9762\u4e0a\u7684\u4e00\u4e2a\u6587\u4ef6\u5939\u4e2d\uff0c\u53ef\u4ee5\u8f93\u5165 <code>cd Desktop\/your_folder_name<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u4ee3\u7801\u6587\u4ef6<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165 <code>python filename.py<\/code> \u6216\u8005 <code>python3 filename.py<\/code>\uff08\u6839\u636e\u4f60\u7684Python\u7248\u672c\u6765\u9009\u62e9\uff09\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u6587\u4ef6\u540d\u662f <code>script.py<\/code>\uff0c\u5219\u8f93\u5165 <code>python script.py<\/code> \u6216 <code>python3 script.py<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/h3>\n<\/p>\n<p><p>\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u4e3a\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\u63d0\u4f9b\u4e86\u4e00\u4e2a\u66f4\u53cb\u597d\u7684\u754c\u9762\u3002\u5e38\u89c1\u7684Python IDE\u5305\u62ecPyCharm\u3001Visual Studio Code\u3001Jupyter Notebook\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>PyCharm<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00PyCharm\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\u6216\u8005\u6253\u5f00\u4e00\u4e2a\u73b0\u6709\u9879\u76ee\u3002<\/li>\n<li>\u5728\u9879\u76ee\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u6587\u4ef6\uff0c\u6216\u8005\u6253\u5f00\u4e00\u4e2a\u73b0\u6709\u7684Python\u6587\u4ef6\u3002<\/li>\n<li>\u5728IDE\u7684\u9876\u90e8\u83dc\u5355\u4e2d\uff0c\u9009\u62e9\u201cRun\u201d\u9009\u9879\uff0c\u7136\u540e\u9009\u62e9\u201cRun&#8230;\u201d\u6765\u8fd0\u884c\u4ee3\u7801\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Visual Studio Code<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00Visual Studio Code\u5e76\u5b89\u88c5Python\u6269\u5c55\u3002<\/li>\n<li>\u6253\u5f00\u6216\u8005\u521b\u5efa\u4e00\u4e2aPython\u6587\u4ef6\u3002<\/li>\n<li>\u5728\u6587\u4ef6\u4e2d\u53f3\u952e\u70b9\u51fb\uff0c\u9009\u62e9\u201cRun Python File in Terminal\u201d\u6765\u8fd0\u884c\u4ee3\u7801\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Jupyter Notebook<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00Jupyter Notebook\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Notebook\u3002<\/li>\n<li>\u5728Notebook\u7684\u5355\u5143\u683c\u4e2d\u7f16\u5199Python\u4ee3\u7801\u3002<\/li>\n<li>\u70b9\u51fb\u201cRun\u201d\u6309\u94ae\u6765\u8fd0\u884c\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u811a\u672c\u6267\u884c\u5668<\/h3>\n<\/p>\n<p><p>\u811a\u672c\u6267\u884c\u5668\u662f\u4e00\u79cd\u81ea\u52a8\u5316\u5de5\u5177\uff0c\u7528\u4e8e\u8fd0\u884cPython\u811a\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u8bf8\u5982<code>cron<\/code>\uff08\u5728Linux\u548cmacOS\u4e0a\uff09\u6216<code>Task Scheduler<\/code>\uff08\u5728Windows\u4e0a\uff09\u7b49\u5de5\u5177\u6765\u5b9a\u671f\u8fd0\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5728Linux\u548cmacOS\u4e0a\u4f7f\u7528<code>cron<\/code><\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165 <code>crontab -e<\/code> \u6765\u7f16\u8f91cron\u4f5c\u4e1a\u3002<\/li>\n<li>\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684cron\u4f5c\u4e1a\u6761\u76ee\uff0c\u4f8b\u5982 <code>0 0 * * * \/usr\/bin\/python3 \/path\/to\/your_script.py<\/code>\uff0c\u8868\u793a\u6bcf\u5929\u5348\u591c\u8fd0\u884c\u4e00\u6b21Python\u811a\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5728Windows\u4e0a\u4f7f\u7528Task Scheduler<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u201c\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u201d\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u57fa\u672c\u4efb\u52a1\u3002<\/li>\n<li>\u8bbe\u7f6e\u89e6\u53d1\u5668\u548c\u64cd\u4f5c\uff0c\u9009\u62e9\u201c\u542f\u52a8\u7a0b\u5e8f\u201d\uff0c\u5e76\u8f93\u5165Python\u89e3\u91ca\u5668\u7684\u4f4d\u7f6e\u4ee5\u53caPython\u811a\u672c\u7684\u8def\u5f84\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u4f7f\u7528\u5728\u7ebf\u8fd0\u884c\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u6ca1\u6709\u672c\u5730\u8fd0\u884cPython\u4ee3\u7801\u7684\u73af\u5883\uff0c\u53ef\u4ee5\u4f7f\u7528\u5728\u7ebf\u8fd0\u884c\u73af\u5883\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Google Colab<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00Google Colab\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Notebook\u3002<\/li>\n<li>\u5728Notebook\u7684\u5355\u5143\u683c\u4e2d\u7f16\u5199Python\u4ee3\u7801\u3002<\/li>\n<li>\u70b9\u51fb\u201cRun\u201d\u6309\u94ae\u6765\u8fd0\u884c\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Repl.it<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00Repl.it\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Repl\u9879\u76ee\u3002<\/li>\n<li>\u9009\u62e9Python\u4f5c\u4e3a\u7f16\u7a0b\u8bed\u8a00\u3002<\/li>\n<li>\u5728\u7f16\u8f91\u5668\u4e2d\u7f16\u5199Python\u4ee3\u7801\uff0c\u7136\u540e\u70b9\u51fb\u201cRun\u201d\u6309\u94ae\u6765\u8fd0\u884c\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u7ed3\u8bed<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0a\u4ecb\u7ecd\u4e86\u8fd0\u884cPython\u4ee3\u7801\u6587\u4ef6\u7684\u51e0\u79cd\u5e38\u89c1\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u547d\u4ee4\u884c\u3001\u96c6\u6210\u5f00\u53d1\u73af\u5883\u3001\u811a\u672c\u6267\u884c\u5668\u548c\u5728\u7ebf\u8fd0\u884c\u73af\u5883\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u7684\u573a\u666f\u548c\u4f18\u7f3a\u70b9\u3002\u9009\u62e9\u6700\u9002\u5408\u81ea\u5df1\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c<strong>\u4f7f\u7528\u547d\u4ee4\u884c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883<\/strong> \u662f\u6700\u5e38\u89c1\u7684\u9009\u62e9\u3002\u5bf9\u4e8e\u65b0\u624b\u6765\u8bf4\uff0cIDE\u63d0\u4f9b\u7684\u53cb\u597d\u754c\u9762\u548c\u8c03\u8bd5\u529f\u80fd\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002\u800c\u5bf9\u4e8e\u9700\u8981\u81ea\u52a8\u5316\u4efb\u52a1\u7684\u573a\u666f\uff0c\u811a\u672c\u6267\u884c\u5668\u5219\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u9009\u62e9\u3002\u5728\u7ebf\u8fd0\u884c\u73af\u5883\u5219\u9002\u7528\u4e8e\u4e34\u65f6\u6d4b\u8bd5\u4ee3\u7801\u6216\u8005\u6ca1\u6709\u672c\u5730Python\u73af\u5883\u7684\u60c5\u51b5\u3002\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u8fd0\u884cPython\u4ee3\u7801\u6587\u4ef6\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884cPython\u4ee3\u7801\u6587\u4ef6\uff1f<\/strong><br \/>\u8981\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884cPython\u4ee3\u7801\u6587\u4ef6\uff0c\u60a8\u9700\u8981\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u63a5\u7740\uff0c\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230\u4ee3\u7801\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55\u3002\u7136\u540e\uff0c\u8f93\u5165<code>python \u6587\u4ef6\u540d.py<\/code>\uff08\u5bf9\u4e8ePython 3\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528<code>python3<\/code>\uff09\uff0c\u6309\u4e0b\u56de\u8f66\u952e\u5373\u53ef\u6267\u884c\u4ee3\u7801\u3002\u786e\u4fdd\u60a8\u7684\u8ba1\u7b97\u673a\u5df2\u6b63\u786e\u5b89\u88c5Python\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u7cfb\u7edf\u8def\u5f84\u4e2d\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u4e2d\u8fd0\u884cPython\u4ee3\u7801\u6587\u4ef6\uff1f<\/strong><br \/>\u5728\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08\u5982PyCharm\u3001VSCode\u6216Jupyter Notebook\uff09\u4e2d\u8fd0\u884cPython\u4ee3\u7801\u975e\u5e38\u7b80\u5355\u3002\u901a\u5e38\uff0c\u6253\u5f00\u6587\u4ef6\u540e\u53ef\u4ee5\u76f4\u63a5\u70b9\u51fb\u201c\u8fd0\u884c\u201d\u6309\u94ae\uff0c\u6216\u4f7f\u7528\u5feb\u6377\u952e\uff08\u5982Shift+F10\u5728PyCharm\u4e2d\uff09\u3002IDE\u4f1a\u81ea\u52a8\u68c0\u6d4b\u5e76\u6267\u884c\u4ee3\u7801\uff0c\u540c\u65f6\u663e\u793a\u8f93\u51fa\u7ed3\u679c\u548c\u9519\u8bef\u4fe1\u606f\uff0c\u65b9\u4fbf\u8c03\u8bd5\u3002<\/p>\n<p><strong>\u5982\u4f55\u8c03\u8bd5\u4e00\u4e2aPython\u4ee3\u7801\u6587\u4ef6\uff1f<\/strong><br \/>\u8c03\u8bd5Python\u4ee3\u7801\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5de5\u5177\u548c\u65b9\u6cd5\u3002\u5728\u96c6\u6210\u5f00\u53d1\u73af\u5883\u4e2d\uff0c\u901a\u5e38\u53ef\u4ee5\u8bbe\u7f6e\u65ad\u70b9\u5e76\u9010\u884c\u6267\u884c\u4ee3\u7801\uff0c\u4ee5\u89c2\u5bdf\u53d8\u91cf\u7684\u53d8\u5316\u548c\u4ee3\u7801\u7684\u6267\u884c\u6d41\u7a0b\u3002\u4f7f\u7528<code>print()<\/code>\u51fd\u6570\u4e5f\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u63d2\u5165\u8c03\u8bd5\u4fe1\u606f\uff0c\u5e2e\u52a9\u8bc6\u522b\u95ee\u9898\u7684\u6839\u6e90\u3002\u6b64\u5916\uff0cPython\u81ea\u5e26\u7684<code>pdb<\/code>\u6a21\u5757\u53ef\u4ee5\u7528\u6765\u8fdb\u884c\u66f4\u9ad8\u7ea7\u7684\u8c03\u8bd5\uff0c\u63d0\u4f9b\u4e30\u5bcc\u7684\u8c03\u8bd5\u529f\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u8fd0\u884c\u4e00\u4e2aPython\u4ee3\u7801\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u4f7f\u7528\u811a\u672c\u6267\u884c\u5668\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1094014,"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\/1094006"}],"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=1094006"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1094006\/revisions"}],"predecessor-version":[{"id":1094017,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1094006\/revisions\/1094017"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1094014"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1094006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1094006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1094006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}