{"id":52241,"date":"2024-10-09T00:59:12","date_gmt":"2024-10-08T16:59:12","guid":{"rendered":"https:\/\/server.hk\/cnblog\/52241\/"},"modified":"2024-11-14T10:39:46","modified_gmt":"2024-11-14T02:39:46","slug":"ubuntu-%e4%b8%8b-ipython-%e7%9a%84%e6%90%ad%e5%bb%ba%e5%92%8c%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/52241\/","title":{"rendered":"Ubuntu \u4e0b IPython \u7684\u642d\u5efa\u548c\u4f7f\u7528"},"content":{"rendered":"<h1 id=\"ubuntu-%e4%b8%8b-ipython-%e7%9a%84%e6%90%ad%e5%bb%ba%e5%92%8c%e4%bd%bf%e7%94%a8-HyRDRVjtJk\">Ubuntu \u4e0b IPython \u7684\u642d\u5efa\u548c\u4f7f\u7528<\/h1>\n<p>\u5728\u6578\u64da\u79d1\u5b78\u548c\u6a5f\u5668\u5b78\u7fd2\u7684\u9818\u57df\u4e2d\uff0cIPython \u662f\u4e00\u500b\u975e\u5e38\u53d7\u6b61\u8fce\u7684\u4ea4\u4e92\u5f0f\u8a08\u7b97\u74b0\u5883\u3002\u5b83\u4e0d\u50c5\u63d0\u4f9b\u4e86\u5f37\u5927\u7684 Python \u7de8\u7a0b\u529f\u80fd\uff0c\u9084\u652f\u6301\u591a\u7a2e\u6578\u64da\u53ef\u8996\u5316\u548c\u6578\u64da\u5206\u6790\u5de5\u5177\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Ubuntu \u7cfb\u7d71\u4e0a\u642d\u5efa\u548c\u4f7f\u7528 IPython\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-ipython-HyRDRVjtJk\">\u5b89\u88dd IPython<\/h2>\n<p>\u5728 Ubuntu \u4e0a\u5b89\u88dd IPython \u975e\u5e38\u7c21\u55ae\uff0c\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install python3-pip\npip3 install ipython\n<\/code><\/pre>\n<p>\u4e0a\u8ff0\u547d\u4ee4\u9996\u5148\u66f4\u65b0\u4e86\u60a8\u7684\u5305\u7ba1\u7406\u5668\uff0c\u7136\u5f8c\u5b89\u88dd\u4e86 Python 3 \u7684 pip \u5de5\u5177\uff0c\u6700\u5f8c\u4f7f\u7528 pip \u5b89\u88dd\u4e86 IPython\u3002<\/p>\n<h2 id=\"%e5%95%9f%e5%8b%95-ipython-HyRDRVjtJk\">\u555f\u52d5 IPython<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u901a\u904e\u5728\u7d42\u7aef\u4e2d\u8f38\u5165\u4ee5\u4e0b\u547d\u4ee4\u4f86\u555f\u52d5 IPython\uff1a<\/p>\n<pre><code>ipython\n<\/code><\/pre>\n<p>\u555f\u52d5\u5f8c\uff0c\u60a8\u5c07\u770b\u5230\u4e00\u500b\u4ea4\u4e92\u5f0f\u7684\u547d\u4ee4\u884c\u754c\u9762\uff0c\u60a8\u53ef\u4ee5\u5728\u9019\u88e1\u8f38\u5165 Python \u4ee3\u78bc\u4e26\u7acb\u5373\u57f7\u884c\u3002<\/p>\n<h2 id=\"%e5%9f%ba%e6%9c%ac%e7%94%a8%e6%b3%95-HyRDRVjtJk\">\u57fa\u672c\u7528\u6cd5<\/h2>\n<p>\u5728 IPython \u4e2d\uff0c\u60a8\u53ef\u4ee5\u57f7\u884c\u5404\u7a2e Python \u4ee3\u78bc\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684\u7528\u6cd5\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"%e8%ae%8a%e9%87%8f%e5%92%8c%e6%95%b8%e5%ad%b8%e9%81%8b%e7%ae%97-HyRDRVjtJk\">\u8b8a\u91cf\u548c\u6578\u5b78\u904b\u7b97<\/h3>\n<pre><code>x = 10\ny = 5\nz = x + y\nprint(z)  # \u8f38\u51fa 15\n<\/code><\/pre>\n<h3 id=\"%e4%bd%bf%e7%94%a8%e5%ba%ab-HyRDRVjtJk\">\u4f7f\u7528\u5eab<\/h3>\n<p>\u60a8\u53ef\u4ee5\u5728 IPython \u4e2d\u8f15\u9b06\u5c0e\u5165\u548c\u4f7f\u7528\u5404\u7a2e Python \u5eab\u3002\u4f8b\u5982\uff0c\u4f7f\u7528 NumPy \u9032\u884c\u6578\u64da\u8655\u7406\uff1a<\/p>\n<pre><code>import numpy as np\na = np.array([1, 2, 3])\nprint(a * 2)  # \u8f38\u51fa [2 4 6]\n<\/code><\/pre>\n<h3 id=\"%e6%95%b8%e6%93%9a%e5%8f%af%e8%a6%96%e5%8c%96-HyRDRVjtJk\">\u6578\u64da\u53ef\u8996\u5316<\/h3>\n<p>IPython \u9084\u652f\u6301\u6578\u64da\u53ef\u8996\u5316\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 Matplotlib \u5eab\u4f86\u5275\u5efa\u5716\u8868\uff1a<\/p>\n<pre><code>import matplotlib.pyplot as plt\n\nx = [1, 2, 3, 4]\ny = [10, 20, 25, 30]\n\nplt.plot(x, y)\nplt.title('\u7c21\u55ae\u5716\u8868')\nplt.xlabel('X \u8ef8')\nplt.ylabel('Y \u8ef8')\nplt.show()\n<\/code><\/pre>\n<h2 id=\"%e4%bd%bf%e7%94%a8-jupyter-notebook-HyRDRVjtJk\">\u4f7f\u7528 Jupyter Notebook<\/h2>\n<p>\u9664\u4e86\u5728\u7d42\u7aef\u4e2d\u4f7f\u7528 IPython\uff0c\u60a8\u9084\u53ef\u4ee5\u4f7f\u7528 Jupyter Notebook \u4f86\u5275\u5efa\u66f4\u70ba\u8c50\u5bcc\u7684\u4ea4\u4e92\u5f0f\u6587\u6a94\u3002\u5b89\u88dd Jupyter Notebook \u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre><code>pip3 install notebook\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 Jupyter Notebook\uff1a<\/p>\n<pre><code>jupyter notebook\n<\/code><\/pre>\n<p>\u9019\u5c07\u5728\u60a8\u7684\u700f\u89bd\u5668\u4e2d\u6253\u958b\u4e00\u500b\u65b0\u7684\u9801\u9762\uff0c\u60a8\u53ef\u4ee5\u5728\u9019\u88e1\u5275\u5efa\u548c\u7de8\u8f2f Notebook\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-HyRDRVjtJk\">\u7e3d\u7d50<\/h2>\n<p>\u5728 Ubuntu \u4e0a\u642d\u5efa\u548c\u4f7f\u7528 IPython \u662f\u4e00\u500b\u7c21\u55ae\u800c\u6709\u6548\u7684\u904e\u7a0b\uff0c\u7121\u8ad6\u662f\u9032\u884c\u6578\u64da\u5206\u6790\u9084\u662f\u5b78\u7fd2 Python \u7de8\u7a0b\uff0cIPython \u90fd\u80fd\u63d0\u4f9b\u5f37\u5927\u7684\u652f\u6301\u3002\u901a\u904e\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u5730\u5b89\u88dd\u548c\u4f7f\u7528 IPython\uff0c\u4e26\u5229\u7528\u5176\u5f37\u5927\u7684\u529f\u80fd\u4f86\u63d0\u5347\u60a8\u7684\u5de5\u4f5c\u6548\u7387\u3002\u5982\u679c\u60a8\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u4f86\u904b\u884c\u60a8\u7684 Python \u61c9\u7528\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b66\u4e60\u5982\u4f55\u5728 Ubuntu \u4e0a\u642d\u5efa\u548c\u4f7f\u7528 IPython\uff0c\u63d0\u5347\u4f60\u7684 Python \u7f16\u7a0b\u4f53\u9a8c\uff0c\u638c\u63e1\u4ea4\u4e92\u5f0f\u8ba1\u7b97\u7684\u5f3a\u5927\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-52241","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=52241"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52241\/revisions"}],"predecessor-version":[{"id":52242,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52241\/revisions\/52242"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=52241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=52241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=52241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}