{"id":972258,"date":"2024-12-27T05:47:06","date_gmt":"2024-12-26T21:47:06","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/972258.html"},"modified":"2024-12-27T05:47:08","modified_gmt":"2024-12-26T21:47:08","slug":"python-%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\/972258.html","title":{"rendered":"python \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\/24195016\/6ad51581-adad-4fe2-addb-bc62ab413b16.webp\" alt=\"python \u5982\u4f55\u8fd0\u884c\u7a0b\u5e8f\" \/><\/p>\n<p><p> <strong>\u8981\u8fd0\u884cPython\u7a0b\u5e8f\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\uff08\u5982Terminal\u6216Cmd\uff09\u3001\u4f7f\u7528Python\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u3001Jupyter Notebook\u6216VS Code\u3001\u5229\u7528\u5728\u7ebf\u7f16\u8bd1\u5668\u3002<\/strong>\u5176\u4e2d\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u662f\u6700\u57fa\u7840\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u7cfb\u7edf\u4e2d\u4f7f\u7528\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e2d\u8be6\u7ec6\u8fd0\u884cPython\u7a0b\u5e8f\u7684\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>\u5728\u8fd0\u884cPython\u7a0b\u5e8f\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u8ba1\u7b97\u673a\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u3002\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff08python.org\uff09\u4e0b\u8f7d\u9002\u5408\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u5305\u5e76\u8fdb\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python --version<\/code>\u6765\u9a8c\u8bc1\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u7f16\u5199Python\u4ee3\u7801\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u5728\u4efb\u4f55\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\uff0c\u5e76\u5c06\u6587\u4ef6\u547d\u540d\u4e3a<code>example.py<\/code>\uff0c\u7136\u540e\u7f16\u5199\u4f60\u7684Python\u4ee3\u7801\u3002\u4f8b\u5982\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>\u5c06\u6b64\u4ee3\u7801\u4fdd\u5b58\u5728<code>example.py<\/code>\u6587\u4ef6\u4e2d\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884cPython\u7a0b\u5e8f<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177<\/strong><\/p>\n<\/p>\n<ul>\n<li><strong>Windows<\/strong>\uff1a\u6309\u4e0b<code>Windows + R<\/code>\u952e\uff0c\u8f93\u5165<code>cmd<\/code>\u7136\u540e\u6309Enter\u3002<\/li>\n<li><strong>MacOS\u548cLinux<\/strong>\uff1a\u6253\u5f00\u7ec8\u7aef\u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5bfc\u822a\u5230Python\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\uff08change directory\uff09\u5bfc\u822a\u5230\u4f60\u4fdd\u5b58Python\u6587\u4ef6\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u6587\u4ef6\u4fdd\u5b58\u5728\u684c\u9762\u4e0a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd Desktop<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u547d\u4ee4<code>python example.py<\/code>\uff08\u6216<code>python3 example.py<\/code>\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u4f60\u7684Python\u5b89\u88c5\uff09\u6765\u8fd0\u884c\u6587\u4ef6\u3002\u5982\u679cPython\u5b89\u88c5\u6b63\u786e\u4e14\u8def\u5f84\u6b63\u786e\uff0c\u4f60\u5e94\u8be5\u80fd\u770b\u5230\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">Hello, World!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>PyCharm<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4e0b\u8f7d\u5e76\u5b89\u88c5PyCharm\u3002<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u9879\u76ee\u5e76\u6dfb\u52a0Python\u6587\u4ef6\u3002<\/li>\n<li>\u5728PyCharm\u7f16\u8f91\u5668\u4e2d\u7f16\u5199\u4f60\u7684\u4ee3\u7801\uff0c\u7136\u540e\u70b9\u51fb\u8fd0\u884c\u6309\u94ae\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>VS Code<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5b89\u88c5VS Code\u548cPython\u6269\u5c55\u3002<\/li>\n<li>\u6253\u5f00Python\u6587\u4ef6\u5e76\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Jupyter Notebook<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5b89\u88c5Jupyter Notebook\uff08\u53ef\u4ee5\u901a\u8fc7Anaconda\u5b89\u88c5\uff09\u3002<\/li>\n<li>\u542f\u52a8Notebook\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python Notebook\u3002<\/li>\n<li>\u5728\u5355\u5143\u683c\u4e2d\u7f16\u5199Python\u4ee3\u7801\u5e76\u6267\u884c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5728\u7ebf\u8fd0\u884cPython\u4ee3\u7801<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4e0d\u60f3\u5728\u672c\u5730\u5b89\u88c5Python\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5728\u7ebf\u7f16\u8bd1\u5668\u5982Repl.it\u3001Google Colab\u7b49\u5e73\u53f0\uff0c\u76f4\u63a5\u5728\u6d4f\u89c8\u5668\u4e2d\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u5728\u672c\u5730\u6216\u5728\u7ebf\u73af\u5883\u4e2d\u8fd0\u884cPython\u7a0b\u5e8f\u3002<strong>\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u662f\u6700\u57fa\u7840\u4e14\u901a\u7528\u7684\u65b9\u6cd5<\/strong>\uff0c\u800cIDE\u548c\u5728\u7ebf\u5de5\u5177\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u5f00\u53d1\u4fbf\u5229\u548c\u8c03\u8bd5\u529f\u80fd\u3002\u9009\u62e9\u9002\u5408\u4f60\u7684\u5f00\u53d1\u73af\u5883\u53ef\u4ee5\u6781\u5927\u63d0\u9ad8\u7f16\u7a0b\u6548\u7387\u548c\u4f53\u9a8c\u3002\u65e0\u8bba\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u786e\u4fddPython\u5b89\u88c5\u6b63\u786e\u662f\u6210\u529f\u8fd0\u884c\u7a0b\u5e8f\u7684\u524d\u63d0\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884cPython\u7a0b\u5e8f\uff1f<\/strong><br \/>\u5728Windows\u7cfb\u7edf\u4e0a\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u63d0\u793a\u7b26\u6216PowerShell\u8fd0\u884cPython\u7a0b\u5e8f\u3002\u53ea\u9700\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u5bfc\u822a\u5230\u5305\u542bPython\u6587\u4ef6\u7684\u76ee\u5f55\uff0c\u8f93\u5165<code>python \u6587\u4ef6\u540d.py<\/code>\u6765\u6267\u884c\u3002\u5728macOS\u6216Linux\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u7ec8\u7aef\uff0c\u6b65\u9aa4\u7c7b\u4f3c\u3002\u786e\u4fddPython\u5df2\u6b63\u786e\u5b89\u88c5\uff0c\u5e76\u4e14\u73af\u5883\u53d8\u91cf\u5df2\u914d\u7f6e\u3002<\/p>\n<p><strong>\u6211\u5982\u4f55\u786e\u4fdd\u6211\u7684Python\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u6ca1\u6709\u9519\u8bef\uff1f<\/strong><br \/>\u5728\u8fd0\u884cPython\u7a0b\u5e8f\u4e4b\u524d\uff0c\u5efa\u8bae\u4f7f\u7528IDE\uff08\u5982PyCharm\u6216VS Code\uff09\u6765\u8fdb\u884c\u4ee3\u7801\u7f16\u8f91\u548c\u8c03\u8bd5\u3002\u8fd9\u4e9b\u5de5\u5177\u901a\u5e38\u4f1a\u63d0\u4f9b\u8bed\u6cd5\u9ad8\u4eae\u3001\u9519\u8bef\u63d0\u793a\u548c\u8c03\u8bd5\u529f\u80fd\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5728\u8fd0\u884c\u4e4b\u524d\u53d1\u73b0\u6f5c\u5728\u95ee\u9898\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528<code>python -m py_compile \u6587\u4ef6\u540d.py<\/code>\u547d\u4ee4\u6765\u68c0\u67e5\u4ee3\u7801\u7684\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528\u547d\u4ee4\u884c\u53c2\u6570\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u901a\u8fc7<code>sys<\/code>\u6a21\u5757\u5728Python\u7a0b\u5e8f\u4e2d\u63a5\u6536\u547d\u4ee4\u884c\u53c2\u6570\u3002\u9996\u5148\uff0c\u5bfc\u5165<code>sys<\/code>\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528<code>sys.argv<\/code>\u6765\u8bbf\u95ee\u4f20\u9012\u7ed9\u7a0b\u5e8f\u7684\u53c2\u6570\u3002<code>sys.argv[0]<\/code>\u662f\u811a\u672c\u7684\u540d\u79f0\uff0c\u540e\u7eed\u7684\u7d22\u5f15\u5305\u542b\u5176\u4ed6\u53c2\u6570\u3002\u8fd9\u6837\u53ef\u4ee5\u4f7f\u60a8\u7684\u7a0b\u5e8f\u66f4\u7075\u6d3b\u548c\u52a8\u6001\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u4f20\u9012\u8f93\u5165\u6587\u4ef6\u540d\u6216\u5176\u4ed6\u914d\u7f6e\u9009\u9879\u6765\u5f71\u54cd\u7a0b\u5e8f\u7684\u884c\u4e3a\u3002<\/p>\n<p><strong>\u6211\u53ef\u4ee5\u5728Python\u4e2d\u8fd0\u884c\u591a\u4e2a\u7a0b\u5e8f\u5b9e\u4f8b\u5417\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u60a8\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u547d\u4ee4\u884c\u7a97\u53e3\u4e2d\u542f\u52a8\u591a\u4e2aPython\u7a0b\u5e8f\u5b9e\u4f8b\u3002\u6bcf\u4e2a\u5b9e\u4f8b\u90fd\u5c06\u5728\u72ec\u7acb\u7684\u8fdb\u7a0b\u4e2d\u8fd0\u884c\uff0c\u5e76\u4e14\u53ef\u4ee5\u4e92\u4e0d\u5e72\u6270\u3002\u786e\u4fdd\u6bcf\u4e2a\u5b9e\u4f8b\u4f7f\u7528\u4e0d\u540c\u7684\u8d44\u6e90\uff08\u5982\u6587\u4ef6\u6216\u7aef\u53e3\uff09\uff0c\u4ee5\u907f\u514d\u51b2\u7a81\u3002\u5982\u679c\u9700\u8981\u5728\u540c\u4e00\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u5e76\u53d1\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u7ebf\u7a0b\u6216\u5f02\u6b65\u7f16\u7a0b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u8fd0\u884cPython\u7a0b\u5e8f\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\uff08\u5982Terminal\u6216Cmd\uff09\u3001\u4f7f\u7528Python [&hellip;]","protected":false},"author":3,"featured_media":972265,"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\/972258"}],"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=972258"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/972258\/revisions"}],"predecessor-version":[{"id":972267,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/972258\/revisions\/972267"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/972265"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=972258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=972258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=972258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}