{"id":1068854,"date":"2024-12-31T16:46:55","date_gmt":"2024-12-31T08:46:55","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1068854.html"},"modified":"2024-12-31T16:46:57","modified_gmt":"2024-12-31T08:46:57","slug":"%e5%9c%a8linux%e4%b8%8a%e9%9d%a2%e5%a6%82%e4%bd%95%e5%8d%b8%e8%bd%bdpython3","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1068854.html","title":{"rendered":"\u5728linux\u4e0a\u9762\u5982\u4f55\u5378\u8f7dpython3"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/5b86594c-ac02-4e4f-bf44-9bcadc96840f.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u5728linux\u4e0a\u9762\u5982\u4f55\u5378\u8f7dpython3\" \/><\/p>\n<p><p> <strong>\u5728 Linux \u4e0a\u5378\u8f7d Python3 \u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5305\u7ba1\u7406\u5668\uff08\u5982 apt\u3001yum \u7b49\uff09\u3001\u624b\u52a8\u5220\u9664\u5b89\u88c5\u6587\u4ef6\u548c\u4f9d\u8d56\u9879\u3001\u6e05\u7406\u73af\u5883\u53d8\u91cf\u7b49\u3002<\/strong> \u5176\u4e2d\uff0c\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u662f\u6700\u5e38\u89c1\u4e14\u63a8\u8350\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u76f8\u5bf9\u7b80\u5355\u4e14\u5b89\u5168\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\u5378\u8f7d Python3\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5378\u8f7d Python3<\/h3>\n<\/p>\n<p><h4>1\u3001Debian\/Ubuntu \u7cfb\u7edf<\/h4>\n<\/p>\n<p><p>\u5728 Debian \u6216 Ubuntu \u7cfb\u7edf\u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>apt<\/code> \u6216 <code>apt-get<\/code> \u547d\u4ee4\u6765\u5378\u8f7d Python3\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u66f4\u65b0\u8f6f\u4ef6\u5305\u5217\u8868<\/strong>\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">sudo apt update<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u5378\u8f7d Python3<\/strong>\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">sudo apt remove python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u6e05\u7406\u6b8b\u4f59\u6587\u4ef6<\/strong>\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">sudo apt autoremove<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u547d\u4ee4\u4f9d\u6b21\u66f4\u65b0\u8f6f\u4ef6\u5305\u5217\u8868\u3001\u5378\u8f7d Python3 \u4ee5\u53ca\u6e05\u7406\u6b8b\u4f59\u7684\u4f9d\u8d56\u9879\u548c\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>2\u3001CentOS\/RHEL \u7cfb\u7edf<\/h4>\n<\/p>\n<p><p>\u5728 CentOS \u6216 RHEL \u7cfb\u7edf\u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>yum<\/code> \u6216 <code>dnf<\/code> \u547d\u4ee4\u6765\u5378\u8f7d Python3\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u5378\u8f7d Python3<\/strong>\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">sudo yum remove python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo dnf remove python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u6e05\u7406\u6b8b\u4f59\u6587\u4ef6<\/strong>\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">sudo yum autoremove<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo dnf autoremove<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4ee5\u4e0a\u547d\u4ee4\u5c06\u5378\u8f7d Python3 \u53ca\u5176\u76f8\u5173\u7684\u4f9d\u8d56\u9879\u548c\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u624b\u52a8\u5220\u9664\u5b89\u88c5\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u662f\u901a\u8fc7\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5\u7684 Python3\uff0c\u90a3\u4e48\u9700\u8981\u624b\u52a8\u5220\u9664\u5b89\u88c5\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u67e5\u627e\u5b89\u88c5\u76ee\u5f55<\/h4>\n<\/p>\n<p><p>\u901a\u5e38\uff0cPython3 \u7684\u5b89\u88c5\u76ee\u5f55\u5728 <code>\/usr\/local\/<\/code> \u6216 <code>\/opt\/<\/code> \u4e0b\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u67e5\u627e\u5b89\u88c5\u76ee\u5f55\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">which python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5220\u9664\u5b89\u88c5\u76ee\u5f55<\/h4>\n<\/p>\n<p><p>\u627e\u5230\u5b89\u88c5\u76ee\u5f55\u540e\uff0c\u4f7f\u7528 <code>rm<\/code> \u547d\u4ee4\u5220\u9664\u8be5\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u5b89\u88c5\u76ee\u5f55\u5728 <code>\/usr\/local\/python3<\/code>\uff0c\u5219\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo rm -rf \/usr\/local\/python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5220\u9664\u76f8\u5173\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u68c0\u67e5\u5e76\u5220\u9664 <code>\/usr\/bin<\/code> \u6216 <code>\/usr\/local\/bin<\/code> \u4e2d\u7684 Python3 \u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo rm -f \/usr\/bin\/python3<\/p>\n<p>sudo rm -f \/usr\/local\/bin\/python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u6e05\u7406\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u5378\u8f7d Python3 \u540e\uff0c\u8fd8\u9700\u8981\u6e05\u7406\u76f8\u5173\u7684\u73af\u5883\u53d8\u91cf\uff0c\u907f\u514d\u51fa\u73b0\u8def\u5f84\u9519\u8bef\u6216\u51b2\u7a81\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u7f16\u8f91\u73af\u5883\u53d8\u91cf\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u7f16\u8f91 <code>.bashrc<\/code> \u6216 <code>.bash_profile<\/code> \u6587\u4ef6\uff0c\u5220\u9664\u4e0e Python3 \u76f8\u5173\u7684\u8def\u5f84\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">nano ~\/.bashrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">nano ~\/.bash_profile<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u627e\u5230\u7c7b\u4f3c\u4ee5\u4e0b\u5185\u5bb9\u7684\u884c\u5e76\u5220\u9664\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PATH=&quot;\/usr\/local\/python3\/bin:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5237\u65b0\u73af\u5883\u53d8\u91cf<\/h4>\n<\/p>\n<p><p>\u4fdd\u5b58\u5e76\u5173\u95ed\u6587\u4ef6\u540e\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u5237\u65b0\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source ~\/.bashrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source ~\/.bash_profile<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><h4>1\u3001\u7cfb\u7edf\u4f9d\u8d56<\/h4>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b Linux \u53d1\u884c\u7248\u4e2d\uff0cPython \u662f\u7cfb\u7edf\u7684\u4e00\u90e8\u5206\uff0c\u8bb8\u591a\u7cfb\u7edf\u5de5\u5177\u548c\u811a\u672c\u90fd\u4f9d\u8d56\u4e8e\u5b83\u3002\u5728\u5378\u8f7d Python3 \u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u7684\u6b63\u5e38\u8fd0\u884c\u3002\u5982\u679c\u5fc5\u987b\u5378\u8f7d\uff0c\u8bf7\u5907\u4efd\u7cfb\u7edf\u5e76\u786e\u8ba4\u6ca1\u6709\u4f9d\u8d56 Python3 \u7684\u5173\u952e\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u591a\u7248\u672c\u5171\u5b58<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u7cfb\u7edf\u4e2d\u540c\u65f6\u5b58\u5728\u591a\u4e2a Python \u7248\u672c\uff08\u5982 Python2 \u548c Python3\uff09\uff0c\u8bf7\u786e\u4fdd\u5728\u5378\u8f7d\u5176\u4e2d\u4e00\u4e2a\u7248\u672c\u65f6\u4e0d\u4f1a\u8bef\u5220\u9664\u6216\u5f71\u54cd\u53e6\u4e00\u4e2a\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528 <code>python<\/code> \u548c <code>python3<\/code> \u547d\u4ee4\u5206\u522b\u8c03\u7528\u4e0d\u540c\u7248\u672c\u7684 Python\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u4f7f\u7528\u865a\u62df\u73af\u5883\uff08\u5982 <code>virtualenv<\/code> \u6216 <code>pyenv<\/code>\uff09\uff0c\u8bf7\u786e\u8ba4\u5728\u5378\u8f7d Python3 \u4e4b\u524d\u5df2\u5220\u9664\u6216\u8fc1\u79fb\u76f8\u5173\u7684\u865a\u62df\u73af\u5883\u3002\u865a\u62df\u73af\u5883\u53ef\u4ee5\u6709\u6548\u9694\u79bb\u4e0d\u540c\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u907f\u514d\u51b2\u7a81\u548c\u7248\u672c\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0c\u5378\u8f7d Python3 \u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u3001\u624b\u52a8\u5220\u9664\u5b89\u88c5\u6587\u4ef6\u4ee5\u53ca\u6e05\u7406\u73af\u5883\u53d8\u91cf\u3002<strong>\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u662f\u6700\u5e38\u89c1\u4e14\u63a8\u8350\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u76f8\u5bf9\u7b80\u5355\u4e14\u5b89\u5168<\/strong>\u3002\u65e0\u8bba\u91c7\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u5e94\u786e\u4fdd\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u7684\u6b63\u5e38\u8fd0\u884c\uff0c\u7279\u522b\u662f\u5728\u7cfb\u7edf\u5de5\u5177\u548c\u811a\u672c\u4f9d\u8d56 Python3 \u7684\u60c5\u51b5\u4e0b\u3002<\/p>\n<\/p>\n<p><p>\u5378\u8f7d Python3 \u540e\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u91cd\u65b0\u5b89\u88c5\u5176\u4ed6\u7248\u672c\u6216\u4e0d\u540c\u7684 Python \u89e3\u91ca\u5668\uff0c\u4ee5\u6ee1\u8db3\u7279\u5b9a\u7684\u5f00\u53d1\u6216\u8fd0\u884c\u9700\u6c42\u3002\u5728\u5b89\u88c5\u548c\u5378\u8f7d\u8fc7\u7a0b\u4e2d\uff0c\u59cb\u7ec8\u4fdd\u6301\u8c28\u614e\uff0c\u786e\u4fdd\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u5b89\u5168\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u5982\u4f55\u786e\u8ba4\u5df2\u5b89\u88c5\u7684Python3\u7248\u672c\uff1f<\/strong><br \/>\u8981\u786e\u8ba4\u5728Linux\u7cfb\u7edf\u4e2d\u5b89\u88c5\u4e86\u54ea\u4e9b\u7248\u672c\u7684Python3\uff0c\u60a8\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<code>python3 --version<\/code> \u6216 <code>python3 -V<\/code>\u3002\u8fd9\u5c06\u663e\u793a\u5f53\u524d\u5b89\u88c5\u7684Python3\u7248\u672c\u4fe1\u606f\u3002\u5982\u679c\u60a8\u6709\u591a\u4e2aPython\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>ls \/usr\/bin\/python*<\/code>\u547d\u4ee4\u67e5\u770b\u6240\u6709Python\u7684\u5b89\u88c5\u8def\u5f84\u548c\u7248\u672c\u3002<\/p>\n<p><strong>\u5728Linux\u4e2d\uff0c\u5378\u8f7dPython3\u4f1a\u5f71\u54cd\u7cfb\u7edf\u7684\u54ea\u4e9b\u529f\u80fd\uff1f<\/strong><br \/>\u8bb8\u591aLinux\u53d1\u884c\u7248\uff08\u5982Ubuntu\u548cCentOS\uff09\u5c06Python\u4f5c\u4e3a\u7cfb\u7edf\u5de5\u5177\u7684\u4e00\u90e8\u5206\uff0c\u56e0\u6b64\u5378\u8f7dPython3\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u67d0\u4e9b\u529f\u80fd\u6216\u5e94\u7528\u7a0b\u5e8f\u65e0\u6cd5\u6b63\u5e38\u8fd0\u884c\u3002\u5728\u8fdb\u884c\u5378\u8f7d\u4e4b\u524d\uff0c\u786e\u4fdd\u60a8\u4e86\u89e3\u54ea\u4e9b\u4f9d\u8d56\u4e8ePython3\u7684\u7a0b\u5e8f\uff0c\u5e76\u8003\u8651\u662f\u5426\u9700\u8981\u4fdd\u7559\u67d0\u4e9b\u7248\u672c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Linux\u4e0a\u5b89\u5168\u5730\u5378\u8f7dPython3\u4ee5\u9632\u6b62\u7cfb\u7edf\u5d29\u6e83\uff1f<\/strong><br \/>\u5728\u5378\u8f7dPython3\u4e4b\u524d\uff0c\u5efa\u8bae\u60a8\u5148\u5b89\u88c5\u4e00\u4e2a\u66ff\u4ee3\u7248\u672c\uff08\u5982Python2\u6216\u66f4\u65b0\u7684Python3\u7248\u672c\uff09\uff0c\u4ee5\u786e\u4fdd\u7cfb\u7edf\u4ecd\u80fd\u6b63\u5e38\u8fd0\u884c\u3002\u53ef\u4ee5\u4f7f\u7528\u5305\u7ba1\u7406\u5668\uff08\u5982apt\u3001yum\u7b49\uff09\u6765\u5378\u8f7dPython3\uff0c\u5e76\u5728\u5378\u8f7d\u524d\u521b\u5efa\u7cfb\u7edf\u5907\u4efd\u6216\u4f7f\u7528\u865a\u62df\u73af\u5883\uff0c\u4ee5\u4fbf\u8f7b\u677e\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\u3002\u8fd0\u884c\u547d\u4ee4\u5982<code>sudo apt remove python3<\/code>\u6216<code>sudo yum remove python3<\/code>\uff0c\u5e76\u6839\u636e\u63d0\u793a\u786e\u8ba4\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728 Linux \u4e0a\u5378\u8f7d Python3 \u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5305\u7ba1\u7406\u5668\uff08\u5982 apt\u3001yum \u7b49\uff09\u3001\u624b\u52a8\u5220\u9664\u5b89\u88c5\u6587\u4ef6\u548c\u4f9d [&hellip;]","protected":false},"author":3,"featured_media":1068859,"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\/1068854"}],"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=1068854"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1068854\/revisions"}],"predecessor-version":[{"id":1068860,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1068854\/revisions\/1068860"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1068859"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1068854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1068854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1068854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}