{"id":1072201,"date":"2025-01-08T11:14:09","date_gmt":"2025-01-08T03:14:09","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1072201.html"},"modified":"2025-01-08T11:14:12","modified_gmt":"2025-01-08T03:14:12","slug":"python%e5%a6%82%e4%bd%95%e4%b8%80%e6%ad%a5%e6%89%a7%e8%a1%8c%e7%a8%8b%e5%ba%8f-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1072201.html","title":{"rendered":"python\u5982\u4f55\u4e00\u6b65\u6267\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\/25102521\/c9de12b5-a810-4c36-a093-6595351c60bc.webp\" alt=\"python\u5982\u4f55\u4e00\u6b65\u6267\u884c\u7a0b\u5e8f\" \/><\/p>\n<p><p> <strong>Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u4e00\u6b65\u6267\u884c\u7a0b\u5e8f\uff0c\u5305\u62ec\u4f7f\u7528\u547d\u4ee4\u884c\u3001IDE\u3001\u811a\u672c\u6587\u4ef6\u7b49\u3002<\/strong> \u5176\u4e2d\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u662f\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\uff0c\u53ea\u9700\u5728\u7ec8\u7aef\u8f93\u5165 <code>python your_script.py<\/code> \u5373\u53ef\u8fd0\u884c\u6307\u5b9a\u7684Python\u811a\u672c\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u901a\u8fc7\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u3001VS Code\u7b49\u6765\u4e00\u6b65\u8fd0\u884c\u7a0b\u5e8f\uff0c\u8fd9\u4e9b\u5de5\u5177\u901a\u5e38\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u201c\u8fd0\u884c\u201d\u6309\u94ae\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u6765\u4e00\u6b65\u6267\u884cPython\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u6267\u884cPython\u7a0b\u5e8f<\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884cPython\u7a0b\u5e8f\u662f\u4e00\u79cd\u5e38\u89c1\u4e14\u7b80\u5355\u7684\u65b9\u6cd5\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u89e3\u91ca\u5668\u3002\u7136\u540e\uff0c\u6253\u5f00\u7ec8\u7aef\uff08\u547d\u4ee4\u63d0\u793a\u7b26\uff09\u5e76\u5bfc\u822a\u5230\u4f60\u7684Python\u811a\u672c\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55\u3002\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u662f\u7b80\u5355\u76f4\u63a5\uff0c\u9002\u7528\u4e8e\u6240\u6709\u64cd\u4f5c\u7cfb\u7edf\u3002\u540c\u65f6\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u53c2\u6570\u6765\u63a7\u5236\u811a\u672c\u7684\u884c\u4e3a\uff0c\u4f8b\u5982\u4f20\u9012\u8f93\u5165\u53c2\u6570\u3001\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u6267\u884cPython\u7a0b\u5e8f<\/p>\n<\/p>\n<p><p>\u4f7f\u7528IDE\u6765\u6267\u884cPython\u7a0b\u5e8f\u4e0d\u4ec5\u65b9\u4fbf\uff0c\u800c\u4e14\u53ef\u4ee5\u63d0\u4f9b\u66f4\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u5982\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u7b49\u3002\u4e0b\u9762\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u7684IDE\u53ca\u5176\u4f7f\u7528\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><p>1\u3001PyCharm<\/p>\n<\/p>\n<p><p>PyCharm\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python IDE\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u5f3a\u5927\u7684\u529f\u80fd\u3002\u8981\u5728PyCharm\u4e2d\u8fd0\u884cPython\u811a\u672c\uff0c\u53ea\u9700\u6253\u5f00\u9879\u76ee\uff0c\u7136\u540e\u5728\u9879\u76ee\u7a97\u53e3\u4e2d\u627e\u5230\u4f60\u8981\u8fd0\u884c\u7684\u811a\u672c\u6587\u4ef6\uff0c\u53f3\u952e\u70b9\u51fb\u5e76\u9009\u62e9\u201cRun &#39;your_script&#39;\u201d\u5373\u53ef\u3002\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5feb\u6377\u952e Shift + F10 \u6765\u8fd0\u884c\u5f53\u524d\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>2\u3001Visual Studio Code (VS Code)<\/p>\n<\/p>\n<p><p>VS Code\u662f\u4e00\u6b3e\u8f7b\u91cf\u7ea7\u4f46\u529f\u80fd\u5f3a\u5927\u7684\u4ee3\u7801\u7f16\u8f91\u5668\uff0c\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\uff0c\u5305\u62ecPython\u3002\u5b89\u88c5Python\u6269\u5c55\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u7f16\u8f91\u5668\u4e2d\u76f4\u63a5\u8fd0\u884cPython\u811a\u672c\u3002\u70b9\u51fb\u53f3\u4e0a\u89d2\u7684\u201c\u8fd0\u884c\u201d\u6309\u94ae\uff0c\u6216\u8005\u4f7f\u7528\u5feb\u6377\u952e Ctrl + F5 \u6765\u8fd0\u884c\u5f53\u524d\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>3\u3001Jupyter Notebook<\/p>\n<\/p>\n<p><p>Jupyter Notebook \u662f\u4e00\u79cd\u4ea4\u4e92\u5f0f\u7f16\u7a0b\u73af\u5883\uff0c\u7279\u522b\u9002\u5408\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u4efb\u52a1\u3002\u5728Jupyter Notebook\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4e00\u6b65\u4e00\u6b65\u5730\u8fd0\u884c\u4ee3\u7801\u5757\uff0c\u5e76\u5373\u65f6\u67e5\u770b\u8f93\u51fa\u7ed3\u679c\u3002\u8981\u8fd0\u884c\u4e00\u4e2a\u4ee3\u7801\u5757\uff0c\u53ea\u9700\u70b9\u51fb\u4ee3\u7801\u5757\u5de6\u4fa7\u7684\u8fd0\u884c\u6309\u94ae\uff0c\u6216\u8005\u4f7f\u7528\u5feb\u6377\u952e Shift + Enter\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u811a\u672c\u6587\u4ef6\u6267\u884cPython\u7a0b\u5e8f<\/p>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u5c06Python\u4ee3\u7801\u4fdd\u5b58\u4e3a\u4e00\u4e2a\u811a\u672c\u6587\u4ef6\uff08\u901a\u5e38\u4ee5 <code>.py<\/code> \u7ed3\u5c3e\uff09\uff0c\u7136\u540e\u901a\u8fc7\u53cc\u51fb\u8be5\u6587\u4ef6\u6765\u8fd0\u884c\u7a0b\u5e8f\u3002\u8fd9\u79cd\u65b9\u6cd5\u5728Windows\u7cfb\u7edf\u4e0a\u7279\u522b\u65b9\u4fbf\uff0c\u4f60\u53ea\u9700\u786e\u4fdd\u4f60\u7684\u7cfb\u7edf\u5df2\u7ecf\u914d\u7f6e\u597dPython\u89e3\u91ca\u5668\uff0c\u5e76\u5c06 <code>.py<\/code> \u6587\u4ef6\u5173\u8054\u5230Python\u89e3\u91ca\u5668\u3002\u53cc\u51fb\u811a\u672c\u6587\u4ef6\u540e\uff0cPython\u89e3\u91ca\u5668\u4f1a\u81ea\u52a8\u542f\u52a8\u5e76\u8fd0\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u6267\u884c\u4ee3\u7801<\/p>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\uff0c\u53ef\u4ee5\u8ba9\u4f60\u4e00\u6b65\u4e00\u6b65\u5730\u8f93\u5165\u548c\u6267\u884c\u4ee3\u7801\u3002\u8fd9\u79cd\u65b9\u6cd5\u7279\u522b\u9002\u5408\u6d4b\u8bd5\u548c\u8c03\u8bd5\u5c0f\u6bb5\u4ee3\u7801\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165 <code>python<\/code> \u6216 <code>python3<\/code>\uff08\u53d6\u51b3\u4e8e\u4f60\u7684Python\u7248\u672c\uff09\u5373\u53ef\u542f\u52a8\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u3002\u4f60\u53ef\u4ee5\u5728\u63d0\u793a\u7b26\u4e0b\u8f93\u5165Python\u4ee3\u7801\uff0c\u5e76\u5373\u65f6\u67e5\u770b\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u81ea\u52a8\u5316\u811a\u672c\u548c\u4efb\u52a1\u8c03\u5ea6<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u5b9a\u671f\u8fd0\u884c\u7684Python\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4efb\u52a1\u8c03\u5ea6\u5de5\u5177\u6765\u81ea\u52a8\u6267\u884c\u811a\u672c\u3002\u4f8b\u5982\uff0c\u5728Windows\u7cfb\u7edf\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\uff08Task Scheduler\uff09\u6765\u5b89\u6392\u5b9a\u65f6\u4efb\u52a1\uff1b\u5728Unix\/Linux\u7cfb\u7edf\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528cron\u4f5c\u4e1a\u6765\u81ea\u52a8\u8fd0\u884c\u811a\u672c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5b9a\u671f\u6267\u884c\u7684\u6279\u5904\u7406\u4efb\u52a1\uff0c\u4f8b\u5982\u6570\u636e\u5907\u4efd\u3001\u65e5\u5fd7\u5206\u6790\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u603b\u4e4b\uff0c\u4e00\u6b65\u6267\u884cPython\u7a0b\u5e8f\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5177\u4f53\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u4f60\u7684\u9700\u6c42\u548c\u4f7f\u7528\u4e60\u60ef\u3002\u65e0\u8bba\u662f\u4f7f\u7528\u547d\u4ee4\u884c\u3001IDE\u3001\u811a\u672c\u6587\u4ef6\uff0c\u8fd8\u662f\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\uff0c\u90fd\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fd0\u884cPython\u7a0b\u5e8f\u3002\u901a\u8fc7\u5408\u7406\u9009\u62e9\u548c\u914d\u7f6e\u5de5\u5177\uff0c\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u4f60\u7684\u5f00\u53d1\u6548\u7387\u548c\u5de5\u4f5c\u8d28\u91cf\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u4e00\u6b65\u6267\u884c\u7a0b\u5e8f\u7684\u529f\u80fd\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\u5982PDB\uff08Python Debugger\uff09\u6765\u9010\u884c\u6267\u884c\u4ee3\u7801\u3002\u901a\u8fc7\u5728\u4ee3\u7801\u4e2d\u63d2\u5165<code>import pdb; pdb.set_trace()<\/code>\uff0c\u4f60\u53ef\u4ee5\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u8fdb\u5165\u8c03\u8bd5\u6a21\u5f0f\uff0c\u9010\u884c\u6267\u884c\u5e76\u68c0\u67e5\u53d8\u91cf\u72b6\u6001\u3002\u6b64\u5916\uff0c\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u6216VS Code\u4e5f\u63d0\u4f9b\u4e86\u56fe\u5f62\u5316\u7684\u8c03\u8bd5\u529f\u80fd\uff0c\u4f7f\u5f97\u9010\u6b65\u6267\u884c\u7a0b\u5e8f\u53d8\u5f97\u66f4\u52a0\u76f4\u89c2\u548c\u4fbf\u6377\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u6267\u884cPython\u7a0b\u5e8f\u5e76\u9010\u6b65\u8c03\u8bd5\uff1f<\/strong><br \/>\u786e\u5b9e\u53ef\u4ee5\u3002\u901a\u8fc7\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528<code>python -m pdb your_script.py<\/code>\u547d\u4ee4\uff0c\u4f60\u53ef\u4ee5\u542f\u52a8Python\u7a0b\u5e8f\u7684\u8c03\u8bd5\u6a21\u5f0f\u3002\u8fd9\u5c06\u5141\u8bb8\u4f60\u901a\u8fc7\u8f93\u5165\u7279\u5b9a\u7684\u547d\u4ee4\u6765\u9010\u6b65\u6267\u884c\u7a0b\u5e8f\uff0c\u4f8b\u5982\u4f7f\u7528<code>n<\/code>\u547d\u4ee4\u6267\u884c\u4e0b\u4e00\u884c\u4ee3\u7801\uff0c\u6216\u4f7f\u7528<code>c<\/code>\u547d\u4ee4\u7ee7\u7eed\u6267\u884c\u5230\u4e0b\u4e00\u4e2a\u65ad\u70b9\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Jupyter Notebook\u4e2d\u9010\u6b65\u6267\u884cPython\u4ee3\u7801\uff1f<\/strong><br \/>\u5728Jupyter Notebook\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528<code>%debug<\/code>\u9b54\u6cd5\u547d\u4ee4\u6765\u8fdb\u5165\u8c03\u8bd5\u6a21\u5f0f\u3002\u8fd9\u5728\u4ee3\u7801\u53d1\u751f\u5f02\u5e38\u65f6\u7279\u522b\u6709\u7528\uff0c\u4f60\u53ef\u4ee5\u67e5\u770b\u9519\u8bef\u53d1\u751f\u524d\u7684\u53d8\u91cf\u72b6\u6001\uff0c\u5e76\u9010\u6b65\u6267\u884c\u4ee3\u7801\u5757\u3002\u6b64\u5916\uff0cJupyter Notebook\u7684\u5355\u5143\u683c\u6267\u884c\u7279\u6027\u4e5f\u5141\u8bb8\u4f60\u9010\u884c\u8fd0\u884c\u4ee3\u7801\uff0c\u4fbf\u4e8e\u6d4b\u8bd5\u548c\u8c03\u8bd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u4e00\u6b65\u6267\u884c\u7a0b\u5e8f\uff0c\u5305\u62ec\u4f7f\u7528\u547d\u4ee4\u884c\u3001IDE\u3001\u811a\u672c\u6587\u4ef6\u7b49\u3002 \u5176\u4e2d\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u662f\u6700\u76f4\u63a5\u7684\u65b9\u6cd5 [&hellip;]","protected":false},"author":3,"featured_media":1072215,"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\/1072201"}],"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=1072201"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1072201\/revisions"}],"predecessor-version":[{"id":1072218,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1072201\/revisions\/1072218"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1072215"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1072201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1072201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1072201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}