{"id":13,"date":"2014-06-21T14:44:14","date_gmt":"2014-06-21T14:44:14","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=13"},"modified":"2014-06-21T14:44:14","modified_gmt":"2014-06-21T14:44:14","slug":"%e5%9c%a8ubuntu%e4%b8%8a%e5%ae%89%e8%a3%85pyenv","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/13.html","title":{"rendered":"\u5728Ubuntu\u4e0a\u5b89\u88c5pyenv"},"content":{"rendered":"<p>\u56e0\u4e3a\u627e\u5230\u4e00\u4e2a\u57df\u540d\u679a\u4e3e\u7684\u811a\u672c\u4f7f\u7528Python3\u7f16\u5199\u7684\uff0c\u800c\u6211\u4e00\u76f4\u4e60\u60ef\u7684\u662f\u4f7f\u7528Python2.7\uff0c\u5728\u81ea\u5df1\u7684Windows7\u4e0a\u518d\u5b89\u88c5\u4e2aPython\u6015\u6df7\u4e86\uff0c\u4e8e\u662f\u60f3\u7740\u5728VPS\u4e0a\u88c5\u4e2aPython\u7684\u7248\u672c\u7ba1\u7406\u5de5\u5177\uff0c\u4e5f\u65b9\u4fbf\u81ea\u5df1\u4ee5\u540e\u6d4b\u8bd5\uff0c\u60f3\u5230\u4e86pyenv\uff08\u4e4b\u524d\u7684\u662fpythonbrew\u4f46\u662f\u5df2\u7ecf\u4e0d\u5728\u66f4\u65b0\u4e86\uff0c\u90fd\u662f\u540c\u4e00\u4e2a\u4f5c\u8005\uff09\uff0c\u5728GitHub\u4e0a\u7684\u94fe\u63a5\u4e3a\uff1a<a href=\"https:\/\/github.com\/yyuu\/pyenv\">https:\/\/github.com\/yyuu\/pyenv<\/a><\/p>\n<h3>\u5b89\u88c5pyenv\uff1a<\/h3>\n<pre class=\"lang:sh decode:true\">$ cd\n$ git clone git:\/\/github.com\/yyuu\/pyenv.git .pyenv\n\n$ echo 'export PYENV_ROOT=\"$HOME\/.pyenv\"' &gt;&gt; ~\/.bashrc\n$ echo 'export PATH=\"$PYENV_ROOT\/bin:$PATH\"' &gt;&gt; ~\/.bashrc\n\n$ echo 'eval \"$(pyenv init -)\"' &gt;&gt; ~\/.bashrc\n\n$ exec $SHELL<\/pre>\n<h3>\u5b89\u88c5Python\uff1a<\/h3>\n<h4>\u67e5\u770b\u53ef\u5b89\u88c5\u7248\u672c\u5217\u8868\uff1a<\/h4>\n<p>$ pyenv install &#8211;list<\/p>\n<h4>\u5b89\u88c5\u6307\u5b9a\u7248\u672c\uff1a<\/h4>\n<p>$ pyenv install 3.4.1<\/p>\n<p>\u8be5\u547d\u4ee4\u4f1a\u4ecegithub\u4e0a\u4e0b\u8f7dpython\u7684\u6e90\u4ee3\u7801\uff0c\u5e76\u89e3\u538b\u5230\/tmp\u76ee\u5f55\u4e0b\uff0c\u7136\u540e\u5728\/tmp\u4e2d\u6267\u884c\u7f16\u8bd1\u5b89\u88c5\u5de5\u4f5c\u3002\u7f16\u8bd1\u8fc7\u7a0b\u4f9d\u8d56\u4e00\u4e9b\u5176\u4ed6\u7684\u5e93\u6587\u4ef6\uff0c\u82e5\u5e93\u6587\u4ef6\u4e0d\u80fd\u6ee1\u8db3\uff0c\u5219\u7f16\u8bd1\u9519\u8bef\uff0c\u9700\u8981\u91cd\u65b0\u4e0b\u8f7d\u3001\u7f16\u8bd1\u3002\u3002\u3002\uff08\u5e38\u89c1\u7f16\u8bd1\u95ee\u9898\u89e3\u51b3\u65b9\u6cd5\uff1a<a href=\"https:\/\/github.com\/yyuu\/pyenv\/wiki\/Common-build-problems\">https:\/\/github.com\/yyuu\/pyenv\/wiki\/Common-build-problems<\/a>\uff09<\/p>\n<h6>\u5df2\u77e5\u7684\u4e00\u4e9b\u9700\u8981\u9884\u5148\u5b89\u88c5\u7684\u5e93\u5305\u62ec\uff1a<\/h6>\n<ul>\n<li>readline readline-devel readline-static<\/li>\n<li>openssl openssl-devel openssl-static<\/li>\n<li>sqlite-devel<\/li>\n<li>bzip2-devel bzip2-libs<\/li>\n<\/ul>\n<p>\u5728\u6240\u6709python\u4f9d\u8d56\u5e93\u90fd\u5b89\u88c5\u597d\u7684\u60c5\u51b5\u4e0b\uff0cpython\u7684\u5b89\u88c5\u5f88\u987a\u5229\uff08\u6211\u5728\u4e24\u4e2aVPS\u4e0a\u5206\u522b\u88c5\u7684\u65f6\u5019\uff0c\u4e00\u4e2a\u975e\u5e38\u987a\u5229\uff0c\u53e6\u4e00\u4e2a\u5219\u603b\u662f\u51fa\u95ee\u9898\uff09\u3002<\/p>\n<h4>\u66f4\u65b0\u6570\u636e\u5e93<\/h4>\n<p>\u5b89\u88c5\u5b8c\u6210\u4e4b\u540e\u9700\u8981\u5bf9\u6570\u636e\u5e93\u8fdb\u884c\u66f4\u65b0\uff1a<br \/>\n$ pyenv rehash<\/p>\n<p>\u67e5\u770b\u5f53\u524d\u5df2\u5b89\u88c5\u7684python\u7248\u672c<br \/>\n$ pyenv versions<br \/>\n* system (set by \/export\/root\/.pyenv\/version)<br \/>\n3.4.1<br \/>\n\u5176\u4e2d\u7684\u661f\u53f7\u8868\u793a\u4f7f\u7528\u7684\u662f\u7cfb\u7edf\u81ea\u5e26\u7684python\u3002<\/p>\n<h4>\u8bbe\u7f6e\u5168\u5c40\u7684python\u7248\u672c<\/h4>\n<p>$ pyenv global 3.4.1<br \/>\n$ pyenv versions<br \/>\nsystem<br \/>\n* 3.4.1 (set by \/export\/root\/.pyenv\/version)<br \/>\n\u5f53\u524d\u5168\u5c40\u7684python\u7248\u672c\u5df2\u7ecf\u53d8\u6210\u4e863.4.1\u3002\u4e5f\u53ef\u4ee5\u4f7f\u7528pyenv local\u6216pyenv shell\u4e34\u65f6\u6539\u53d8python\u7248\u672c\uff08\u91cd\u65b0\u767b\u5f55\u540e\u5931\u6548\uff09\u3002<\/p>\n<h6>\u786e\u8ba4python\u7248\u672c\uff1a<\/h6>\n<p>$ python<br \/>\nPython 2.7.3 (default, Feb 27 2014, 20:00:17)<br \/>\n[GCC 4.6.3] on linux2<br \/>\nType &#8220;help&#8221;, &#8220;copyright&#8221;, &#8220;credits&#8221; or &#8220;license&#8221; for more information.<br \/>\n&gt;&gt;&gt;<\/p>\n<h6>\u4f7f\u7528python\uff1a<\/h6>\n<p>\u8f93\u5165python\u5373\u53ef\u4f7f\u7528\u65b0\u7248\u672c\u7684python\uff1b<br \/>\n\u7cfb\u7edf\u547d\u4ee4\u4f1a\u4ee5\/usr\/bin\/python\u7684\u65b9\u5f0f\u76f4\u63a5\u8c03\u7528\u8001\u7248\u672c\u7684python\uff1b<br \/>\n\u4f7f\u7528pip\u5b89\u88c5\u7b2c\u4e09\u65b9\u6a21\u5757\u65f6\u4f1a\u5b89\u88c5\u5230~\/.pyenv\/versions\/3.4.1\u4e0b\uff0c\u4e0d\u4f1a\u548c\u7cfb\u7edf\u6a21\u5757\u53d1\u751f\u51b2\u7a81\u3002<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<h6>\u53c2\u8003\u6587\u7ae0\uff1a<\/h6>\n<p><a href=\"https:\/\/github.com\/yyuu\/pyenv#installation\">https:\/\/github.com\/yyuu\/pyenv#installation<\/a><\/p>\n<p><a href=\"http:\/\/seisman.info\/python-pyenv.html\">http:\/\/seisman.info\/python-pyenv.html<\/a><\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<h5>\u9644\u4e0a\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u7684\u4e00\u4e9b\u95ee\u9898\u53ca\u5176\u89e3\u51b3\u65b9\u6cd5\uff1a<\/h5>\n<p>$ pyenv install 3.4.1 #\u8fd9\u91cc\u9009\u62e9\u76ee\u524d\u4e3a\u6b62\u6700\u65b0\u7684Python3.4.1<\/p>\n<p>\u2026\u2026<\/p>\n<p>checking whether the C compiler works&#8230; no<br \/>\nconfigure: error: in `\/tmp\/python-build.20140621173243.14345\/Python-3.4.1&#8242;:<br \/>\nconfigure: error: C compiler cannot create executables<\/p>\n<pre class=\"lang:sh decode:true\"># apt-get install libc6-dev gcc<\/pre>\n<p>\u7136\u540e\u518d\u6267\u884c\uff1a<\/p>\n<pre class=\"lang:sh decode:true\"># pyenv install 3.4.1\nDownloading Python-3.4.1.tgz...\n-&gt; http:\/\/yyuu.github.io\/pythons\/8d007e3ef80b128a292be101201e75dec5480e5632e994771e7c231d17720b66\nInstalling Python-3.4.1...\nWARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?\nERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?\n\nPlease consult to the Wiki page to fix the problem.\nhttps:\/\/github.com\/yyuu\/pyenv\/wiki\/Common-build-problems\n\n\nBUILD FAILED\n\nInspect or clean up the working tree at \/tmp\/python-build.20140621173821.18496\nResults logged to \/tmp\/python-build.20140621173821.18496.log\n\nLast 10 log lines:\n(cd \/root\/.pyenv\/versions\/3.4.1\/share\/man\/man1; ln -s python3.4.1 python3.1)\nif test \"xupgrade\" != \"xno\" ; then\ncase upgrade in\nupgrade) ensurepip=\"--upgrade\" ;;\ninstall|*) ensurepip=\"\" ;;\nesac;\n.\/python -E -m ensurepip\n$ensurepip --root=\/ ;\nfi\nIgnoring ensurepip failure: pip 1.5.6 requires SSL\/TLS<\/pre>\n<p>\u5b89\u88c5bzip2\u548cOpenSSL\u5e93\u4f9d\u8d56\uff08\u56e0\u4e3aPython3.4.1\u8fd9\u4e2a\u7248\u672c\u4fee\u590d\u4e86\u4e4b\u524d\u7684Heart Bleed\u90a3\u4e2a\u6f0f\u6d1e\uff0c\u6240\u4ee5OpenSSL\u7684\u7248\u672c\u548c\u4e4b\u524d\u7684\u7248\u672c\u4e0d\u540c\uff0c\u9700\u8981\u91cd\u65b0\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684OpenSSL\uff0c\u8fd9\u662f\u6211\u4f30\u8ba1\u7684\uff0c\u56e0\u4e3a\u5728Python\u7684\u5b98\u65b9\u4e3b\u9875\u4e0a\u9762\u770b\u5230Python3.4.1\u8fd9\u4e2a\u7248\u672c\u4fee\u590d\u4e86HeartBleed\u6f0f\u6d1e\uff09<\/p>\n<p>\u8bd5\u8bd5\u518d\u8fd0\u884c\u4e00\u904d\u57fa\u7840\u5e93\u4f9d\u8d56\u7684\u5b89\u88c5\u547d\u4ee4\uff1a<\/p>\n<pre class=\"lang:sh decode:true\"># apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm<\/pre>\n<p>\u518d\u6267\u884c\u5b89\u88c5\u547d\u4ee4\uff0c\u679c\u7136\u5c31\u6ca1\u95ee\u9898\u4e86\uff1a<\/p>\n<pre class=\"lang:sh decode:true\"># pyenv install 3.4.1\nDownloading Python-3.4.1.tgz...\n-&gt; http:\/\/yyuu.github.io\/pythons\/8d007e3ef80b128a292be101201e75dec5480e5632e994771e7c231d17720b66\nInstalling Python-3.4.1...\nInstalled Python-3.4.1 to \/root\/.pyenv\/versions\/3.4.1<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u56e0\u4e3a\u627e\u5230\u4e00\u4e2a\u57df\u540d\u679a\u4e3e\u7684\u811a\u672c\u4f7f\u7528Python3\u7f16\u5199\u7684\uff0c\u800c\u6211\u4e00\u76f4\u4e60\u60ef\u7684\u662f\u4f7f\u7528Python2.7\uff0c\u5728\u81ea\u5df1\u7684Windo [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,12],"tags":[39],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-linux","category-tools","tag-ubuntu-python"],"views":3237,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}