{"id":977141,"date":"2024-12-27T06:27:09","date_gmt":"2024-12-26T22:27:09","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/977141.html"},"modified":"2024-12-27T06:27:11","modified_gmt":"2024-12-26T22:27:11","slug":"ubuntu%e5%a6%82%e4%bd%95%e7%9c%8bpython%e7%89%88%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/977141.html","title":{"rendered":"ubuntu\u5982\u4f55\u770bpython\u7248\u672c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24202529\/8f35c916-8be1-48c7-913c-ee34de437fb2.webp\" alt=\"ubuntu\u5982\u4f55\u770bpython\u7248\u672c\" \/><\/p>\n<p><p> <strong>\u5728Ubuntu\u7cfb\u7edf\u4e0a\u67e5\u770bPython\u7248\u672c\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u67e5\u770b\u3001\u68c0\u67e5Python\u5b89\u88c5\u76ee\u5f55\u3001\u67e5\u770bPython\u865a\u62df\u73af\u5883\u4e2d\u7684\u7248\u672c\u3002\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u6765\u67e5\u770b\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\u3002<\/strong> \u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\u6765\u83b7\u53d6Python\u7248\u672c\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u67e5\u770bPython\u7248\u672c<\/p>\n<\/p>\n<p><p>\u5728Ubuntu\u4e0a\uff0c\u547d\u4ee4\u884c\u662f\u975e\u5e38\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u51e0\u4e4e\u6240\u6709\u7684\u7cfb\u7edf\u64cd\u4f5c\u90fd\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u5b8c\u6210\u3002\u67e5\u770bPython\u7248\u672c\u4e5f\u4e0d\u4f8b\u5916\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528<code>python --version<\/code>\u547d\u4ee4<\/strong><\/p>\n<\/p>\n<p><p>\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -V<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u7cfb\u7edf\u4e2d\u5b89\u88c5\u4e86Python 2.x\u7248\u672c\uff0c\u8fd9\u6761\u547d\u4ee4\u5c06\u8f93\u51fa\u7c7b\u4f3c\u4e8e<code>Python 2.7.18<\/code>\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528<code>python3 --version<\/code>\u547d\u4ee4<\/strong><\/p>\n<\/p>\n<p><p>\u5927\u591a\u6570\u73b0\u4ee3Ubuntu\u7cfb\u7edf\u90fd\u9884\u88c5\u4e86Python 3.x\u7248\u672c\u3002\u8981\u67e5\u770b\u5177\u4f53\u7684Python 3\u7248\u672c\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 -V<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u7c7b\u4f3c\u4e8e<code>Python 3.8.10<\/code>\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528<code>which python<\/code>\u548c<code>which python3<\/code><\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u60f3\u77e5\u9053Python\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u53ef\u4ee5\u4f7f\u7528<code>which<\/code>\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">which python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">which python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51faPython\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff0c\u6bd4\u5982<code>\/usr\/bin\/python3<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u68c0\u67e5Python\u5b89\u88c5\u76ee\u5f55<\/p>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u68c0\u67e5Python\u7684\u5b89\u88c5\u76ee\u5f55\u4ee5\u83b7\u53d6\u66f4\u591a\u7684\u7248\u672c\u4fe1\u606f\u6216\u8c03\u8bd5\u95ee\u9898\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770bPython\u5b89\u88c5\u8def\u5f84<\/strong><\/p>\n<\/p>\n<p><p>\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u67e5\u770bPython\u7684\u5b89\u88c5\u8def\u5f84\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">whereis python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">whereis python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5217\u51faPython\u76f8\u5173\u7684\u6587\u4ef6\u548c\u76ee\u5f55\uff0c\u4f8b\u5982<code>\/usr\/bin\/python3.8<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770bPython\u5e93\u7684\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u8981\u67e5\u770b\u5b89\u88c5\u7684Python\u5e93\u7684\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u5de5\u5177\u3002\u9996\u5148\uff0c\u786e\u4fddpip\u5df2\u7ecf\u5b89\u88c5\uff0c\u7136\u540e\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\u5bf9\u4e8ePython 3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip3 list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5217\u51fa\u6240\u6709\u5b89\u88c5\u7684Python\u5305\u53ca\u5176\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u67e5\u770bPython\u865a\u62df\u73af\u5883\u4e2d\u7684\u7248\u672c<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1Python\u5e94\u7528\u65f6\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u6765\u9694\u79bb\u9879\u76ee\u4f9d\u8d56\u662f\u4e2a\u597d\u4e60\u60ef\u3002\u6bcf\u4e2a\u865a\u62df\u73af\u5883\u53ef\u80fd\u6709\u4e0d\u540c\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u548c\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5b89\u88c5<code>virtualenv<\/code>\u5de5\u5177\uff08\u5982\u679c\u8fd8\u6ca1\u6709\u5b89\u88c5\uff09\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>\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<\/li>\n<li>\n<p><strong>\u68c0\u67e5\u865a\u62df\u73af\u5883\u4e2d\u7684Python\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u67e5\u770bPython\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u663e\u793a\u865a\u62df\u73af\u5883\u4e2d\u4f7f\u7528\u7684Python\u7248\u672c\uff0c\u901a\u5e38\u4e0e\u7cfb\u7edfPython\u7248\u672c\u4e00\u81f4\uff0c\u9664\u975e\u7279\u522b\u6307\u5b9a\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528Python\u811a\u672c\u67e5\u770b\u7248\u672c<\/p>\n<\/p>\n<p><p>\u6709\u65f6\u4f60\u53ef\u80fd\u9700\u8981\u5728Python\u811a\u672c\u4e2d\u83b7\u53d6Python\u7248\u672c\u4fe1\u606f\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7<code>sys<\/code>\u6a21\u5757\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u5199Python\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2aPython\u811a\u672c\u6587\u4ef6\uff0c\u6bd4\u5982<code>check_version.py<\/code>\uff0c\u5e76\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>print(&quot;Python version&quot;)<\/p>\n<p>print(sys.version)<\/p>\n<p>print(&quot;Version info.&quot;)<\/p>\n<p>print(sys.version_info)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u8fd9\u4e2a\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python check_version.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\u5bf9\u4e8ePython 3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 check_version.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u89e3\u6790\u8f93\u51fa\u4fe1\u606f<\/strong><\/p>\n<\/p>\n<p><p>\u8fd9\u4e2a\u811a\u672c\u5c06\u8f93\u51fa\u8be6\u7ec6\u7684Python\u7248\u672c\u4fe1\u606f\uff0c\u5305\u62ec\u4e3b\u7248\u672c\u53f7\u3001\u6b21\u7248\u672c\u53f7\u548c\u5fae\u7248\u672c\u53f7\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u4e86\u89e3\u5982\u4f55\u5728Ubuntu\u4e0a\u67e5\u770bPython\u7248\u672c\u662f\u6bcf\u4e2aPython\u5f00\u53d1\u8005\u7684\u57fa\u672c\u6280\u80fd\u3002\u901a\u8fc7\u547d\u4ee4\u884c\u3001\u68c0\u67e5\u5b89\u88c5\u76ee\u5f55\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u4ee5\u53ca\u7f16\u5199Python\u811a\u672c\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u5230Python\u7684\u7248\u672c\u4fe1\u606f\u3002\u8fd9\u4e9b\u65b9\u6cd5\u4e0d\u4ec5\u9002\u7528\u4e8eUbuntu\uff0c\u4e5f\u53ef\u4ee5\u5728\u5176\u4ed6Linux\u53d1\u884c\u7248\u4e2d\u4f7f\u7528\uff0c\u4e3a\u4f60\u7684\u5f00\u53d1\u5de5\u4f5c\u63d0\u4f9b\u4fbf\u5229\u3002\u65e0\u8bba\u662f\u5728\u8c03\u8bd5\u95ee\u9898\u8fd8\u662f\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\uff0c\u77e5\u9053\u4f60\u6240\u4f7f\u7528\u7684Python\u7248\u672c\u90fd\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Ubuntu\u7cfb\u7edf\u4e2d\u67e5\u770bPython\u7684\u5177\u4f53\u7248\u672c\u53f7\uff1f<\/strong><br \/>\u5728Ubuntu\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u547d\u4ee4\u6765\u67e5\u770bPython\u7684\u7248\u672c\u3002\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u3002\u8fd9\u4e24\u4e2a\u547d\u4ee4\u5206\u522b\u4f1a\u663e\u793aPython 2\u548cPython 3\u7684\u7248\u672c\u4fe1\u606f\uff0c\u901a\u5e38Ubuntu\u9ed8\u8ba4\u5b89\u88c5\u7684\u662fPython 3\u3002<\/p>\n<p><strong>\u5982\u679c\u6211\u5b89\u88c5\u4e86\u591a\u4e2aPython\u7248\u672c\uff0c\u5982\u4f55\u67e5\u770b\u6240\u6709\u5df2\u5b89\u88c5\u7684\u7248\u672c\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>ls \/usr\/bin\/python*<\/code>\u547d\u4ee4\u6765\u5217\u51fa\u6240\u6709\u5df2\u5b89\u88c5\u7684Python\u7248\u672c\u3002\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u663e\u793a\u6240\u6709\u4ee5\u201cpython\u201d\u5f00\u5934\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5305\u62ec\u4e0d\u540c\u7248\u672c\u7684Python\u3002\u901a\u8fc7\u8fd9\u4e9b\u8f93\u51fa\uff0c\u4f60\u53ef\u4ee5\u770b\u5230\u7cfb\u7edf\u4e2d\u6240\u6709\u53ef\u7528\u7684Python\u7248\u672c\u3002<\/p>\n<p><strong>\u5728Ubuntu\u4e2d\uff0c\u5982\u4f55\u786e\u8ba4\u6211\u6b63\u5728\u4f7f\u7528\u7684Python\u7248\u672c\uff1f<\/strong><br \/>\u8981\u786e\u8ba4\u5f53\u524d\u4f7f\u7528\u7684Python\u7248\u672c\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>which python<\/code>\u6216<code>which python3<\/code>\u547d\u4ee4\u3002\u8fd9\u5c06\u663e\u793a\u6b63\u5728\u4f7f\u7528\u7684Python\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff0c\u63a5\u7740\u53ef\u4ee5\u4f7f\u7528\u524d\u9762\u63d0\u5230\u7684\u7248\u672c\u547d\u4ee4\u6765\u83b7\u53d6\u5177\u4f53\u7248\u672c\u4fe1\u606f\u3002\u8fd9\u6837\u4f60\u53ef\u4ee5\u786e\u4fdd\u4f60\u4f7f\u7528\u7684\u662f\u6b63\u786e\u7684Python\u7248\u672c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Ubuntu\u7cfb\u7edf\u4e0a\u67e5\u770bPython\u7248\u672c\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u67e5\u770b\u3001\u68c0\u67e5Python\u5b89\u88c5\u76ee\u5f55\u3001\u67e5\u770bPython [&hellip;]","protected":false},"author":3,"featured_media":977152,"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\/977141"}],"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=977141"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/977141\/revisions"}],"predecessor-version":[{"id":977153,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/977141\/revisions\/977153"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/977152"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=977141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=977141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=977141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}