{"id":43780,"date":"2024-10-06T09:57:01","date_gmt":"2024-10-06T01:57:01","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43780\/"},"modified":"2024-10-06T09:57:01","modified_gmt":"2024-10-06T01:57:01","slug":"centos-7-%e4%bf%9d%e7%95%99%e9%bb%98%e8%aa%8d-python-%e7%89%88%e6%9c%ac%e4%b8%a6%e5%ae%89%e8%a3%9d%e6%9b%b4%e6%96%b0-python-2-%e5%92%8c-python-3-%e5%85%b1%e5%ad%98","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43780\/","title":{"rendered":"CentOS 7 \u4fdd\u7559\u9ed8\u8a8d Python \u7248\u672c\u4e26\u5b89\u88dd\u66f4\u65b0 Python 2 \u548c Python 3 \u5171\u5b58"},"content":{"rendered":"<h1 id=\"centos-7-%e4%bf%9d%e7%95%99%e9%bb%98%e8%aa%8d-python-%e7%89%88%e6%9c%ac%e4%b8%a6%e5%ae%89%e8%a3%9d%e6%9b%b4%e6%96%b0-python-2-%e5%92%8c-python-3-%e5%85%b1%e5%ad%98-HZHvPMHyHB\">CentOS 7 \u4fdd\u7559\u9ed8\u8a8d Python \u7248\u672c\u4e26\u5b89\u88dd\u66f4\u65b0 Python 2 \u548c Python 3 \u5171\u5b58<\/h1>\n<p>\u5728 CentOS 7 \u7cfb\u7d71\u4e2d\uff0cPython \u662f\u4e00\u500b\u91cd\u8981\u7684\u5de5\u5177\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u7cfb\u7d71\u7ba1\u7406\u3001\u7db2\u7d61\u958b\u767c\u53ca\u81ea\u52d5\u5316\u4efb\u52d9\u7b49\u591a\u500b\u9818\u57df\u3002\u7531\u65bc\u8a31\u591a\u7cfb\u7d71\u5de5\u5177\u548c\u61c9\u7528\u7a0b\u5e8f\u4f9d\u8cf4\u65bc Python 2\uff0c\u56e0\u6b64\u5728 CentOS 7 \u4e2d\uff0c\u9ed8\u8a8d\u5b89\u88dd\u7684 Python \u7248\u672c\u70ba Python 2.7\u3002\u7136\u800c\uff0c\u96a8\u8457 Python 2 \u7684\u5b98\u65b9\u652f\u6301\u5df2\u65bc 2020 \u5e74 1 \u6708\u7d50\u675f\uff0c\u8a31\u591a\u958b\u767c\u8005\u548c\u7cfb\u7d71\u7ba1\u7406\u54e1\u958b\u59cb\u8f49\u5411 Python 3\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 7 \u4e2d\u4fdd\u7559\u9ed8\u8a8d\u7684 Python \u7248\u672c\uff0c\u540c\u6642\u5b89\u88dd\u66f4\u65b0\u7684 Python 2 \u548c Python 3 \u4ee5\u5be6\u73fe\u5171\u5b58\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e5%85%b1%e5%ad%98-python-2-%e5%92%8c-python-3%ef%bc%9f-HZHvPMHyHB\">\u70ba\u4ec0\u9ebc\u9700\u8981\u5171\u5b58 Python 2 \u548c Python 3\uff1f<\/h2>\n<p>Python 2 \u548c Python 3 \u4e4b\u9593\u5b58\u5728\u4e00\u4e9b\u4e0d\u517c\u5bb9\u7684\u8b8a\u66f4\uff0c\u9019\u4f7f\u5f97\u67d0\u4e9b\u820a\u7684\u61c9\u7528\u7a0b\u5e8f\u7121\u6cd5\u5728 Python 3 \u4e0a\u904b\u884c\u3002\u56e0\u6b64\uff0c\u8a31\u591a\u7528\u6236\u4ecd\u7136\u9700\u8981\u4fdd\u7559 Python 2 \u7684\u74b0\u5883\u3002\u540c\u6642\uff0cPython 3 \u63d0\u4f9b\u4e86\u8a31\u591a\u65b0\u7279\u6027\u548c\u6027\u80fd\u6539\u9032\uff0c\u5c0d\u65bc\u65b0\u958b\u767c\u7684\u61c9\u7528\u7a0b\u5e8f\u4f86\u8aaa\uff0c\u4f7f\u7528 Python 3 \u662f\u66f4\u597d\u7684\u9078\u64c7\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-python-3-HZHvPMHyHB\">\u5b89\u88dd Python 3<\/h2>\n<p>\u5728 CentOS 7 \u4e2d\u5b89\u88dd Python 3 \u7684\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u7cfb\u7d71\u7684\u5305\u7ba1\u7406\u5668\u662f\u6700\u65b0\u7684\uff0c\u7136\u5f8c\u5b89\u88dd EPEL\uff08Extra Packages for Enterprise Linux\uff09\u5eab\uff0c\u9019\u662f\u5b89\u88dd Python 3 \u7684\u5fc5\u8981\u6b65\u9a5f\u3002<\/p>\n<pre><code>sudo yum install epel-release\nsudo yum update\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Python 3\uff1a<\/p>\n<pre><code>sudo yum install python34\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 Python 3 \u7684\u7248\u672c\uff1a<\/p>\n<pre><code>python3.4 --version\n<\/code><\/pre>\n<h2 id=\"%e4%bf%9d%e7%95%99%e9%bb%98%e8%aa%8d%e7%9a%84-python-2-%e7%89%88%e6%9c%ac-HZHvPMHyHB\">\u4fdd\u7559\u9ed8\u8a8d\u7684 Python 2 \u7248\u672c<\/h2>\n<p>\u5728 CentOS 7 \u4e2d\uff0c\u9ed8\u8a8d\u7684 Python \u7248\u672c\u662f Python 2.7\u3002\u70ba\u4e86\u907f\u514d\u7cfb\u7d71\u5de5\u5177\u548c\u61c9\u7528\u7a0b\u5e8f\u51fa\u73fe\u554f\u984c\uff0c\u60a8\u61c9\u8a72\u907f\u514d\u66f4\u6539\u9ed8\u8a8d\u7684 Python \u7248\u672c\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5\u9ed8\u8a8d\u7684 Python \u7248\u672c\uff1a<\/p>\n<pre><code>python --version\n<\/code><\/pre>\n<p>\u5982\u679c\u60a8\u9700\u8981\u4f7f\u7528 Python 3\uff0c\u5efa\u8b70\u4f7f\u7528 <code>python3<\/code> \u547d\u4ee4\u4f86\u904b\u884c Python 3\uff0c\u800c\u4e0d\u662f\u66f4\u6539\u9ed8\u8a8d\u7684 Python \u7248\u672c\u3002<\/p>\n<h2 id=\"%e8%a8%ad%e7%bd%ae%e8%99%9b%e6%93%ac%e7%92%b0%e5%a2%83-HZHvPMHyHB\">\u8a2d\u7f6e\u865b\u64ec\u74b0\u5883<\/h2>\n<p>\u70ba\u4e86\u66f4\u597d\u5730\u7ba1\u7406 Python \u74b0\u5883\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u865b\u64ec\u74b0\u5883\u3002\u865b\u64ec\u74b0\u5883\u5141\u8a31\u60a8\u5728\u540c\u4e00\u7cfb\u7d71\u4e0a\u5275\u5efa\u591a\u500b\u7368\u7acb\u7684 Python \u74b0\u5883\uff0c\u9019\u6a23\u53ef\u4ee5\u907f\u514d\u4e0d\u540c\u9805\u76ee\u4e4b\u9593\u7684\u4f9d\u8cf4\u885d\u7a81\u3002<\/p>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88dd <code>virtualenv<\/code> \u5de5\u5177\uff1a<\/p>\n<pre><code>sudo yum install python34-virtualenv\n<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u4e00\u500b\u65b0\u7684\u865b\u64ec\u74b0\u5883\uff1a<\/p>\n<pre><code>virtualenv -p python3.4 myenv\n<\/code><\/pre>\n<p>\u6fc0\u6d3b\u865b\u64ec\u74b0\u5883\u5f8c\uff0c\u60a8\u53ef\u4ee5\u5728\u8a72\u74b0\u5883\u4e2d\u5b89\u88dd\u6240\u9700\u7684 Python \u5305\uff1a<\/p>\n<pre><code>source myenv\/bin\/activate\npip install \n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-HZHvPMHyHB\">\u7e3d\u7d50<\/h2>\n<p>\u5728 CentOS 7 \u4e2d\u4fdd\u7559\u9ed8\u8a8d\u7684 Python \u7248\u672c\u4e26\u5b89\u88dd\u66f4\u65b0\u7684 Python 2 \u548c Python 3 \u5171\u5b58\u662f\u4e00\u500b\u6709\u6548\u7684\u89e3\u6c7a\u65b9\u6848\uff0c\u80fd\u5920\u6eff\u8db3\u4e0d\u540c\u61c9\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\u3002\u901a\u904e\u4f7f\u7528\u865b\u64ec\u74b0\u5883\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u7ba1\u7406\u4e0d\u540c\u7684 Python \u74b0\u5883\uff0c\u907f\u514d\u4f9d\u8cf4\u885d\u7a81\u3002\u9019\u6a23\u7684\u8a2d\u7f6e\u4e0d\u50c5\u63d0\u9ad8\u4e86\u7cfb\u7d71\u7684\u9748\u6d3b\u6027\uff0c\u4e5f\u70ba\u958b\u767c\u8005\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u958b\u767c\u9ad4\u9a57\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u5404\u7a2e\u9700\u6c42\u3002\u7121\u8ad6\u662f\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f\u9748\u6d3b\u7684 <a href=\"https:\/\/server.hk\">\u4e91\u4f3a\u670d\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728 CentOS 7 \u4e2d\u4fdd\u7559\u9ed8\u8a8d Python \u7248\u672c\uff0c\u540c\u6642\u5b89\u88dd\u66f4\u65b0\u7684 Python 2 \u548c Python 3 \u4ee5\u5be6\u73fe\u5171\u5b58\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-43780","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43780","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=43780"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43780\/revisions"}],"predecessor-version":[{"id":43781,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43780\/revisions\/43781"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}