{"id":131,"date":"2019-03-04T21:04:07","date_gmt":"2019-03-04T13:04:07","guid":{"rendered":"https:\/\/www.aiqinqin.info\/?p=131"},"modified":"2019-03-27T23:16:13","modified_gmt":"2019-03-27T15:16:13","slug":"centos6-x-7-x%e4%b8%8b%e9%9d%a2%e5%ae%89%e8%a3%85%e7%89%b9%e5%ae%9a%e7%9a%84python%e7%89%88%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/www.aiqinqin.info\/?p=131","title":{"rendered":"Centos6.x\/7.x\u4e0b\u9762\u5b89\u88c5\u7279\u5b9a\u7684python\u7248\u672c"},"content":{"rendered":"<ul>\n<li>\u7531\u4e8eopenssl\u51fa\u73b0\u95ee\u9898\uff0c\u5728\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5python3\u7684\u65f6\u5019\uff0c\u4f1a\u4e00\u76f4\u4e0d\u6210\u529f\uff0c\u6211\u6d4b\u8bd5\u4e86\u51e0\u4e2aopenssl\u7684\u7248\u672c\u6700\u540e\u7f16\u8bd1\u7684\u65f6\u5019\u90fd\u4e0d\u80fd\u901a\u8fc7\uff0c\u6700\u540e\u6839\u636epython3\u7ed9\u51fa\u7684\u63d0\u793a\uff0c\u5b89\u88c5\u4e86LibreSSL\u6765\u4ee3\u66ffopenssl\uff0cLibreSSL\u662f\u5728\u770b\u5230openssl\u6709\u95ee\u9898\u7684\u57fa\u7840\u4e0a\u5f00\u53d1\u51fa\u6765\u7684\u7528\u6765\u66ff\u4ee3openssl\u7684<\/li>\n<\/ul>\n<pre><code class=\"\">#!\/bin\/bash\nWORK_DIR=`mktemp -d`\n\n#some Dependency software\nyum install gcc make wget libffi-devel unzip zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel openssl  -y\nyum install openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel git -y\n\ndownloadPip(){\n    curl https:\/\/bootstrap.pypa.io\/get-pip.py -o get-pip.py\n}\n\ndownloadSetuptools(){\n    wget https:\/\/files.pythonhosted.org\/packages\/b0\/d1\/8acb42f391cba52e35b131e442e80deffbb8d0676b93261d761b1f0ef8fb\/setuptools-40.6.2.zip\n}\n\ninstallLibreSSL(){\n    cd $WORK_DIR &amp;&amp; [ ! -f $WORK_DIR\/libressl-2.8.1.tar.gz ] &amp;&amp; wget https:\/\/ftp.openbsd.org\/pub\/OpenBSD\/LibreSSL\/libressl-2.8.1.tar.gz\n    tar zxvf libressl-2.8.1.tar.gz &amp;&amp; cd libressl-2.8.1\n    .\/configure --prefix=\/opt\/libressl &amp;&amp; make install\n    mv \/usr\/bin\/openssl \/usr\/bin\/openssl.bak \n    mv \/usr\/include\/openssl \/usr\/include\/openssl.bak \n    ln -s \/opt\/libressl\/bin\/openssl \/usr\/bin\/openssl \n    ln -s \/opt\/libressl\/\/include\/openssl \/usr\/include\/openssl\n    echo \"\/opt\/libressl\/lib\" &gt; \/etc\/ld.so.conf.d\/libressl.conf\n    ldconfig \n}\n\ninstallPython2(){\n    #get python2 and install python2\n    cd $WORK_DIR &amp;&amp; [ ! -f $WORK_DIR\/Python-2.7.15.tar.xz ] &amp;&amp; wget https:\/\/www.python.org\/ftp\/python\/2.7.15\/Python-2.7.15.tar.xz\n    xz -d Python-2.7.15.tar.xz &amp;&amp; tar -xvf  Python-2.7.15.tar &amp;&amp; cd Python-2.7.15\n    .\/configure --prefix=\/opt\/python2\n    make  &amp;&amp; make install  &amp;&amp; make clean  &amp;&amp; make distclean\n\n    #install setuptools\n    cd $WORK_DIR &amp;&amp; [ ! -f $WORK_DIR\/setuptools-40.6.2.zip ] &amp;&amp; downloadSetuptools\n    unzip setuptools-40.6.2.zip &amp;&amp; cd setuptools-40.6.2\n    \/opt\/python2\/bin\/python2 .\/setup.py install\n\n    #install pip\n    cd $WORK_DIR &amp;&amp; [ ! -f $WORK_DIR\/get-pip.py ] &amp;&amp; downloadPip\n    \/opt\/python2\/bin\/python2 $WORK_DIR\/get-pip.py\n}\n\ninstallPython3(){\n    installLibreSSL\n    cd $WORK_DIR &amp;&amp; [  ! -f $WORK_DIR\/Python-3.7.1.tar.xz ] &amp;&amp; wget https:\/\/www.python.org\/ftp\/python\/3.7.1\/Python-3.7.1.tar.xz\n    xz -d Python-3.7.1.tar.xz &amp;&amp; tar -xvf  Python-3.7.1.tar &amp;&amp; cd Python-3.7.1\n    export LDFLAGS=\"-L \/opt\/libressl\/lib\"\n    export CPPFLAGS=\"-I \/opt\/libressl\/include\"\n    export PKG_CONFIG_PATH=\"\/opt\/libressl\/lib\/pkgconfig\"\n    .\/configure --prefix=\/opt\/python3 --enable-shared  CFLAGS=-fPIC ##--enable-optimizations \u662f\u4f18\u5316\u9009\u9879(LTO\uff0cPGO \u7b49)\u52a0\u4e0a\u8fd9\u4e2a flag \u7f16\u8bd1\u540e\uff0c\u6027\u80fd\u6709 10% \u5de6\u53f3\u7684\u4f18\u5316,\u4f46\u4f1a\u82b1\u66f4\u591a\u7684\u65f6\u95f4\n    make  &amp;&amp; make install  &amp;&amp; make clean &amp;&amp; make distclean\n    echo \"\/opt\/python3\/lib\" &gt; \/etc\/ld.so.conf.d\/python3.conf\n    ldconfig\n    \/opt\/python3\/bin\/pip3 install --upgrade pip\n}\n\necho -e \"\\033[31m Which python version do you want to install  :  \\033[0m\"\nselect var in \"Python2\" \"Python3\" \"Python2andPython3\" \"Exit\"\ndo\n    case $var in\n        \"Python2\")\n            installPython2\n            exit\n            ;;\n        \"Python3\")\n            installPython3\n            exit\n            ;;\n        \"Python2andPython3\")\n            installPython2\n            installPython3\n            exit\n            ;;\n        \"Exit\")\n            exit\n            ;;\n        *)\n            echo \"Please chose 1 || 2 || 3 || 4\"\n            ;;\n    esac\ndone\n\n#clear\ncd  &amp;&amp; [ -d $WORK_DIR ] &amp;&amp; rm $WORK_DIR -rf\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7531\u4e8eopenssl\u51fa\u73b0\u95ee\u9898\uff0c\u5728\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5python3\u7684\u65f6\u5019\uff0c\u4f1a\u4e00\u76f4\u4e0d\u6210\u529f\uff0c\u6211\u6d4b\u8bd5\u4e86\u51e0\u4e2aopenssl\u7684\u7248\u672c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,8,13,5],"tags":[],"class_list":["post-131","post","type-post","status-publish","format-standard","hentry","category-linux","category-python","category-shell-linux","category-program"],"_links":{"self":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts\/131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=131"}],"version-history":[{"count":4,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=\/wp\/v2\/posts\/131\/revisions\/159"}],"wp:attachment":[{"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aiqinqin.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}