{"id":990833,"date":"2024-12-27T08:23:31","date_gmt":"2024-12-27T00:23:31","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/990833.html"},"modified":"2024-12-27T08:23:33","modified_gmt":"2024-12-27T00:23:33","slug":"python%e5%a6%82%e4%bd%95%e8%bf%9b%e5%85%a5shell","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/990833.html","title":{"rendered":"python\u5982\u4f55\u8fdb\u5165shell"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065413\/a7073164-bd38-482c-aac5-bc220364b4c3.webp\" alt=\"python\u5982\u4f55\u8fdb\u5165shell\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u8fdb\u5165Shell\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u3001\u4f7f\u7528\u4ea4\u4e92\u5f0f\u5f00\u53d1\u5de5\u5177\u5982Jupyter Notebook\u3002<\/strong>\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\uff0c\u8fd9\u79cd\u65b9\u5f0f\u7b80\u5355\u76f4\u89c2\uff0c\u9002\u5408\u5feb\u901f\u6d4b\u8bd5\u4ee3\u7801\u548c\u8fdb\u884c\u7b80\u5355\u7684\u8ba1\u7b97\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4e0a\u8ff0\u547d\u4ee4\u540e\uff0c\u4f60\u5c06\u8fdb\u5165Python\u4ea4\u4e92\u5f0fShell\uff0c\u8fd9\u91cc\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u8fdb\u884c\u6d4b\u8bd5\u548c\u6267\u884c\u3002\u4e0b\u9762\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u547d\u4ee4\u884c<\/p>\n<\/p>\n<p><p>\u5728\u5927\u591a\u6570\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u5982Windows\u3001MacOS\u548cLinux\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u8fdb\u5165Python Shell\u662f\u4e00\u79cd\u5feb\u901f\u4e14\u5e38\u7528\u7684\u65b9\u6cd5\u3002\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u7136\u540e\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\uff08\u5177\u4f53\u7684\u547d\u4ee4\u53d6\u51b3\u4e8e\u4f60\u5b89\u88c5\u7684Python\u7248\u672c\u4ee5\u53ca\u7cfb\u7edf\u7684\u914d\u7f6e\uff09\uff0c\u6309\u4e0b\u56de\u8f66\u952e\u540e\uff0c\u4f60\u5c06\u770b\u5230\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u7684\u63d0\u793a\u7b26\uff1a<\/p>\n<\/p>\n<p><pre><code>Python 3.x.x (default, Oct  8 2023, 20:04:44)<\/p>\n<p>[GCC 7.3.0] on linux<\/p>\n<p>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<\/p>\n<p>&gt;&gt;&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a<code>&gt;&gt;&gt;<\/code>\u7b26\u53f7\u8868\u793a\u4f60\u5df2\u7ecf\u8fdb\u5165\u4e86Python Shell\u3002\u5728\u8fd9\u91cc\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165Python\u8bed\u53e5\u5e76\u6309\u4e0b\u56de\u8f66\u6765\u6267\u884c\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u5408\u5feb\u901f\u6267\u884c\u5c0f\u6bb5\u4ee3\u7801\uff0c\u8fdb\u884c\u7b80\u5355\u7684\u8ba1\u7b97\u6216\u6d4b\u8bd5\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/p>\n<\/p>\n<p><p>Python\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u529f\u80fd\uff0c\u5305\u62ec\u4ee3\u7801\u7f16\u8f91\u3001\u8c03\u8bd5\u548c\u7248\u672c\u63a7\u5236\u7b49\u3002\u5e38\u7528\u7684IDE\u6709PyCharm\u3001Visual Studio Code\u3001Anaconda\u7b49\u3002\u4ee5PyCharm\u4e3a\u4f8b\uff0c\u8fdb\u5165Python Shell\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00PyCharm\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u9879\u76ee\u3002<\/li>\n<li>\u5728\u4e0b\u65b9\u5de5\u5177\u680f\u4e2d\u627e\u5230\u201cTerminal\u201d\u9009\u9879\u5361\u5e76\u70b9\u51fb\u3002<\/li>\n<li>\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<\/ol>\n<p><p>\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728PyCharm\u4e2d\u4f7f\u7528Python Shell\u4e86\u3002\u4f7f\u7528IDE\u7684\u597d\u5904\u662f\uff0c\u4f60\u53ef\u4ee5\u5728\u540c\u4e00\u4e2a\u73af\u5883\u4e2d\u7f16\u5199\u3001\u6d4b\u8bd5\u548c\u8c03\u8bd5\u4ee3\u7801\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u4ea4\u4e92\u5f0f\u5f00\u53d1\u5de5\u5177<\/p>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u79cd\u57fa\u4e8eWeb\u7684\u4ea4\u4e92\u5f0f\u5f00\u53d1\u5de5\u5177\uff0c\u9002\u7528\u4e8e\u6570\u636e\u5206\u6790\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u7b49\u9886\u57df\u3002\u4f7f\u7528Jupyter Notebook\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u6d4f\u89c8\u5668\u4e2d\u8fd0\u884cPython\u4ee3\u7801\uff0c\u5e76\u5b9e\u65f6\u67e5\u770b\u7ed3\u679c\u3002<\/p>\n<\/p>\n<ol>\n<li>\u9996\u5148\u786e\u4fdd\u5df2\u5b89\u88c5Jupyter Notebook\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>pip install notebook<\/code>\u8fdb\u884c\u5b89\u88c5\u3002<\/li>\n<li>\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>jupyter notebook<\/code>\u5e76\u6309\u4e0b\u56de\u8f66\u3002<\/li>\n<li>\u6d4f\u89c8\u5668\u5c06\u81ea\u52a8\u6253\u5f00Jupyter Notebook\u4e3b\u9875\uff0c\u4f60\u53ef\u4ee5\u5728\u8fd9\u91cc\u521b\u5efa\u65b0\u7684Notebook\u5e76\u5f00\u59cb\u7f16\u5199Python\u4ee3\u7801\u3002<\/li>\n<\/ol>\n<p><p>\u5728Jupyter Notebook\u4e2d\uff0c\u6bcf\u4e2a\u4ee3\u7801\u5355\u5143\u90fd\u53ef\u4ee5\u5355\u72ec\u8fd0\u884c\uff0c\u7ed3\u679c\u4f1a\u663e\u793a\u5728\u5355\u5143\u4e0b\u65b9\uff0c\u975e\u5e38\u9002\u5408\u5b9e\u9a8c\u6027\u7f16\u7a0b\u548c\u6570\u636e\u5206\u6790\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u901a\u8fc7Python\u811a\u672c\u8fdb\u5165Shell<\/p>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u5728\u6267\u884cPython\u811a\u672c\u540e\u8fdb\u5165Shell\uff0c\u53ef\u4ee5\u4f7f\u7528<code>code.interact()<\/code>\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import code<\/p>\n<p>def m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n():<\/p>\n<p>    print(&quot;Python Shell&quot;)<\/p>\n<p>    code.interact(local=locals())<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u8fd9\u4e2a\u811a\u672c\u540e\uff0c\u7a0b\u5e8f\u4f1a\u8fdb\u5165Python Shell\uff0c\u5141\u8bb8\u4f60\u4ea4\u4e92\u5f0f\u5730\u6267\u884c\u4ee3\u7801\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u7528\u4e8e\u8c03\u8bd5\u6216\u5728\u7279\u5b9a\u7684\u811a\u672c\u6267\u884c\u540e\u63d0\u4f9b\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u8fdb\u5165IPython Shell<\/p>\n<\/p>\n<p><p>IPython\u662fPython\u7684\u4e00\u4e2a\u589e\u5f3a\u7248Shell\uff0c\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u529f\u80fd\u548c\u66f4\u52a0\u53cb\u597d\u7684\u7528\u6237\u4f53\u9a8c\u3002\u8981\u4f7f\u7528IPython Shell\uff0c\u4f60\u9700\u8981\u5148\u5b89\u88c5IPython\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install ipython<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>ipython<\/code>\u5e76\u6309\u4e0b\u56de\u8f66\uff0c\u5373\u53ef\u8fdb\u5165IPython Shell\u3002IPython\u652f\u6301\u8bed\u6cd5\u9ad8\u4eae\u3001\u81ea\u52a8\u8865\u5168\u548c\u9b54\u6cd5\u547d\u4ee4\u7b49\u529f\u80fd\uff0c\u4f7f\u5f97\u5f00\u53d1\u66f4\u52a0\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3\uff1a<\/p>\n<\/p>\n<p><p>\u8fdb\u5165Python Shell\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5177\u4f53\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u4f60\u7684\u9700\u6c42\u548c\u5de5\u4f5c\u73af\u5883\u3002\u5bf9\u4e8e\u5feb\u901f\u6d4b\u8bd5\u4ee3\u7801\uff0c\u547d\u4ee4\u884c\u662f\u6700\u7b80\u5355\u7684\u65b9\u5f0f\uff1b\u5bf9\u4e8e\u590d\u6742\u9879\u76ee\u5f00\u53d1\uff0cIDE\u548cJupyter Notebook\u63d0\u4f9b\u4e86\u66f4\u4e3a\u5f3a\u5927\u7684\u529f\u80fd\u548c\u4fbf\u5229\u6027\u3002\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u5f0f\uff0c\u638c\u63e1Python Shell\u7684\u4f7f\u7528\u6280\u5de7\u90fd\u80fd\u6781\u5927\u63d0\u9ad8\u7f16\u7a0b\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8fdb\u5165\u4ea4\u4e92\u5f0fShell\uff1f<\/strong><br \/>\u8981\u8fdb\u5165Python\u7684\u4ea4\u4e92\u5f0fShell\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\uff0c\u8fd9\u5c06\u542f\u52a8Python\u89e3\u91ca\u5668\u3002\u7528\u6237\u53ef\u4ee5\u5728Shell\u4e2d\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u5e76\u7acb\u5373\u770b\u5230\u7ed3\u679c\uff0c\u975e\u5e38\u9002\u5408\u8fdb\u884c\u5feb\u901f\u6d4b\u8bd5\u548c\u5b9e\u9a8c\u3002<\/p>\n<p><strong>\u5728Python Shell\u4e2d\u53ef\u4ee5\u6267\u884c\u54ea\u4e9b\u64cd\u4f5c\uff1f<\/strong><br \/>Python Shell\u652f\u6301\u57fa\u672c\u7684\u6570\u5b66\u8fd0\u7b97\u3001\u53d8\u91cf\u5b9a\u4e49\u3001\u51fd\u6570\u521b\u5efa\u548c\u6a21\u5757\u5bfc\u5165\u7b49\u64cd\u4f5c\u3002\u7528\u6237\u53ef\u4ee5\u8f93\u5165\u8868\u8fbe\u5f0f\uff0cShell\u4f1a\u81ea\u52a8\u8ba1\u7b97\u5e76\u8fd4\u56de\u7ed3\u679c\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528<code>help()<\/code>\u51fd\u6570\u83b7\u53d6\u5173\u4e8ePython\u5185\u7f6e\u51fd\u6570\u548c\u6a21\u5757\u7684\u5e2e\u52a9\u4fe1\u606f\u3002<\/p>\n<p><strong>\u5982\u4f55\u9000\u51faPython Shell\uff1f<\/strong><br \/>\u8981\u9000\u51faPython\u7684\u4ea4\u4e92\u5f0fShell\uff0c\u7528\u6237\u53ef\u4ee5\u8f93\u5165<code>exit()<\/code>\u6216\u6309\u4e0b<code>Ctrl + D<\/code>\uff08\u5728Unix\/Linux\u7cfb\u7edf\u4e2d\uff09\u6216\u8005<code>Ctrl + Z<\/code>\u540e\u6309Enter\uff08\u5728Windows\u7cfb\u7edf\u4e2d\uff09\u3002\u8fd9\u5c06\u7ed3\u675f\u5f53\u524d\u7684Shell\u4f1a\u8bdd\u5e76\u8fd4\u56de\u5230\u64cd\u4f5c\u7cfb\u7edf\u7684\u547d\u4ee4\u63d0\u793a\u7b26\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8fdb\u5165Shell\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u8f93\u5165python\u6216python3\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af [&hellip;]","protected":false},"author":3,"featured_media":990839,"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\/990833"}],"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=990833"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/990833\/revisions"}],"predecessor-version":[{"id":990840,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/990833\/revisions\/990840"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/990839"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=990833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=990833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=990833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}