{"id":44190,"date":"2024-10-06T13:38:12","date_gmt":"2024-10-06T05:38:12","guid":{"rendered":"https:\/\/server.hk\/cnblog\/44190\/"},"modified":"2024-10-06T13:38:13","modified_gmt":"2024-10-06T05:38:13","slug":"centos-%e4%b8%8b%e5%ae%89%e8%a3%9d-python","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/44190\/","title":{"rendered":"CentOS \u4e0b\u5b89\u88dd Python"},"content":{"rendered":"<h1 id=\"centos-%e4%b8%8b%e5%ae%89%e8%a3%9d-python-bBlSWBHIJE\">CentOS \u4e0b\u5b89\u88dd Python<\/h1>\n<p>Python \u662f\u4e00\u7a2e\u5ee3\u6cdb\u4f7f\u7528\u7684\u9ad8\u7d1a\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u56e0\u5176\u7c21\u6f54\u7684\u8a9e\u6cd5\u548c\u5f37\u5927\u7684\u529f\u80fd\u800c\u53d7\u5230\u958b\u767c\u8005\u7684\u559c\u611b\u3002\u5728 CentOS \u7cfb\u7d71\u4e0a\u5b89\u88dd Python \u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\uff0c\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u5728 CentOS \u4e0a\u5b89\u88dd Python\uff0c\u5305\u62ec\u4e0d\u540c\u7248\u672c\u7684\u5b89\u88dd\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"%e6%aa%a2%e6%9f%a5%e9%a0%90%e8%a3%9d%e7%9a%84-python-%e7%89%88%e6%9c%ac-bBlSWBHIJE\">\u6aa2\u67e5\u9810\u88dd\u7684 Python \u7248\u672c<\/h2>\n<p>\u5728\u958b\u59cb\u5b89\u88dd\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u6aa2\u67e5\u7cfb\u7d71\u4e2d\u662f\u5426\u5df2\u7d93\u5b89\u88dd\u4e86 Python\u3002\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u4f86\u6aa2\u67e5\uff1a<\/p>\n<pre><code>python --version<\/code><\/pre>\n<p>\u6216\u662f\uff1a<\/p>\n<pre><code>python3 --version<\/code><\/pre>\n<p>\u5982\u679c\u7cfb\u7d71\u4e2d\u5df2\u7d93\u5b89\u88dd\u4e86 Python\uff0c\u5247\u6703\u986f\u793a\u76f8\u61c9\u7684\u7248\u672c\u865f\u3002\u5982\u679c\u672a\u5b89\u88dd\uff0c\u5247\u53ef\u4ee5\u7e7c\u7e8c\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\u5b89\u88dd\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-python-2-x-bBlSWBHIJE\">\u5b89\u88dd Python 2.x<\/h2>\n<p>\u5728 CentOS \u4e0a\u5b89\u88dd Python 2.x \u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u9996\u5148\uff0c\u66f4\u65b0\u7cfb\u7d71\u7684\u8edf\u4ef6\u5305\u5217\u8868\uff1a<\/li>\n<pre><code>sudo yum update<\/code><\/pre>\n<li>\u7136\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Python 2.x\uff1a<\/li>\n<pre><code>sudo yum install python<\/code><\/pre>\n<li>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u518d\u6b21\u6aa2\u67e5 Python \u7248\u672c\uff1a<\/li>\n<pre><code>python --version<\/code><\/pre>\n<\/ol>\n<h2 id=\"%e5%ae%89%e8%a3%9d-python-3-x-bBlSWBHIJE\">\u5b89\u88dd Python 3.x<\/h2>\n<p>\u96a8\u8457 Python 2.x \u7684\u9010\u6b65\u6dd8\u6c70\uff0c\u8d8a\u4f86\u8d8a\u591a\u7684\u958b\u767c\u8005\u9078\u64c7\u4f7f\u7528 Python 3.x\u3002\u4ee5\u4e0b\u662f\u5728 CentOS \u4e0a\u5b89\u88dd Python 3.x \u7684\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li>\u9996\u5148\uff0c\u66f4\u65b0\u7cfb\u7d71\u7684\u8edf\u4ef6\u5305\u5217\u8868\uff1a<\/li>\n<pre><code>sudo yum update<\/code><\/pre>\n<li>\u63a5\u4e0b\u4f86\uff0c\u5b89\u88dd EPEL\uff08Extra Packages for Enterprise Linux\uff09\u5eab\uff0c\u9019\u662f\u5b89\u88dd Python 3.x \u6240\u9700\u7684\uff1a<\/li>\n<pre><code>sudo yum install epel-release<\/code><\/pre>\n<li>\u7136\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Python 3.x\uff1a<\/li>\n<pre><code>sudo yum install python3<\/code><\/pre>\n<li>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u6aa2\u67e5 Python 3 \u7684\u7248\u672c\uff1a<\/li>\n<pre><code>python3 --version<\/code><\/pre>\n<\/ol>\n<h2 id=\"%e5%ae%89%e8%a3%9d-pip-bBlSWBHIJE\">\u5b89\u88dd pip<\/h2>\n<p>pip \u662f Python \u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4f86\u5b89\u88dd\u548c\u7ba1\u7406 Python \u5305\u3002\u5b89\u88dd pip \u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u5c0d\u65bc Python 2.x\uff0c\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd pip\uff1a<\/li>\n<pre><code>sudo yum install python-pip<\/code><\/pre>\n<li>\u5c0d\u65bc Python 3.x\uff0c\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd pip\uff1a<\/li>\n<pre><code>sudo yum install python3-pip<\/code><\/pre>\n<\/ol>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e8%99%9b%e6%93%ac%e7%92%b0%e5%a2%83-bBlSWBHIJE\">\u4f7f\u7528\u865b\u64ec\u74b0\u5883<\/h2>\n<p>\u5728\u958b\u767c Python \u61c9\u7528\u6642\uff0c\u4f7f\u7528\u865b\u64ec\u74b0\u5883\u53ef\u4ee5\u5e6b\u52a9\u7ba1\u7406\u4e0d\u540c\u9805\u76ee\u7684\u4f9d\u8cf4\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5275\u5efa\u865b\u64ec\u74b0\u5883\uff1a<\/p>\n<pre><code>python3 -m venv myenv<\/code><\/pre>\n<p>\u555f\u52d5\u865b\u64ec\u74b0\u5883\uff1a<\/p>\n<pre><code>source myenv\/bin\/activate<\/code><\/pre>\n<p>\u5728\u865b\u64ec\u74b0\u5883\u4e2d\uff0c\u60a8\u53ef\u4ee5\u5b89\u88dd\u6240\u9700\u7684\u5305\uff0c\u800c\u4e0d\u6703\u5f71\u97ff\u5168\u5c40\u74b0\u5883\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-bBlSWBHIJE\">\u7e3d\u7d50<\/h2>\n<p>\u5728 CentOS \u4e0a\u5b89\u88dd Python \u662f\u4e00\u500b\u7c21\u55ae\u7684\u904e\u7a0b\uff0c\u7121\u8ad6\u662f Python 2.x \u9084\u662f Python 3.x\uff0c\u90fd\u53ef\u4ee5\u901a\u904e\u7c21\u55ae\u7684\u547d\u4ee4\u5b8c\u6210\u3002\u5b89\u88dd pip \u548c\u865b\u64ec\u74b0\u5883\u5f8c\uff0c\u60a8\u5c07\u80fd\u5920\u66f4\u6709\u6548\u5730\u7ba1\u7406\u60a8\u7684 Python \u958b\u767c\u74b0\u5883\u3002\u5982\u679c\u60a8\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u4f86\u904b\u884c\u60a8\u7684 Python \u61c9\u7528\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u60a8\u90fd\u53ef\u4ee5\u5728\u6211\u5011\u7684\u7db2\u7ad9\u4e0a\u627e\u5230\u5408\u9069\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to install Python on CentOS with step-by-step instructions for a smooth setup and optimal performance.<\/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-44190","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44190","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=44190"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44190\/revisions"}],"predecessor-version":[{"id":44191,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44190\/revisions\/44191"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=44190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=44190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=44190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}