{"id":43110,"date":"2024-10-04T17:17:16","date_gmt":"2024-10-04T09:17:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43110\/"},"modified":"2024-10-04T17:17:16","modified_gmt":"2024-10-04T09:17:16","slug":"centos-7-%e5%be%9e-python-2-7-%e5%8d%87%e7%b4%9a%e8%87%b3-python-3-6-1","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43110\/","title":{"rendered":"CentOS 7 \u5f9e Python 2.7 \u5347\u7d1a\u81f3 Python 3.6.1"},"content":{"rendered":"<h1 id=\"centos-7-%e5%be%9e-python-2-7-%e5%8d%87%e7%b4%9a%e8%87%b3-python-3-6-1-ObyOhtxQnb\">CentOS 7 \u5f9e Python 2.7 \u5347\u7d1a\u81f3 Python 3.6.1<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u958b\u767c\u74b0\u5883\u4e2d\uff0cPython \u5df2\u7d93\u6210\u70ba\u4e00\u7a2e\u5ee3\u6cdb\u4f7f\u7528\u7684\u7de8\u7a0b\u8a9e\u8a00\u3002\u96a8\u8457 Python 2 \u7684\u5b98\u65b9\u652f\u6301\u65bc 2020 \u5e74\u521d\u7d50\u675f\uff0c\u8a31\u591a\u4f7f\u7528 CentOS 7 \u7684\u958b\u767c\u8005\u958b\u59cb\u8003\u616e\u5c07\u5176\u7cfb\u7d71\u4e2d\u7684 Python 2.7 \u5347\u7d1a\u81f3 Python 3.6.1\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 7 \u4e0a\u9032\u884c\u9019\u4e00\u5347\u7d1a\u904e\u7a0b\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%81%b8%e6%93%87-python-3-6-1%ef%bc%9f-ObyOhtxQnb\">\u70ba\u4ec0\u9ebc\u9078\u64c7 Python 3.6.1\uff1f<\/h2>\n<p>Python 3.6.1 \u5f15\u5165\u4e86\u8a31\u591a\u65b0\u7279\u6027\u548c\u6539\u9032\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\uff08f-strings\uff09\uff0c\u4f7f\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u66f4\u52a0\u7c21\u6f54\u3002<\/li>\n<li>\u5b57\u5178\u7684\u4fdd\u5e8f\u7279\u6027\uff0c\u8b93\u958b\u767c\u8005\u80fd\u5920\u66f4\u597d\u5730\u63a7\u5236\u6578\u64da\u7684\u9806\u5e8f\u3002<\/li>\n<li>\u7570\u6b65\u751f\u6210\u5668\u548c\u7570\u6b65\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\uff0c\u63d0\u5347\u4e86\u7570\u6b65\u7de8\u7a0b\u7684\u80fd\u529b\u3002<\/li>\n<\/ul>\n<p>\u9019\u4e9b\u65b0\u7279\u6027\u4f7f\u5f97 Python 3.6.1 \u6210\u70ba\u4e00\u500b\u66f4\u5f37\u5927\u4e14\u9748\u6d3b\u7684\u9078\u64c7\uff0c\u9069\u5408\u73fe\u4ee3\u958b\u767c\u9700\u6c42\u3002<\/p>\n<h2 id=\"%e5%8d%87%e7%b4%9a%e5%89%8d%e7%9a%84%e6%ba%96%e5%82%99-ObyOhtxQnb\">\u5347\u7d1a\u524d\u7684\u6e96\u5099<\/h2>\n<p>\u5728\u9032\u884c\u5347\u7d1a\u4e4b\u524d\uff0c\u5efa\u8b70\u5148\u6aa2\u67e5\u7cfb\u7d71\u4e2d\u5df2\u5b89\u88dd\u7684 Python \u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u78ba\u8a8d\uff1a<\/p>\n<pre><code>python --version<\/code><\/pre>\n<p>\u5982\u679c\u986f\u793a\u7684\u662f Python 2.7.x\uff0c\u5247\u53ef\u4ee5\u958b\u59cb\u5347\u7d1a\u904e\u7a0b\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-epel-%e5%ad%98%e5%84%b2%e5%ba%ab-ObyOhtxQnb\">\u5b89\u88dd EPEL \u5b58\u5132\u5eab<\/h2>\n<p>\u9996\u5148\uff0c\u9700\u8981\u5b89\u88dd EPEL\uff08Extra Packages for Enterprise Linux\uff09\u5b58\u5132\u5eab\uff0c\u56e0\u70ba Python 3.6.1 \u53ef\u80fd\u4e0d\u5728\u9ed8\u8a8d\u7684 CentOS \u5b58\u5132\u5eab\u4e2d\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd EPEL\uff1a<\/p>\n<pre><code>sudo yum install epel-release<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-python-3-6-1-ObyOhtxQnb\">\u5b89\u88dd Python 3.6.1<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Python 3.6.1\uff1a<\/p>\n<pre><code>sudo yum install python36<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u518d\u6b21\u6aa2\u67e5 Python \u7248\u672c\uff1a<\/p>\n<pre><code>python3.6 --version<\/code><\/pre>\n<h2 id=\"%e8%a8%ad%e7%bd%ae-python-3-6-%e7%82%ba%e9%bb%98%e8%aa%8d%e7%89%88%e6%9c%ac-ObyOhtxQnb\">\u8a2d\u7f6e Python 3.6 \u70ba\u9ed8\u8a8d\u7248\u672c<\/h2>\n<p>\u5982\u679c\u5e0c\u671b\u5c07 Python 3.6 \u8a2d\u7f6e\u70ba\u9ed8\u8a8d\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528 alternatives \u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo alternatives --set python \/usr\/bin\/python3.6<\/code><\/pre>\n<p>\u9019\u6a23\uff0c\u7576\u57f7\u884c `python` \u547d\u4ee4\u6642\uff0c\u7cfb\u7d71\u5c07\u4f7f\u7528 Python 3.6\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-pip3-ObyOhtxQnb\">\u5b89\u88dd pip3<\/h2>\n<p>\u70ba\u4e86\u65b9\u4fbf\u7ba1\u7406 Python \u5305\uff0c\u5efa\u8b70\u5b89\u88dd pip3\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo yum install python36-pip<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 pip3 \u7684\u7248\u672c\uff1a<\/p>\n<pre><code>pip3 --version<\/code><\/pre>\n<h2 id=\"%e9%81%b7%e7%a7%bb%e7%8f%be%e6%9c%89%e9%a0%85%e7%9b%ae-ObyOhtxQnb\">\u9077\u79fb\u73fe\u6709\u9805\u76ee<\/h2>\n<p>\u5728\u5347\u7d1a\u81f3 Python 3.6.1 \u5f8c\uff0c\u958b\u767c\u8005\u9700\u8981\u8003\u616e\u5982\u4f55\u5c07\u73fe\u6709\u7684 Python 2.7 \u9805\u76ee\u9077\u79fb\u81f3 Python 3\u3002\u9019\u901a\u5e38\u6d89\u53ca\u5230\u4ee3\u78bc\u7684\u4fee\u6539\u548c\u6e2c\u8a66\u3002\u53ef\u4ee5\u4f7f\u7528 <a href=\"https:\/\/docs.python.org\/3\/library\/2to3.html\" rel=\"nofollow noopener\" target=\"_blank\">2to3<\/a> \u5de5\u5177\u4f86\u81ea\u52d5\u8f49\u63db\u4ee3\u78bc\uff0c\u96d6\u7136\u4ecd\u7136\u9700\u8981\u624b\u52d5\u6aa2\u67e5\u548c\u6e2c\u8a66\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ObyOhtxQnb\">\u7e3d\u7d50<\/h2>\n<p>\u5c07 CentOS 7 \u4e0a\u7684 Python 2.7 \u5347\u7d1a\u81f3 Python 3.6.1 \u662f\u4e00\u500b\u91cd\u8981\u7684\u6b65\u9a5f\uff0c\u80fd\u5920\u8b93\u958b\u767c\u8005\u5229\u7528\u6700\u65b0\u7684\u8a9e\u8a00\u7279\u6027\u548c\u6539\u9032\u3002\u901a\u904e\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u5b8c\u6210\u5347\u7d1a\u904e\u7a0b\uff0c\u4e26\u70ba\u672a\u4f86\u7684\u958b\u767c\u505a\u597d\u6e96\u5099\u3002\u5982\u679c\u60a8\u9700\u8981\u7a69\u5b9a\u7684\u74b0\u5883\u4f86\u904b\u884c\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\uff0c\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u670d\u52d9\uff0c\u63d0\u4f9b\u9ad8\u6548\u80fd\u7684\u652f\u6301\u548c\u9748\u6d3b\u7684\u914d\u7f6e\u9078\u64c7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 CentOS 7 \u4e0a\u5c07 Python 2.7 \u5347\u7d1a\u81f3 Python 3.6.1\uff0c\u78ba\u4fdd\u7cfb\u7d71\u517c\u5bb9\u6027\u8207\u6700\u65b0\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-43110","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=43110"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43110\/revisions"}],"predecessor-version":[{"id":43111,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43110\/revisions\/43111"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}