{"id":978659,"date":"2024-12-27T06:39:37","date_gmt":"2024-12-26T22:39:37","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/978659.html"},"modified":"2024-12-27T06:39:40","modified_gmt":"2024-12-26T22:39:40","slug":"ubuntu%e4%b8%8a%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8cpython","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/978659.html","title":{"rendered":"Ubuntu\u4e0a\u5982\u4f55\u8fd0\u884cPython"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24203537\/ea140b2d-cf6b-47a7-86b1-1d78e406c44e.webp\" alt=\"Ubuntu\u4e0a\u5982\u4f55\u8fd0\u884cPython\" \/><\/p>\n<p><p> \u5728Ubuntu\u4e0a\u8fd0\u884cPython\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec<strong>\u4f7f\u7528\u7ec8\u7aef\u3001\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u3001\u548c\u811a\u672c\u6587\u4ef6<\/strong>\u3002\u5176\u4e2d\uff0c\u7ec8\u7aef\u662f\u6700\u5e38\u7528\u4e14\u76f4\u63a5\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u662f\u6240\u6709Ubuntu\u7cfb\u7edf\u7684\u5185\u7f6e\u529f\u80fd\u3002\u901a\u8fc7\u7ec8\u7aef\u8fd0\u884cPython\uff0c\u4f60\u53ef\u4ee5\u5feb\u901f\u6267\u884c\u4ee3\u7801\u7247\u6bb5\u6216\u6d4b\u8bd5\u5c0f\u7a0b\u5e8f\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Ubuntu\u4e0a\u8fd0\u884cPython\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5Python<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5Ubuntu\u662f\u5426\u5df2\u5b89\u88c5Python<\/strong><\/p>\n<\/p>\n<p><p>\u5927\u591a\u6570\u73b0\u4ee3Ubuntu\u7248\u672c\u5df2\u7ecf\u9884\u88c5\u4e86Python\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u68c0\u67e5\u662f\u5426\u5df2\u7ecf\u5b89\u88c5\u4e86Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679cPython\u5df2\u5b89\u88c5\uff0c\u4f60\u5c06\u770b\u5230\u5b89\u88c5\u7684Python\u7248\u672c\u3002\u5982\u679c\u6ca1\u6709\u770b\u5230\u7248\u672c\u4fe1\u606f\uff0c\u5219\u9700\u8981\u5b89\u88c5Python\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u7cfb\u7edf\u4e2d\u6ca1\u6709\u5b89\u88c5Python\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\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>\u6b64\u5916\uff0c\u5efa\u8bae\u5b89\u88c5<code>pip<\/code>\uff0cPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u4ee5\u65b9\u4fbf\u5b89\u88c5\u548c\u7ba1\u7406Python\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt install python3-pip<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884cPython<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u76f4\u63a5\u8fd0\u884cPython\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668<\/strong><\/p>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u8f93\u5165<code>python3<\/code>\u6765\u542f\u52a8Python\u7684\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u3002\u5728\u8fd9\u91cc\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u5e76\u7acb\u5373\u6267\u884c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fdb\u5165Python\u89e3\u91ca\u5668\u540e\uff0c\u4f60\u53ef\u4ee5\u8f93\u5165\u4efb\u4f55Python\u547d\u4ee4\uff0c\u6bd4\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>\u8fd9\u5c06\u7acb\u5373\u8f93\u51fa<code>Hello, World!<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u6709\u4e00\u4e2aPython\u811a\u672c\u6587\u4ef6\uff08\u4f8b\u5982<code>script.py<\/code>\uff09\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u8fd0\u884c\u5b83\u3002\u5047\u8bbe\u4f60\u7684\u811a\u672c\u6587\u4ef6\u4f4d\u4e8e\u5f53\u524d\u76ee\u5f55\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u6267\u884c\u811a\u672c\u4e2d\u7684\u6240\u6709Python\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\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<p><p>PyCharm\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684Python IDE\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u5f00\u53d1\u5de5\u5177\u548c\u9ad8\u7ea7\u8c03\u8bd5\u529f\u80fd\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5728Ubuntu\u4e0a\u5b89\u88c5\u548c\u4f7f\u7528PyCharm\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u4e0b\u8f7dPyCharm\u7684Linux\u7248\u672c\uff0c\u5e76\u89e3\u538b\u7f29\u6587\u4ef6\u3002<\/li>\n<li>\u8fdb\u5165\u89e3\u538b\u7f29\u7684\u76ee\u5f55\uff0c\u8fd0\u884c<code>bin<\/code>\u6587\u4ef6\u5939\u4e2d\u7684<code>pycharm.sh<\/code>\u811a\u672c\u542f\u52a8PyCharm\u3002<\/li>\n<li>\u5728PyCharm\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee\u6216\u6253\u5f00\u4e00\u4e2a\u73b0\u6709\u9879\u76ee\u3002<\/li>\n<li>\u4f60\u53ef\u4ee5\u5728PyCharm\u7684\u7f16\u8f91\u5668\u4e2d\u7f16\u5199Python\u4ee3\u7801\uff0c\u5e76\u901a\u8fc7\u70b9\u51fb\u201c\u8fd0\u884c\u201d\u6309\u94ae\u6765\u6267\u884c\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Visual Studio Code<\/strong><\/p>\n<\/p>\n<p><p>Visual Studio Code\uff08VS Code\uff09\u662f\u53e6\u4e00\u4e2a\u6d41\u884c\u7684\u4ee3\u7801\u7f16\u8f91\u5668\uff0c\u652f\u6301Python\u6269\u5c55\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5728Ubuntu\u4e0a\u5b89\u88c5\u548c\u4f7f\u7528VS Code\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u901a\u8fc7Ubuntu\u8f6f\u4ef6\u4e2d\u5fc3\u6216\u4ece\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5VS Code\u3002<\/li>\n<li>\u542f\u52a8VS Code\u5e76\u5b89\u88c5Python\u6269\u5c55\u3002<\/li>\n<li>\u6253\u5f00\u6216\u521b\u5efa\u4e00\u4e2aPython\u6587\u4ef6\uff0c\u8f93\u5165\u4ee3\u7801\u5e76\u6309<code>F5<\/code>\u8fd0\u884c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528Jupyter Notebook<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Jupyter Notebook<\/strong><\/p>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u79cd\u4ea4\u4e92\u5f0fPython\u73af\u5883\uff0c\u7279\u522b\u9002\u5408\u6570\u636e\u79d1\u5b66\u548c\u5206\u6790\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Jupyter Notebook\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip3 install jupyter<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cJupyter Notebook<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\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>\u8fd9\u5c06\u542f\u52a8\u4e00\u4e2aWeb\u670d\u52a1\u5668\uff0c\u5e76\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00Jupyter Notebook\u754c\u9762\u3002\u4f60\u53ef\u4ee5\u5728\u8fd9\u91cc\u521b\u5efa\u548c\u8fd0\u884cPython\u7b14\u8bb0\u672c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001Python\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5e93\u7248\u672c\u51b2\u7a81\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2aPython\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>\u4e0a\u8ff0\u547d\u4ee4\u5c06\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>myenv<\/code>\u7684\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\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\u7ec8\u7aef\u63d0\u793a\u7b26\u4f1a\u51fa\u73b0\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\uff0c\u8868\u793a\u4f60\u5df2\u7ecf\u8fdb\u5165\u4e86\u8be5\u865a\u62df\u73af\u5883\u3002\u6b64\u65f6\u5b89\u88c5\u7684Python\u5e93\u5c06\u4ec5\u5bf9\u8be5\u865a\u62df\u73af\u5883\u6709\u6548\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u9000\u51fa\u865a\u62df\u73af\u5883\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u603b\u7ed3\uff0cUbuntu\u4e0a\u8fd0\u884cPython\u7684\u65b9\u6cd5\u591a\u79cd\u591a\u6837\uff0c\u5305\u62ec\u76f4\u63a5\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u3001\u4f7f\u7528IDE\u3001Jupyter Notebook\u3001\u4ee5\u53ca\u865a\u62df\u73af\u5883\u7b49\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u4f18\u70b9\uff0c\u9009\u62e9\u9002\u5408\u81ea\u5df1\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002\u5728\u4f7f\u7528\u8fc7\u7a0b\u4e2d\uff0c\u786e\u4fdd\u4f7f\u7528Python 3\uff0c\u5e76\u5229\u7528<code>pip<\/code>\u6765\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u5c06\u6709\u52a9\u4e8e\u786e\u4fdd\u4ee3\u7801\u7684\u53ef\u79fb\u690d\u6027\u548c\u7a33\u5b9a\u6027\u3002\u901a\u8fc7\u8fd9\u4e9b\u5de5\u5177\u548c\u6280\u5de7\uff0c\u4f60\u53ef\u4ee5\u5728Ubuntu\u4e0a\u8f7b\u677e\u5730\u8fd0\u884c\u548c\u7ba1\u7406Python\u9879\u76ee\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Ubuntu\u4e0a\u5b89\u88c5Python\u7684\u6b65\u9aa4\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5728Ubuntu\u7cfb\u7edf\u4e2d\uff0cPython\u901a\u5e38\u9884\u88c5\u5728\u5927\u591a\u6570\u7248\u672c\u4e2d\u3002\u8981\u68c0\u67e5\u7cfb\u7edf\u4e2d\u662f\u5426\u5df2\u5b89\u88c5Python\uff0c\u53ef\u4ee5\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165<code>python3 --version<\/code>\u3002\u5982\u679c\u672a\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>sudo apt update<\/code>\u548c<code>sudo apt install python3<\/code>\u6765\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Python\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Ubuntu\u4e2d\u521b\u5efa\u548c\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u521b\u5efaPython\u811a\u672c\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u6587\u672c\u7f16\u8f91\u5668\uff0c\u4f8b\u5982Nano\u6216Vim\u3002\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165<code>nano my_script.py<\/code>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u6587\u4ef6\u3002\u5728\u6587\u4ef6\u4e2d\u7f16\u5199Python\u4ee3\u7801\u540e\uff0c\u4fdd\u5b58\u5e76\u9000\u51fa\u3002\u8981\u8fd0\u884c\u811a\u672c\uff0c\u8f93\u5165<code>python3 my_script.py<\/code>\u5373\u53ef\u6267\u884c\u3002<\/p>\n<p><strong>\u5728Ubuntu\u4e0a\u5982\u4f55\u7ba1\u7406Python\u5305\uff1f<\/strong><br \/>\u5728Ubuntu\u4e0a\uff0c\u4f7f\u7528<code>pip<\/code>\u5de5\u5177\u53ef\u4ee5\u8f7b\u677e\u7ba1\u7406Python\u5305\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86<code>pip<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>sudo apt install python3-pip<\/code>\u6765\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip install package_name<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684Python\u5305\uff0c\u4f7f\u7528<code>pip list<\/code>\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5305\uff0c\u4ee5\u53ca\u4f7f\u7528<code>pip uninstall package_name<\/code>\u5378\u8f7d\u4e0d\u518d\u9700\u8981\u7684\u5305\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Ubuntu\u4e0a\u8fd0\u884cPython\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u7ec8\u7aef\u3001\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u3001\u548c\u811a\u672c\u6587\u4ef6 [&hellip;]","protected":false},"author":3,"featured_media":978666,"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\/978659"}],"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=978659"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/978659\/revisions"}],"predecessor-version":[{"id":978668,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/978659\/revisions\/978668"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/978666"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=978659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=978659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=978659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}