{"id":44268,"date":"2024-10-06T14:18:13","date_gmt":"2024-10-06T06:18:13","guid":{"rendered":"https:\/\/server.hk\/cnblog\/44268\/"},"modified":"2024-10-06T14:18:13","modified_gmt":"2024-10-06T06:18:13","slug":"centos-%e4%b8%ad-python-%e5%8d%87%e7%b4%9a%e8%88%87-mysql-python%e3%80%81lxml-%e7%9a%84%e5%ae%89%e8%a3%9d","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/44268\/","title":{"rendered":"CentOS \u4e2d Python \u5347\u7d1a\u8207 MySQL-Python\u3001lxml \u7684\u5b89\u88dd"},"content":{"rendered":"<h1 id=\"centos-%e4%b8%ad-python-%e5%8d%87%e7%b4%9a%e8%88%87-mysql-python%e3%80%81lxml-%e7%9a%84%e5%ae%89%e8%a3%9d-xotgMdXcEp\">CentOS \u4e2d Python \u5347\u7d1a\u8207 MySQL-Python\u3001lxml \u7684\u5b89\u88dd<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u958b\u767c\u74b0\u5883\u4e2d\uff0cPython \u662f\u4e00\u7a2e\u5ee3\u6cdb\u4f7f\u7528\u7684\u7de8\u7a0b\u8a9e\u8a00\uff0c\u7279\u5225\u662f\u5728\u6578\u64da\u8655\u7406\u548c\u7db2\u9801\u958b\u767c\u9818\u57df\u3002\u5c0d\u65bc\u4f7f\u7528 CentOS \u4f5c\u70ba\u4f3a\u670d\u5668\u64cd\u4f5c\u7cfb\u7d71\u7684\u958b\u767c\u8005\u4f86\u8aaa\uff0c\u5347\u7d1a Python \u7248\u672c\u4ee5\u53ca\u5b89\u88dd\u76f8\u95dc\u7684\u5eab\u5982 MySQL-Python \u548c lxml \u662f\u4e00\u500b\u5e38\u898b\u7684\u9700\u6c42\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u5728 CentOS \u4e2d\u9032\u884c Python \u5347\u7d1a\u53ca\u5b89\u88dd\u9019\u4e9b\u5eab\u7684\u6b65\u9a5f\u3002<\/p>\n<h2 id=\"%e4%b8%80%e3%80%81%e6%aa%a2%e6%9f%a5%e7%95%b6%e5%89%8d-python-%e7%89%88%e6%9c%ac-xotgMdXcEp\">\u4e00\u3001\u6aa2\u67e5\u7576\u524d Python \u7248\u672c<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u6aa2\u67e5\u7576\u524d\u5b89\u88dd\u7684 Python \u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u67e5\u770b\uff1a<\/p>\n<pre><code>python --version<\/code><\/pre>\n<p>\u5982\u679c\u7cfb\u7d71\u4e2d\u5b89\u88dd\u4e86 Python 3\uff0c\u5247\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>python3 --version<\/code><\/pre>\n<h2 id=\"%e4%ba%8c%e3%80%81%e5%8d%87%e7%b4%9a-python-xotgMdXcEp\">\u4e8c\u3001\u5347\u7d1a Python<\/h2>\n<p>\u5728 CentOS \u4e2d\uff0c\u901a\u5e38\u53ef\u4ee5\u901a\u904e EPEL\uff08Extra Packages for Enterprise Linux\uff09\u4f86\u5b89\u88dd\u6216\u5347\u7d1a Python\u3002\u9996\u5148\uff0c\u78ba\u4fdd EPEL \u5df2\u7d93\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo yum install epel-release<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5b89\u88dd\u6700\u65b0\u7248\u672c\u7684 Python 3\uff1a<\/p>\n<pre><code>sudo yum install python3<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u518d\u6b21\u6aa2\u67e5 Python \u7248\u672c\u4ee5\u78ba\u8a8d\u5347\u7d1a\u6210\u529f\u3002<\/p>\n<h2 id=\"%e4%b8%89%e3%80%81%e5%ae%89%e8%a3%9d-mysql-python-xotgMdXcEp\">\u4e09\u3001\u5b89\u88dd MySQL-Python<\/h2>\n<p>MySQL-Python \u662f\u4e00\u500b\u7528\u65bc Python \u7684 MySQL \u6578\u64da\u5eab\u63a5\u53e3\u3002\u8981\u5b89\u88dd MySQL-Python\uff0c\u9996\u5148\u9700\u8981\u5b89\u88dd\u4e00\u4e9b\u4f9d\u8cf4\u9805\uff1a<\/p>\n<pre><code>sudo yum install mysql-devel<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u4f7f\u7528 pip \u5b89\u88dd MySQL-Python\uff1a<\/p>\n<pre><code>sudo pip3 install MySQL-python<\/code><\/pre>\n<p>\u5982\u679c\u5728\u5b89\u88dd\u904e\u7a0b\u4e2d\u9047\u5230\u554f\u984c\uff0c\u53ef\u80fd\u9700\u8981\u5b89\u88dd\u5176\u4ed6\u958b\u767c\u5de5\u5177\uff1a<\/p>\n<pre><code>sudo yum groupinstall \"Development Tools\"<\/code><\/pre>\n<h2 id=\"%e5%9b%9b%e3%80%81%e5%ae%89%e8%a3%9d-lxml-xotgMdXcEp\">\u56db\u3001\u5b89\u88dd lxml<\/h2>\n<p>lxml \u662f\u4e00\u500b\u5f37\u5927\u7684 XML \u548c HTML \u8655\u7406\u5eab\u3002\u5b89\u88dd lxml \u4e4b\u524d\uff0c\u540c\u6a23\u9700\u8981\u5b89\u88dd\u4e00\u4e9b\u4f9d\u8cf4\u9805\uff1a<\/p>\n<pre><code>sudo yum install libxml2-devel libxslt-devel<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u4f7f\u7528 pip \u5b89\u88dd lxml\uff1a<\/p>\n<pre><code>sudo pip3 install lxml<\/code><\/pre>\n<h2 id=\"%e4%ba%94%e3%80%81%e9%a9%97%e8%ad%89%e5%ae%89%e8%a3%9d-xotgMdXcEp\">\u4e94\u3001\u9a57\u8b49\u5b89\u88dd<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u4f86\u9a57\u8b49 MySQL-Python \u548c lxml \u662f\u5426\u5b89\u88dd\u6210\u529f\uff1a<\/p>\n<pre><code>python3 -c \"import MySQLdb; print('MySQL-Python \u5b89\u88dd\u6210\u529f')\" <\/code><\/pre>\n<pre><code>python3 -c \"import lxml; print('lxml \u5b89\u88dd\u6210\u529f')\" <\/code><\/pre>\n<p>\u5982\u679c\u6c92\u6709\u932f\u8aa4\u4fe1\u606f\u986f\u793a\uff0c\u5247\u8868\u793a\u5b89\u88dd\u6210\u529f\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-xotgMdXcEp\">\u7e3d\u7d50<\/h2>\n<p>\u5728 CentOS \u4e2d\u5347\u7d1a Python \u53ca\u5b89\u88dd MySQL-Python \u548c lxml \u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\u3002\u901a\u904e\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u914d\u7f6e\u4ed6\u5011\u7684\u958b\u767c\u74b0\u5883\uff0c\u4ee5\u4fbf\u9032\u884c\u66f4\u9ad8\u6548\u7684\u958b\u767c\u5de5\u4f5c\u3002\u82e5\u60a8\u9700\u8981\u66f4\u7a69\u5b9a\u7684\u74b0\u5883\u4f86\u904b\u884c\u60a8\u7684\u61c9\u7528\u7a0b\u5f0f\uff0c\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u670d\u52d9\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u9805\u76ee\u63d0\u4f9b\u66f4\u597d\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 CentOS \u4e2d\u5b78\u7fd2\u5982\u4f55\u5347\u7d1a Python \u53ca\u5b89\u88dd MySQL-Python \u548c lxml\uff0c\u63d0\u5347\u958b\u767c\u6548\u7387\u8207\u6578\u64da\u8655\u7406\u80fd\u529b\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-44268","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44268","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=44268"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44268\/revisions"}],"predecessor-version":[{"id":44269,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44268\/revisions\/44269"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=44268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=44268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=44268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}