{"id":1175431,"date":"2025-01-15T17:31:52","date_gmt":"2025-01-15T09:31:52","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1175431.html"},"modified":"2025-01-15T17:31:55","modified_gmt":"2025-01-15T09:31:55","slug":"python%e5%a6%82%e4%bd%95%e8%bf%9b%e5%85%a5%e4%ba%a4%e4%ba%92%e7%95%8c%e9%9d%a2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1175431.html","title":{"rendered":"python\u5982\u4f55\u8fdb\u5165\u4ea4\u4e92\u754c\u9762"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25110904\/b26c4145-2944-4963-9c95-aed0e4fc4fcb.webp\" alt=\"python\u5982\u4f55\u8fdb\u5165\u4ea4\u4e92\u754c\u9762\" \/><\/p>\n<p><p> <strong>Python\u8fdb\u5165\u4ea4\u4e92\u754c\u9762\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Python\u89e3\u91ca\u5668\u3001\u4f7f\u7528Jupyter Notebook\u3001\u4f7f\u7528IPython\u3001\u5728IDE\u5185\u4f7f\u7528\u4ea4\u4e92\u7a97\u53e3\u3002<\/strong><\/p>\n<\/p>\n<p><p><strong>Python\u89e3\u91ca\u5668<\/strong>\u662f\u6700\u5e38\u89c1\u548c\u6700\u57fa\u672c\u7684\u8fdb\u5165\u4ea4\u4e92\u754c\u9762\u7684\u65b9\u6cd5\u3002\u542f\u52a8Python\u89e3\u91ca\u5668\u7684\u65b9\u6cd5\u6709\u591a\u79cd\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u89e3\u91ca\u5668\u8fdb\u5165\u4ea4\u4e92\u754c\u9762\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Python\u89e3\u91ca\u5668<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u547d\u4ee4\u884c\u6216\u7ec8\u7aef<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u201c\u547d\u4ee4\u63d0\u793a\u7b26\u201d\u6216\u201cPowerShell\u201d\u3002<\/li>\n<li>\u5728macOS\u548cLinux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u201c\u7ec8\u7aef\u201d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8f93\u5165python\u6216python3\u547d\u4ee4<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002\u8fd9\u91cc\u7684<code>python3<\/code>\u9002\u7528\u4e8e\u5b89\u88c5\u4e86Python 3.x\u7248\u672c\u7684\u7cfb\u7edf\uff0c\u800c<code>python<\/code>\u901a\u5e38\u9002\u7528\u4e8ePython 2.x\u7248\u672c\uff0c\u6216\u8005\u5728\u67d0\u4e9b\u7cfb\u7edf\u4e2d\u4e5f\u53ef\u80fd\u76f4\u63a5\u6307\u5411Python 3.x\u3002<\/li>\n<li>\u4f8b\u5982\uff1a\n<pre><code class=\"language-bash\">$ python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u5728\u6b63\u786e\u8f93\u5165\u547d\u4ee4\u540e\uff0c\u4f60\u4f1a\u770b\u5230\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u7684\u63d0\u793a\u7b26\uff0c\u8868\u793a\u5df2\u7ecf\u8fdb\u5165\u4e86Python\u4ea4\u4e92\u754c\u9762\uff1a\n<pre><code class=\"language-python\">Python 3.8.5 (default, Jul 28 2020, 12:59:40)<\/p>\n<p>[Clang 11.0.3 (clang-1103.0.32.62)] on darwin<\/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<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8f93\u5165Python\u4ee3\u7801<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u73b0\u5728\uff0c\u4f60\u53ef\u4ee5\u5728\u63d0\u793a\u7b26<code>&gt;&gt;&gt;<\/code>\u540e\u8f93\u5165\u4efb\u610f\u6709\u6548\u7684Python\u4ee3\u7801\uff0c\u5e76\u6309\u56de\u8f66\u952e\u6267\u884c\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\u5e76\u6309\u56de\u8f66\u952e\uff1a\n<pre><code class=\"language-python\">&gt;&gt;&gt; print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u8f93\u51fa\u5c06\u4f1a\u662f\uff1a\n<pre><code class=\"language-python\">Hello, World!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Jupyter Notebook<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Jupyter Notebook<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Jupyter Notebook\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a\n<pre><code class=\"language-bash\">$ pip install notebook<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u542f\u52a8Jupyter Notebook<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5e76\u6309\u56de\u8f66\u952e\uff1a\n<pre><code class=\"language-bash\">$ jupyter notebook<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u8fd9\u4f1a\u5728\u9ed8\u8ba4\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00\u4e00\u4e2a\u65b0\u7684\u7a97\u53e3\u6216\u6807\u7b7e\uff0c\u663e\u793aJupyter Notebook\u7684\u754c\u9762\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u65b0\u7684Notebook<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728Jupyter Notebook\u754c\u9762\u4e2d\uff0c\u70b9\u51fb\u201cNew\u201d\u6309\u94ae\uff0c\u7136\u540e\u9009\u62e9\u201cPython 3\u201d\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Notebook\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8f93\u5165\u5e76\u8fd0\u884c\u4ee3\u7801<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u65b0\u7684Notebook\u5355\u5143\u683c\u4e2d\u8f93\u5165Python\u4ee3\u7801\uff0c\u7136\u540e\u6309\u201cShift + Enter\u201d\u952e\u8fd0\u884c\u4ee3\u7801\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a\n<pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u8fd0\u884c\u540e\u5c06\u663e\u793a\u8f93\u51fa\u7ed3\u679c\uff1a\n<pre><code class=\"language-python\">Hello, World!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u4f7f\u7528IPython<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5IPython<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86IPython\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a\n<pre><code class=\"language-bash\">$ pip install ipython<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u542f\u52a8IPython<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5e76\u6309\u56de\u8f66\u952e\uff1a\n<pre><code class=\"language-bash\">$ ipython<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u4f60\u4f1a\u770b\u5230\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u7684\u63d0\u793a\u7b26\uff0c\u8868\u793a\u5df2\u7ecf\u8fdb\u5165\u4e86IPython\u4ea4\u4e92\u754c\u9762\uff1a\n<pre><code class=\"language-python\">Python 3.8.5 (default, Jul 28 2020, 12:59:40)<\/p>\n<p>Type &#39;copyright&#39;, &#39;credits&#39; or &#39;license&#39; for more information<\/p>\n<p>IPython 7.16.1 -- An enhanced Interactive Python. Type &#39;?&#39; for help.<\/p>\n<p>In [1]:<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8f93\u5165Python\u4ee3\u7801<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u73b0\u5728\uff0c\u4f60\u53ef\u4ee5\u5728\u63d0\u793a\u7b26<code>In [1]:<\/code>\u540e\u8f93\u5165\u4efb\u610f\u6709\u6548\u7684Python\u4ee3\u7801\uff0c\u5e76\u6309\u56de\u8f66\u952e\u6267\u884c\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\u5e76\u6309\u56de\u8f66\u952e\uff1a\n<pre><code class=\"language-python\">In [1]: print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u8f93\u51fa\u5c06\u4f1a\u662f\uff1a\n<pre><code class=\"language-python\">Hello, World!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u5728IDE\u5185\u4f7f\u7528\u4ea4\u4e92\u7a97\u53e3<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9009\u62e9\u5408\u9002\u7684IDE<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u652f\u6301Python\u4ea4\u4e92\u7a97\u53e3\u7684IDE\uff0c\u4f8b\u5982PyCharm\u3001VSCode\u6216Spyder\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6253\u5f00\u4ea4\u4e92\u7a97\u53e3<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728IDE\u4e2d\u6253\u5f00\u4e00\u4e2a\u65b0\u7684\u4ea4\u4e92\u7a97\u53e3\uff0c\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u83dc\u5355\u9009\u9879\u6216\u5feb\u6377\u952e\u6253\u5f00\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u5728PyCharm\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u201cView\u201d -&gt; \u201cTool Windows\u201d -&gt; \u201cPython Console\u201d\u6253\u5f00Python\u4ea4\u4e92\u7a97\u53e3\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8f93\u5165\u5e76\u6267\u884c\u4ee3\u7801<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u4ea4\u4e92\u7a97\u53e3\u4e2d\u8f93\u5165\u4efb\u610f\u6709\u6548\u7684Python\u4ee3\u7801\uff0c\u5e76\u6309\u56de\u8f66\u952e\u6267\u884c\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a\n<pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u8f93\u51fa\u5c06\u4f1a\u663e\u793a\u5728\u4ea4\u4e92\u7a97\u53e3\u4e2d\uff1a\n<pre><code class=\"language-python\">Hello, World!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u8fdb\u5165Python\u4ea4\u4e92\u754c\u9762\u7684\u65b9\u5f0f\u591a\u79cd\u591a\u6837\uff0c\u4e3b\u8981\u5305\u62ec<strong>\u4f7f\u7528Python\u89e3\u91ca\u5668\u3001\u4f7f\u7528Jupyter Notebook\u3001\u4f7f\u7528IPython\u3001\u5728IDE\u5185\u4f7f\u7528\u4ea4\u4e92\u7a97\u53e3<\/strong>\u3002\u6839\u636e\u4e0d\u540c\u7684\u9700\u6c42\u548c\u4f7f\u7528\u4e60\u60ef\uff0c\u53ef\u4ee5\u9009\u62e9\u9002\u5408\u81ea\u5df1\u7684\u65b9\u6cd5\u6765\u8fdb\u5165Python\u4ea4\u4e92\u754c\u9762\uff0c\u5e76\u8fdb\u884c\u4ee3\u7801\u6d4b\u8bd5\u548c\u5f00\u53d1\u3002\u5bf9\u4e8e\u65b0\u624b\u6765\u8bf4\uff0c\u4f7f\u7528Python\u89e3\u91ca\u5668\u548cJupyter Notebook\u662f\u6bd4\u8f83\u5bb9\u6613\u4e0a\u624b\u7684\u65b9\u6cd5\uff0c\u800c\u5bf9\u4e8e\u9700\u8981\u66f4\u591a\u529f\u80fd\u7684\u7528\u6237\u6765\u8bf4\uff0cIPython\u548cIDE\u5185\u7684\u4ea4\u4e92\u7a97\u53e3\u5219\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u5de5\u5177\u548c\u652f\u6301\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u542f\u52a8Python\u4ea4\u4e92\u754c\u9762\uff1f<\/strong><br \/>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08CMD\uff09\u5e76\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\u6765\u542f\u52a8Python\u7684\u4ea4\u4e92\u754c\u9762\u3002\u5982\u679c\u4f60\u5728Mac\u6216Linux\u7cfb\u7edf\u4e0a\uff0c\u53ef\u4ee5\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165\u540c\u6837\u7684\u547d\u4ee4\u3002\u786e\u4fdd\u4f60\u7684Python\u5df2\u7ecf\u6b63\u786e\u5b89\u88c5\uff0c\u5e76\u4e14\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u65e0\u8bef\uff0c\u4ee5\u4fbf\u5728\u7ec8\u7aef\u4e2d\u76f4\u63a5\u8c03\u7528\u3002<\/p>\n<p><strong>Python\u4ea4\u4e92\u754c\u9762\u53ef\u4ee5\u505a\u54ea\u4e9b\u64cd\u4f5c\uff1f<\/strong><br \/>\u5728Python\u7684\u4ea4\u4e92\u754c\u9762\u4e2d\uff0c\u7528\u6237\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u5e76\u7acb\u5373\u83b7\u5f97\u8f93\u51fa\uff0c\u9002\u5408\u8fdb\u884c\u5feb\u901f\u6d4b\u8bd5\u548c\u5b9e\u9a8c\u3002\u4f60\u53ef\u4ee5\u6267\u884c\u7b80\u5355\u7684\u6570\u5b66\u8fd0\u7b97\u3001\u5b9a\u4e49\u51fd\u6570\u3001\u5bfc\u5165\u6a21\u5757\uff0c\u4ee5\u53ca\u6d4b\u8bd5\u4ee3\u7801\u7247\u6bb5\u7b49\u3002\u8fd9\u4e2a\u73af\u5883\u975e\u5e38\u9002\u5408\u5b66\u4e60\u548c\u8c03\u8bd5Python\u4ee3\u7801\u3002<\/p>\n<p><strong>\u5982\u4f55\u9000\u51faPython\u4ea4\u4e92\u754c\u9762\uff1f<\/strong><br \/>\u9000\u51faPython\u4ea4\u4e92\u754c\u9762\u7684\u65b9\u6cd5\u6709\u591a\u79cd\u3002\u4f60\u53ef\u4ee5\u8f93\u5165<code>exit()<\/code>\u6216<code>quit()<\/code>\u547d\u4ee4\u6765\u9000\u51fa\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5feb\u6377\u952e<code>Ctrl + Z<\/code>\uff08\u5728Windows\u4e0a\uff09\u6216<code>Ctrl + D<\/code>\uff08\u5728Mac\/Linux\u4e0a\uff09\u6765\u7ed3\u675f\u5f53\u524d\u4f1a\u8bdd\u3002\u786e\u4fdd\u5728\u9000\u51fa\u4e4b\u524d\u4fdd\u5b58\u597d\u4f60\u6240\u9700\u7684\u4ee3\u7801\u6216\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u8fdb\u5165\u4ea4\u4e92\u754c\u9762\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Python\u89e3\u91ca\u5668\u3001\u4f7f\u7528Jupyter Notebook\u3001\u4f7f\u7528IPyt [&hellip;]","protected":false},"author":3,"featured_media":1175437,"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\/1175431"}],"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=1175431"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1175431\/revisions"}],"predecessor-version":[{"id":1175440,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1175431\/revisions\/1175440"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1175437"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1175431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1175431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1175431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}