{"id":1155648,"date":"2025-01-13T18:06:18","date_gmt":"2025-01-13T10:06:18","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1155648.html"},"modified":"2025-01-13T18:06:21","modified_gmt":"2025-01-13T10:06:21","slug":"ubuntu%e7%bb%88%e7%ab%af%e5%a6%82%e4%bd%95%e6%89%93%e5%bc%80python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1155648.html","title":{"rendered":"Ubuntu\u7ec8\u7aef\u5982\u4f55\u6253\u5f00python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25194239\/2f2f3902-f076-41f6-b5d7-3d52943ca6d2.webp\" alt=\"Ubuntu\u7ec8\u7aef\u5982\u4f55\u6253\u5f00python\" \/><\/p>\n<p><p> <strong>\u8981\u5728Ubuntu\u7ec8\u7aef\u4e2d\u6253\u5f00Python\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a\u76f4\u63a5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python3<\/code>\u3001\u786e\u4fdd\u5df2\u5b89\u88c5Python3\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u3002<\/strong> <\/p>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<strong>\u76f4\u63a5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python3<\/code><\/strong> \u662f\u6700\u4e3a\u7b80\u5355\u548c\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u4f60\u53ea\u9700\u6253\u5f00\u7ec8\u7aef\uff0c\u7136\u540e\u8f93\u5165<code>python3<\/code>\u5e76\u6309\u4e0bEnter\u952e\uff0c\u5373\u53ef\u8fdb\u5165Python\u4ea4\u4e92\u5f0f\u73af\u5883\u3002\u5728\u8fd9\u4e2a\u73af\u5883\u4e2d\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u5e76\u7acb\u5373\u6267\u884c\uff0c\u975e\u5e38\u9002\u5408\u8c03\u8bd5\u548c\u6d4b\u8bd5\u4ee3\u7801\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e00\u3001\u76f4\u63a5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python3<\/code><\/p>\n<\/p>\n<p><p>\u5728Ubuntu\u4e2d\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0bPython 3.x\u7248\u672c\u662f\u9884\u5b89\u88c5\u7684\u3002\u4f60\u53ea\u9700\u8981\u6253\u5f00\u7ec8\u7aef\uff0c\u7136\u540e\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\u8fdb\u5165Python 3\u7684\u4ea4\u4e92\u5f0f\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8f93\u5165\u547d\u4ee4\u540e\uff0c\u4f60\u4f1a\u770b\u5230\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u7684\u63d0\u793a\u7b26\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">Python 3.x.x (default, xxxx-xx-xx, xx:xx:xx)<\/p>\n<p>[GCC x.x.x] 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>\u5728\u8fd9\u4e2a\u73af\u5883\u4e2d\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u5e76\u7acb\u5373\u6267\u884c\uff0c\u975e\u5e38\u9002\u5408\u5feb\u901f\u6d4b\u8bd5\u548c\u8c03\u8bd5\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u786e\u4fdd\u5df2\u5b89\u88c5Python3<\/p>\n<\/p>\n<p><p>\u867d\u7136Ubuntu\u901a\u5e38\u4f1a\u9884\u88c5Python\uff0c\u4f46\u6709\u65f6\u4f60\u53ef\u80fd\u9700\u8981\u624b\u52a8\u5b89\u88c5\u6216\u66f4\u65b0Python 3\u3002\u5982\u679c\u4f60\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python3<\/code>\u547d\u4ee4\u540e\uff0c\u7cfb\u7edf\u63d0\u793a\u201ccommand not found\u201d\uff0c\u5219\u8bf4\u660ePython 3\u672a\u5b89\u88c5\u6216\u73af\u5883\u53d8\u91cf\u672a\u914d\u7f6e\u597d\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Python 3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt update<\/p>\n<p>sudo apt install python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u518d\u6b21\u5c1d\u8bd5\u8f93\u5165<code>python3<\/code>\u547d\u4ee4\uff0c\u5e94\u8be5\u80fd\u6b63\u5e38\u8fdb\u5165Python\u4ea4\u4e92\u5f0f\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u907f\u514d\u5728\u5f00\u53d1\u4e0d\u540cPython\u9879\u76ee\u65f6\u4ea7\u751f\u4f9d\u8d56\u51b2\u7a81\uff0c\u5efa\u8bae\u4f7f\u7528\u865a\u62df\u73af\u5883\u3002\u5728Ubuntu\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>venv<\/code>\u6a21\u5757\u521b\u5efa\u548c\u7ba1\u7406\u865a\u62df\u73af\u5883\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5<code>python3-venv<\/code>\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt install python3-venv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>myenv<\/code>\u662f\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\u3002\u63a5\u4e0b\u6765\uff0c\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u540e\uff0c\u4f60\u4f1a\u770b\u5230\u7ec8\u7aef\u63d0\u793a\u7b26\u524d\u9762\u51fa\u73b0\u4e86\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">(myenv) user@hostname:~$<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u65f6\uff0c\u4f60\u53ef\u4ee5\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\u547d\u4ee4\u8fdb\u5165Python\u4ea4\u4e92\u5f0f\u73af\u5883\u3002\u8981\u9000\u51fa\u865a\u62df\u73af\u5883\uff0c\u53ea\u9700\u8f93\u5165<code>deactivate<\/code>\u547d\u4ee4\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u901a\u8fc7\u811a\u672c\u6587\u4ef6\u8fd0\u884cPython<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u76f4\u63a5\u5728\u7ec8\u7aef\u4e2d\u4ea4\u4e92\u5f0f\u5730\u8fd0\u884cPython\u4ee3\u7801\uff0c\u4f60\u8fd8\u53ef\u4ee5\u901a\u8fc7\u811a\u672c\u6587\u4ef6\u8fd0\u884cPython\u4ee3\u7801\u3002\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2aPython\u811a\u672c\u6587\u4ef6\uff0c\u4f8b\u5982<code>script.py<\/code>\uff0c\u5e76\u5728\u6587\u4ef6\u4e2d\u7f16\u5199\u4f60\u7684Python\u4ee3\u7801\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>\u4fdd\u5b58\u6587\u4ef6\u540e\uff0c\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7ec8\u7aef\u4f1a\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">Hello, world!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u9002\u5408\u8fd0\u884c\u8f83\u957f\u7684\u7a0b\u5e8f\u6216\u5c06\u4ee3\u7801\u4fdd\u5b58\u4e0b\u6765\u4ee5\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u4f7f\u7528Jupyter Notebook<\/p>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u79cd\u4ea4\u4e92\u5f0f\u7684\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>\u7b49\u9886\u57df\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Jupyter Notebook\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt install python3-pip<\/p>\n<p>pip3 install jupyter<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8Jupyter Notebook\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">jupyter notebook<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u6253\u5f00\u5e76\u52a0\u8f7dJupyter Notebook\u754c\u9762\uff0c\u4f60\u53ef\u4ee5\u5728\u5176\u4e2d\u521b\u5efa\u5e76\u8fd0\u884cPython\u4ee3\u7801\u5355\u5143\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u901a\u8fc7IDE\u8fd0\u884cPython<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u66f4\u559c\u6b22\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\uff0c\u53ef\u4ee5\u9009\u62e9\u5b89\u88c5\u548c\u4f7f\u7528PyCharm\u3001Visual Studio Code\u7b49IDE\u3002\u8fd9\u4e9b\u5de5\u5177\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u4ee3\u7801\u7f16\u8f91\u3001\u8c03\u8bd5\u548c\u8fd0\u884c\u529f\u80fd\uff0c\u9002\u5408\u5f00\u53d1\u5927\u578bPython\u9879\u76ee\u3002\u4ee5Visual Studio Code\u4e3a\u4f8b\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo snap install --classic code<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u542f\u52a8Visual Studio Code\uff0c\u5e76\u5b89\u88c5Python\u6269\u5c55\u3002\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u5728IDE\u4e2d\u521b\u5efa\u548c\u8fd0\u884cPython\u9879\u76ee\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Ubuntu\u7ec8\u7aef\u4e2d\u6253\u5f00\u548c\u8fd0\u884cPython\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u76f4\u63a5\u8f93\u5165<code>python3<\/code>\u547d\u4ee4\u3001\u786e\u4fdd\u5df2\u5b89\u88c5Python3\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u3001\u901a\u8fc7\u811a\u672c\u6587\u4ef6\u8fd0\u884cPython\u3001\u4f7f\u7528Jupyter Notebook\u3001\u901a\u8fc7IDE\u8fd0\u884cPython\u7b49\u3002\u6839\u636e\u4f60\u7684\u9700\u6c42\u548c\u4e60\u60ef\uff0c\u9009\u62e9\u6700\u9002\u5408\u4f60\u7684\u65b9\u5f0f\u6765\u8fd0\u884cPython\u4ee3\u7801\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Ubuntu\u7ec8\u7aef\u4e2d\u68c0\u67e5\u662f\u5426\u5df2\u5b89\u88c5Python\uff1f<\/strong><br \/>\u8981\u786e\u8ba4Python\u662f\u5426\u5df2\u5b89\u88c5\u5728\u60a8\u7684Ubuntu\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165\u547d\u4ee4<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u3002\u5982\u679c\u7cfb\u7edf\u8fd4\u56dePython\u7684\u7248\u672c\u53f7\uff0c\u8bf4\u660ePython\u5df2\u6210\u529f\u5b89\u88c5\u3002\u5982\u679c\u672a\u5b89\u88c5\uff0c\u60a8\u9700\u8981\u901a\u8fc7\u5305\u7ba1\u7406\u5de5\u5177\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Ubuntu\u7ec8\u7aef\u4e2d\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5982\u679c\u60a8\u7684\u7cfb\u7edf\u4e2d\u672a\u5b89\u88c5Python\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u8f7b\u677e\u5b89\u88c5\u3002\u4f7f\u7528\u547d\u4ee4<code>sudo apt update<\/code>\u66f4\u65b0\u5305\u5217\u8868\uff0c\u63a5\u7740\u8f93\u5165<code>sudo apt install python3<\/code>\u8fdb\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>python3 --version<\/code>\u6765\u9a8c\u8bc1\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<p><strong>\u5728Ubuntu\u7ec8\u7aef\u4e2d\u5982\u4f55\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u8981\u8fd0\u884c\u4e00\u4e2aPython\u811a\u672c\uff0c\u60a8\u9700\u8981\u5728\u7ec8\u7aef\u4e2d\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\u3002\u4f7f\u7528<code>cd \/path\/to\/your\/script<\/code>\u547d\u4ee4\u8fdb\u5165\u76ee\u6807\u76ee\u5f55\uff0c\u7136\u540e\u8f93\u5165<code>python3 script_name.py<\/code>\u6765\u8fd0\u884c\u60a8\u7684\u811a\u672c\u3002\u786e\u4fdd\u5c06<code>script_name.py<\/code>\u66ff\u6362\u4e3a\u60a8\u5b9e\u9645\u7684\u811a\u672c\u6587\u4ef6\u540d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Ubuntu\u7ec8\u7aef\u4e2d\u6253\u5f00Python\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a\u76f4\u63a5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165python3\u3001\u786e\u4fdd\u5df2\u5b89\u88c5Pyth [&hellip;]","protected":false},"author":3,"featured_media":1155659,"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\/1155648"}],"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=1155648"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1155648\/revisions"}],"predecessor-version":[{"id":1155661,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1155648\/revisions\/1155661"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1155659"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1155648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1155648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1155648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}