{"id":43518,"date":"2024-10-05T20:27:04","date_gmt":"2024-10-05T12:27:04","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43518\/"},"modified":"2024-10-05T20:27:04","modified_gmt":"2024-10-05T12:27:04","slug":"centos-%e4%b8%8b%e5%b0%87-python2-%e5%8d%87%e7%b4%9a%e5%88%b0-python3-5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43518\/","title":{"rendered":"CentOS \u4e0b\u5c07 Python2 \u5347\u7d1a\u5230 Python3.5"},"content":{"rendered":"<h1 id=\"centos-%e4%b8%8b%e5%b0%87-python2-%e5%8d%87%e7%b4%9a%e5%88%b0-python3-5-CjAgqdbyRS\">CentOS \u4e0b\u5c07 Python2 \u5347\u7d1a\u5230 Python3.5<\/h1>\n<p>\u5728\u7576\u524d\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\u958b\u767c\u8005\u548c\u7cfb\u7d71\u7ba1\u7406\u54e1\u90fd\u958b\u59cb\u5c07\u5176\u5347\u7d1a\u5230 Python 3\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS \u7cfb\u7d71\u4e0a\u5c07 Python 2 \u5347\u7d1a\u5230 Python 3.5\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%81%b8%e6%93%87-python-3-5%ef%bc%9f-CjAgqdbyRS\">\u70ba\u4ec0\u9ebc\u9078\u64c7 Python 3.5\uff1f<\/h2>\n<p>Python 3.5 \u662f Python 3 \u7cfb\u5217\u4e2d\u7684\u4e00\u500b\u91cd\u8981\u7248\u672c\uff0c\u63d0\u4f9b\u4e86\u8a31\u591a\u65b0\u7279\u6027\u548c\u6027\u80fd\u6539\u9032\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u5f15\u5165\u4e86\u65b0\u7684\u8a9e\u6cd5\u7279\u6027\uff0c\u5982\u7570\u6b65\u751f\u6210\u5668\u548c\u5354\u7a0b\u3002<\/li>\n<li>\u589e\u5f37\u4e86\u6a19\u6e96\u5eab\uff0c\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u5167\u5efa\u51fd\u6578\u548c\u6a21\u7d44\u3002<\/li>\n<li>\u6539\u9032\u4e86\u932f\u8aa4\u8655\u7406\u548c\u8abf\u8a66\u5de5\u5177\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%aa%a2%e6%9f%a5%e7%95%b6%e5%89%8d-python-%e7%89%88%e6%9c%ac-CjAgqdbyRS\">\u6aa2\u67e5\u7576\u524d Python \u7248\u672c<\/h2>\n<p>\u5728\u5347\u7d1a\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u6aa2\u67e5\u7576\u524d\u5b89\u88dd\u7684 Python \u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u6aa2\u67e5\uff1a<\/p>\n<pre><code>python --version<\/code><\/pre>\n<p>\u5982\u679c\u986f\u793a\u7684\u662f Python 2.x\uff0c\u5247\u53ef\u4ee5\u7e7c\u7e8c\u9032\u884c\u5347\u7d1a\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-epel-%e5%ad%98%e5%84%b2%e5%ba%ab-CjAgqdbyRS\">\u5b89\u88dd EPEL \u5b58\u5132\u5eab<\/h2>\n<p>\u5728 CentOS \u4e0a\u5b89\u88dd Python 3.5\uff0c\u9996\u5148\u9700\u8981\u555f\u7528 EPEL\uff08Extra Packages for Enterprise Linux\uff09\u5b58\u5132\u5eab\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\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-5-CjAgqdbyRS\">\u5b89\u88dd Python 3.5<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Python 3.5\uff1a<\/p>\n<pre><code>sudo yum install python35<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u518d\u6b21\u6aa2\u67e5 Python \u7248\u672c\u4ee5\u78ba\u8a8d\u5b89\u88dd\u6210\u529f\uff1a<\/p>\n<pre><code>python3.5 --version<\/code><\/pre>\n<h2 id=\"%e8%a8%ad%e7%bd%ae-python-3-5-%e7%82%ba%e9%bb%98%e8%aa%8d%e7%89%88%e6%9c%ac-CjAgqdbyRS\">\u8a2d\u7f6e Python 3.5 \u70ba\u9ed8\u8a8d\u7248\u672c<\/h2>\n<p>\u5982\u679c\u5e0c\u671b\u5c07 Python 3.5 \u8a2d\u7f6e\u70ba\u9ed8\u8a8d\u7684 Python \u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo alternatives --set python \/usr\/bin\/python3.5<\/code><\/pre>\n<p>\u9019\u6a23\uff0c\u7576\u4f60\u8f38\u5165 <code>python<\/code> \u547d\u4ee4\u6642\uff0c\u7cfb\u7d71\u5c07\u6703\u4f7f\u7528 Python 3.5\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-pip3-CjAgqdbyRS\">\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 pip3\uff1a<\/p>\n<pre><code>sudo yum install python35-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-python-2-%e4%bb%a3%e7%a2%bc%e5%88%b0-python-3-5-CjAgqdbyRS\">\u9077\u79fb Python 2 \u4ee3\u78bc\u5230 Python 3.5<\/h2>\n<p>\u5728\u5347\u7d1a\u5230 Python 3.5 \u5f8c\uff0c\u53ef\u80fd\u9700\u8981\u5c0d\u73fe\u6709\u7684 Python 2 \u4ee3\u78bc\u9032\u884c\u4e00\u4e9b\u4fee\u6539\u3002\u53ef\u4ee5\u4f7f\u7528 <code>2to3<\/code> \u5de5\u5177\u4f86\u81ea\u52d5\u8f49\u63db\u4ee3\u78bc\uff1a<\/p>\n<pre><code>2to3 -w your_script.py<\/code><\/pre>\n<p>\u9019\u500b\u547d\u4ee4\u6703\u5c07 <code>your_script.py<\/code> \u4e2d\u7684 Python 2 \u4ee3\u78bc\u8f49\u63db\u70ba Python 3 \u4ee3\u78bc\uff0c\u4e26\u5728\u539f\u5730\u9032\u884c\u4fee\u6539\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-CjAgqdbyRS\">\u7e3d\u7d50<\/h2>\n<p>\u5728 CentOS \u7cfb\u7d71\u4e0a\u5c07 Python 2 \u5347\u7d1a\u5230 Python 3.5 \u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\uff0c\u901a\u904e\u5b89\u88dd EPEL \u5b58\u5132\u5eab\u3001\u5b89\u88dd Python 3.5 \u548c pip3\uff0c\u4e26\u4f7f\u7528\u5de5\u5177\u9077\u79fb\u4ee3\u78bc\uff0c\u53ef\u4ee5\u8f15\u9b06\u5b8c\u6210\u5347\u7d1a\u3002\u96a8\u8457 Python 2 \u7684\u9010\u6b65\u6dd8\u6c70\uff0c\u5347\u7d1a\u5230 Python 3 \u5c07\u6709\u52a9\u65bc\u958b\u767c\u8005\u5229\u7528\u6700\u65b0\u7684\u529f\u80fd\u548c\u6027\u80fd\u6539\u9032\u3002<\/p>\n<p>\u5982\u679c\u60a8\u9700\u8981\u66f4\u591a\u6709\u95dc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\uff0c\u4e86\u89e3\u6211\u5011\u7684\u670d\u52d9\u548c\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 CentOS \u4e0a\u5c07 Python 2 \u5347\u7d1a\u5230 Python 3.5\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-43518","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43518","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=43518"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43518\/revisions"}],"predecessor-version":[{"id":43519,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43518\/revisions\/43519"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}