{"id":265,"date":"2016-08-04T09:36:19","date_gmt":"2016-08-04T01:36:19","guid":{"rendered":"http:\/\/yyshell.com\/?p=265"},"modified":"2018-07-21T10:02:36","modified_gmt":"2018-07-21T02:02:36","slug":"centos6%e5%ae%89%e8%a3%85python2-7%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/yyshell.com\/?p=265","title":{"rendered":"centos6\u5b89\u88c5python2.7\u6559\u7a0b"},"content":{"rendered":"<p>\u622a\u6b62\u76ee\u524d\uff0ccentos6\u7cfb\u5217\u7684\u6700\u65b0\u7248\u672c\u662fcentos6.9\uff0c\u5185\u7f6e\u7684python\u7248\u672c\u4f9d\u7136\u662f2.6.6\uff0c\u51fa\u4e8eapi\u548cabi\u7684\u7a33\u5b9a\u6027\u8003\u8651\uff0credhat\u662f\u4e0d\u4f1a\u81ea\u5df1\u5347\u7ea7python\u7248\u672c\u7684\uff0c\u4f46\u662f\uff0c\u5f88\u591a\u65f6\u5019\u6211\u4eec\u975e\u5e38\u9700\u8981\u4f7f\u7528\u8f83\u65b0\u7684\u7248\u672c\uff0c\u7531\u4e8epython\u662f\u7cfb\u7edf\u9ed8\u8ba4\u96c6\u6210\u7684\uff0c\u5373\u4f7f\u662f\u6700\u5c0f\u5316\u5b89\u88c5\u7684\u7cfb\u7edf\uff0c\u9ed8\u8ba4\u5df2\u7ecf\u81ea\u5e26\u4e86python\uff0c\u5982\u679c\u81ea\u5df1\u5b89\u88c5\u4e0d\u5f53\uff0c\u5f88\u53ef\u80fd\u5bf9\u7cfb\u7edf\u9020\u6210\u7834\u574f\u3002\u672c\u6587\u4e3b\u8981\u5c31\u662f\u5728centos6.9\u4e0a\u9762\u5b89\u88c5Python2.7.15\u7248\u672c\u8fdb\u884c\u8bf4\u660e\uff0c\u5982\u679c\u4f60\u8981\u5b89\u88c5Python3.x\u7cfb\u5217\uff0c\u7406\u8bba\u4e0a\u5e94\u8be5\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>\u9996\u5148\u662f\u73af\u5883\u51c6\u5907\uff1a<\/p>\n<pre class=\"lang:default decode:true\">yum install gcc zlib-devel expat-devel bzip2-devel sqlite-devel \\\r\nopenssl-devel readline-devel gdbm-devel ncurses-devel xz-devel tk-devel<\/pre>\n<p>\u6ce8\u610f\uff0c\u524d\u9762\u51e0\u4e2a\u5305\u90fd\u662fPython\u7f16\u8bd1\u5b89\u88c5\u9700\u8981\u7684\uff0c\u6709\u4e9b\u7ec4\u4ef6\uff0cdb4-devel\u53ef\u4ee5\u9009\u88c5\u3002<\/p>\n<p>\u4e0b\u8f7dpython:<\/p>\n<pre class=\"lang:sh decode:true\">curl -L -O  https:\/\/www.python.org\/ftp\/python\/2.7.15\/Python-2.7.15.tar.xz<\/pre>\n<p>\u89e3\u538b\u5b89\u88c5\uff1a<\/p>\n<pre class=\"lang:default decode:true\">tar xf Python-2.7.15.tar.xz\r\ncd Python-2.7.15\r\n\r\n.\/configure --enable-ipv6 --enable-shared \\\r\nLDFLAGS=\"-Wl,-rpath \/usr\/local\/lib\" \\\r\n--with-system-expat --with-system-ffi \\\r\n--enable-unicode=ucs4 \\\r\n--with-ensurepip=install\r\n\r\nmake -j${nproc}\r\nmake altinstall<\/pre>\n<p>\u5982\u679c\u8981\u5728\u6807\u51c6\u76ee\u5f55\u4e0b\u5b89\u88c5\uff0c\u53ef\u4ee5\u8fd9\u6837<\/p>\n<pre class=\"lang:sh decode:true \">cd Python-2.7.15\r\ncurl -L -O https:\/\/src.fedoraproject.org\/rpms\/python2\/raw\/master\/f\/00102-2.7.13-lib64.patch\r\ncurl -L -O https:\/\/src.fedoraproject.org\/rpms\/python2\/raw\/master\/f\/python-2.7-lib64-sysconfig.patch\r\ncurl -L -O https:\/\/src.fedoraproject.org\/rpms\/python2\/raw\/master\/f\/00104-lib64-fix-for-test_install.patch\r\npatch -p1 &lt; 00102-2.7.13-lib64.patch\r\npatch -p1 &lt; python-2.7-lib64-sysconfig.patch\r\npatch -p1 &lt; 00104-lib64-fix-for-test_install.patch<\/pre>\n<p>\u914d\u7f6e\u53ef\u4ee5\u8fd9\u6837\u914d\u7f6e\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">.\/configure --prefix=\/usr --sysconfdir=\/etc --libdir=\/usr\/lib64 --localstatedir=\/var --sharedstatedir=\/var\/lib \\\r\n--enable-ipv6 --enable-shared --enable-unicode=ucs4 --with-system-expat --with-system-ffi \\\r\n--enable-optimizations LDFLAGS='-Wl,-z,relro -Wl,-z,now' --with-ensurepip=install\r\n\r\nmake -j4\r\nmake altinstall<\/pre>\n<p>\u5982\u679c\u4f60\u7528\u66f4\u9ad8\u7248\u672c\u7684gcc\uff0cconfigure\u7684\u65f6\u5019\u53ef\u4ee5\u52a0\u4e0a\u4f18\u5316\u9009\u9879<\/p>\n<pre class=\"lang:sh decode:true \">.\/configure --with-ensurepip=install --enable-optimizations<\/pre>\n<p>\u5728centos6\u81ea\u5e26\u7684\u4f4e\u7248\u672cgcc(4.4.7)\u4e0b\uff0c\u4f18\u5316\u9009\u9879\u597d\u591a\u7279\u6027\u4e0d\u652f\u6301\uff0c\u6240\u4ee5\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\u6700\u540e\u7684\u63d0\u793a\u5e94\u8be5\u662f\u7c7b\u4f3c\u8fd9\u6837\u7684\uff1a<\/p>\n<blockquote><p>Collecting setuptools<br \/>\nCollecting pip<br \/>\nInstalling collected packages: setuptools, pip<br \/>\nSuccessfully installed pip-9.0.3 setuptools-39.0.1<\/p><\/blockquote>\n<p>\u7a0d\u5fae\u89e3\u91ca\u4e0b\u914d\u7f6e\uff0c&#8211;with-ensurepip=install\u662f\u540c\u6b65\u5b89\u88c5pip\u548ceasy_install\uff0c\u73b0\u5728\u7684python\u6e90\u7801\u81ea\u5e26\u6b64\u529f\u80fd\uff0c\u52a0\u4e2a\u53c2\u6570\u5c31\u80fd\u5f00\u542f\u4e86\u3002\u9ed8\u8ba4\u7684\u5b89\u88c5\u8def\u5f84\u662f\/usr\/local, \u8fd9\u91cc\u4e5f\u6ca1\u6709\u53d8\u66f4\u3002\u6700\u540e\u4e0d\u7528make install\u662f\u6015\u66ff\u6362\u7cfb\u7edf\u5df2\u6709\u7684\u7ec4\u4ef6\uff0c\u6240\u4ee5\u7528make altinstall\u3002\u6211\u4eec\u7684\u4e3b\u7a0b\u5e8f\u662fpython2.7\u548cpip2.7\u3002<\/p>\n<p>\u6211\u4eec\u67e5\u770b\u4e0b\u7248\u672c\uff1a<\/p>\n<p>python2.7 -V<\/p>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<p>Python 2.7.15<\/p>\n<p>\u6709\u65f6\uff0c\u6211\u4eec\u4e0d\u60f3\u7528python2.7\u6765\u6267\u884c\uff0c\u60f3\u76f4\u63a5\u7528python\u547d\u4ee4\u6267\u884c\u65b0\u7248\u672c\u7684python\uff0c\u6211\u4eec\u53ef\u4ee5\u505a\u4e2a\u8f6f\u8fde\u63a5\u3002<\/p>\n<pre class=\"lang:default decode:true \">ln -sf \/usr\/local\/bin\/python2.7 \/usr\/bin\/python<\/pre>\n<p>\u8fd9\u91cc\u4f1a\u628a\u8001\u76842.6\u7684python\u6267\u884c\u7a0b\u5e8f\u66ff\u6362\u6389\uff0c\u4f46\u4e0d\u7528\u62c5\u5fc3\uff0c\/usr\/bin\/python2.6\u8fd9\u4e2a\u7a0b\u5e8f\u5176\u5b9e\u662f\u4e2a\u786c\u8fde\u63a5\u6587\u4ef6\uff0c2.6\u7684\u6267\u884c\u7a0b\u5e8f\u8fd8\u5728\u7684\u3002<\/p>\n<p>\u56e0yum\u53ea\u80fd\u5728python2.6\u4e0b\u8fd0\u884c\uff0c\u6211\u4eec\u628ayum\u811a\u672c\u6539\u4e0b\u73af\u5883\uff1a<\/p>\n<pre class=\"lang:default decode:true \">vim \/usr\/bin\/yum<\/pre>\n<p>\u628a\u6587\u4ef6\u5f00\u59cb\u7684#!\/usr\/bin\/python\u6539\u6210#!\/usr\/bin\/python2.6\u5373\u53ef\u3002<\/p>\n<p>\u518d\u628apip\u7684\u8f6f\u8fde\u63a5\u505a\u4e0b\uff1a<\/p>\n<pre class=\"lang:default decode:true \">ln -s \/usr\/local\/bin\/pip2.7 \/usr\/bin\/pip<\/pre>\n<p>\u597d\u4e86\uff0c\u5927\u529f\u544a\u6210\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6211\u4eec\u5df2\u7ecf\u628a\u4e3b\u6267\u884c\u7a0b\u5e8f\u6539\u6210\u4e86python2.7\uff0c\u9664\u4e86yum\u9700\u8981\u6539\u73af\u5883\u5916\uff0c\u4e0d\u6392\u9664\u5176\u4ed6\u7684python\u811a\u672c\u51fa\u95ee\u9898\uff0c\u6240\u4ee5\u8981\u4e0d\u8981\u5bf9python2.7\u505a\u8f6f\u8fde\u63a5\u8fd8\u662f\u53d6\u51b3\u4e8e\u4f60\uff0c\u4f46\u8fd9\u4e2a\u597d\u5904\u662f\u5982\u679c\u6211\u4eec\u60f3\u5207\u6362\u56de\u6765\uff0c\u7cfb\u7edf\u539f\u5148\u76842.6\u7684python\u5176\u5b9e\u90fd\u8fd8\u5728\uff0c\u53ef\u4ee5\u968f\u65f6\u6062\u590d\u56de\u53bb\u3002<\/p>\n<p>\u66f4\u597d\u7684\u5efa\u8bae\u662f\uff0c\u6211\u63a8\u8350\u5b89\u88c5scl\u7684\u6e90\u5b89\u88c5python\uff0c\u8fd9\u4e2a\u539f\u7406\u6709\u70b9\u50cfpython\u4e2d\u7684\u865a\u62df\u73af\u5883\uff0c\u4e00\u70b9\u4e5f\u4e0d\u5f71\u54cd\u7cfb\u7edf\u539f\u5148\u7684\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u968f\u65f6\u5207\u6362\uff0c\u5927\u5bb6\u53ef\u4ee5\u770b\u4e0b\u6211\u4ee5\u524d\u7684<a href=\"http:\/\/yyshell.com\/?p=257\">\u8fd9\u7bc7\u6587\u7ae0<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u622a\u6b62\u76ee\u524d\uff0ccentos6\u7cfb\u5217\u7684\u6700\u65b0\u7248\u672c\u662fcentos6.9\uff0c\u5185\u7f6e\u7684python\u7248<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,1],"tags":[77,61],"class_list":["post-265","post","type-post","status-publish","format-standard","hentry","category-linux","category-uncategorized","tag-gcc","tag-python"],"_links":{"self":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts\/265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=265"}],"version-history":[{"count":12,"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts\/265\/revisions"}],"predecessor-version":[{"id":511,"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts\/265\/revisions\/511"}],"wp:attachment":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}