{"id":510,"date":"2021-04-29T21:26:24","date_gmt":"2021-04-29T13:26:24","guid":{"rendered":"https:\/\/www.wangliguang.cn\/?p=510"},"modified":"2021-04-29T21:26:24","modified_gmt":"2021-04-29T13:26:24","slug":"ubuntu%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9%e9%bb%98%e8%ae%a4python%e7%89%88%e6%9c%ac-sudo%e5%92%8c%e4%b8%8d%e7%94%a8sudopython%e4%b8%8d%e4%b8%80%e8%87%b4%e6%80%8e%e4%b9%88%e5%8a%9e","status":"publish","type":"post","link":"https:\/\/wangliguang.cn\/?p=510","title":{"rendered":"Ubuntu\u5982\u4f55\u4fee\u6539\u9ed8\u8ba4python\u7248\u672c-sudo\u548c\u4e0d\u7528sudopython\u4e0d\u4e00\u81f4\u600e\u4e48\u529e"},"content":{"rendered":"<h2>\u80cc\u666f<\/h2>\n<p>sudo\u4e0bpython\u9ed8\u8ba4\u662fpython2.7\uff0c\u800c\u5728\u81ea\u5df1\u7684\u7528\u6237\u4e0bpython\u9ed8\u8ba4\u662f3.6\uff0c\u5982\u4f55\u5c06sudo\u4e0bpython\u4e5f\u53d8\u6210python3.6\u5462\uff1f<\/p>\n<h2>\u89e3\u51b3\u65b9\u6cd5-\u57fa\u4e8eupdate-alternatives<\/h2>\n<p>\u6ce8\uff1a\u4ee5\u4e0b\u5185\u5bb9\u8f6c\u8f7d\u81eahttps:\/\/blog.csdn.net\/White_Idiot\/article\/details\/78240298<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528update-alternatives\u6765\u4e3a\u6574\u4e2a\u7cfb\u7edf\u66f4\u6539Python\u7248\u672c\u3002<\/p>\n<p>\u7b2c1\u6b65\u9996\u5148\u5217\u51fa\u6240\u6709\u53ef\u7528\u7684python\u66ff\u4ee3\u7248\u672c\u4fe1\u606f\uff1a<\/p>\n<pre><code>$ update-alternatives --list python\nupdate-alternatives: \u9519\u8bef: \u65e0 python \u7684\u5019\u9009\u9879<\/code><\/pre>\n<p>\u5982\u679c\u51fa\u73b0\u4ee5\u4e0a\u6240\u793a\u7684\u9519\u8bef\u4fe1\u606f\uff0c\u8868\u793aupdate-alternatives\u6ca1\u6709\u6dfb\u52a0Python\u7684\u66ff\u4ee3\u7248\u672c\u3002<\/p>\n<p>\u7b2c2\u6b65\u5c06Python\u7684\u66ff\u4ee3\u7248\u672c\u6dfb\u52a0\u8fdb\u53bb\uff1a<\/p>\n<pre><code>$ sudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python2.7 1\nupdate-alternatives: \u4f7f\u7528 \/usr\/bin\/python2.7 \u6765\u5728\u81ea\u52a8\u6a21\u5f0f\u4e2d\u63d0\u4f9b \/usr\/bin\/python (python)\n$ sudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python3.5 2\nupdate-alternatives: \u4f7f\u7528 \/usr\/bin\/python3.5 \u6765\u5728\u81ea\u52a8\u6a21\u5f0f\u4e2d\u63d0\u4f9b \/usr\/bin\/python (python)<\/code><\/pre>\n<p>install\u9009\u9879\u4f7f\u7528\u4e86\u591a\u4e2a\u53c2\u6570\u7528\u4e8e\u521b\u5efa\u7b26\u53f7\u94fe\u63a5\u3002\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u6307\u5b9a\u4e86\u6b64\u9009\u9879\u7684\u4f18\u5148\u7ea7\uff0c\u5982\u679c\u6211\u4eec\u6ca1\u6709\u624b\u52a8\u6765\u8bbe\u7f6e\u66ff\u4ee3\u9009\u9879\uff0c\u90a3\u4e48\u5177\u6709\u6700\u9ad8\u4f18\u5148\u7ea7\u7684\u9009\u9879\u5c31\u4f1a\u88ab\u9009\u4e2d\u3002<\/p>\n<p>\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4e3a\/usr\/bin\/python3.5\u8bbe\u7f6e\u7684\u4f18\u5148\u7ea7\u4e3a2\uff0c\u6240\u4ee5update-alternatives\u547d\u4ee4\u4f1a\u81ea\u52a8\u5c06\u5b83\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4Python\u7248\u672c\uff1a<\/p>\n<pre><code>$ python --version\nPython 3.5.2<\/code><\/pre>\n<p>\u518d\u5217\u51fa\u53ef\u7528\u7684Python\u66ff\u4ee3\u7248\u672c\uff1a<\/p>\n<pre><code>$ update-alternatives --list python\n\/usr\/bin\/python2.7\n\/usr\/bin\/python3.5<\/code><\/pre>\n<p>\u73b0\u5728\u5c31\u53ef\u4ee5\u5728\u5217\u51fa\u7684Python\u66ff\u4ee3\u7248\u672c\u4e2d\u4efb\u610f\u5207\u6362\uff1a<\/p>\n<pre><code>$ update-alternatives --config python<\/code><\/pre>\n<p>\u6709 2 \u4e2a\u5019\u9009\u9879\u53ef\u7528\u4e8e\u66ff\u6362 python (\u63d0\u4f9b \/usr\/bin\/python)\u3002<\/p>\n<pre><code>  \u9009\u62e9       \u8def\u5f84              \u4f18\u5148\u7ea7  \u72b6\u6001\n------------------------------------------------------------\n* 0            \/usr\/bin\/python3.5   2         \u81ea\u52a8\u6a21\u5f0f\n  1            \/usr\/bin\/python2.7   1         \u624b\u52a8\u6a21\u5f0f\n  2            \/usr\/bin\/python3.5   2         \u624b\u52a8\u6a21\u5f0f\n\u8981\u7ef4\u6301\u5f53\u524d\u503c[*]\u8bf7\u6309&lt;\u56de\u8f66\u952e&gt;\uff0c\u6216\u8005\u952e\u5165\u9009\u62e9\u7684\u7f16\u53f7\uff1a1<\/code><\/pre>\n<p>\u7136\u540e\u67e5\u770b\u7248\u672c\u53f7\uff1a<\/p>\n<pre><code>$ python --version<\/code><\/pre>\n<p>Python 2.7.12<br \/>\n\u7b2c3\u6b65\u5f53\u7cfb\u7edf\u4e0d\u518d\u5b58\u5728\u67d0\u4e2aPython\u66ff\u4ee3\u7248\u672c\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u4eceupdate-alternatives\u5217\u8868\u4e2d\u5220\u9664\u6389\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u53ef\u4ee5\u5c06\u5217\u8868\u4e2d\u7684python2.7\u7248\u672c\u79fb\u9664\uff1a<\/p>\n<pre><code>$ sudo update-alternatives --remove python \/usr\/bin\/python2.7\n$ update-alternatives --list python\n\/usr\/bin\/python3.5<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f sudo\u4e0bpython\u9ed8\u8ba4\u662fpython2.7\uff0c\u800c\u5728\u81ea\u5df1\u7684\u7528\u6237\u4e0bpython\u9ed8\u8ba4\u662f3.6\uff0c\u5982\u4f55\u5c06sudo&hellip; <a href=\"https:\/\/wangliguang.cn\/?p=510\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">Ubuntu\u5982\u4f55\u4fee\u6539\u9ed8\u8ba4python\u7248\u672c-sudo\u548c\u4e0d\u7528sudopython\u4e0d\u4e00\u81f4\u600e\u4e48\u529e<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,12],"tags":[],"class_list":["post-510","post","type-post","status-publish","format-standard","hentry","category-python","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts\/510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=510"}],"version-history":[{"count":0,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts\/510\/revisions"}],"wp:attachment":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}