{"id":194,"date":"2017-10-31T20:10:09","date_gmt":"2017-10-31T12:10:09","guid":{"rendered":"https:\/\/chenbing.name\/?p=194"},"modified":"2020-05-22T15:03:03","modified_gmt":"2020-05-22T07:03:03","slug":"linux%e5%ae%89%e8%a3%85python-%e5%a4%9a%e7%89%88%e6%9c%ac%e5%85%b1%e5%ad%98pyenv%e5%8f%8apyenv-virtualenv%e6%8f%92%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/chenbing.name\/blog\/194\/","title":{"rendered":"linux\u5b89\u88c5Python \u591a\u7248\u672c\u5171\u5b58pyenv\u53capyenv-virtualenv\u63d2\u4ef6"},"content":{"rendered":"<div id=\"MathJax_Message\" style=\"display: none;\"><\/div>\n<h2 id=\"\u5b89\u88c5\"><span class=\"ez-toc-section\" id=\"%E5%AE%89%E8%A3%85\"><\/span>\u5b89\u88c5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3 id=\"1. \u5b89\u88c5\u4f9d\u8d56\u5305\"><span class=\"ez-toc-section\" id=\"1_%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96%E5%8C%85\"><\/span>1. \u5b89\u88c5\u4f9d\u8d56\u5305<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>ubuntu16<\/p>\n<div>\n<pre><code>sudo apt-get install curl git-core gcc make build-essential libssl-dev zlib1g-dev libbz2-dev \\\nlibreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \\\nxz-utils tk-dev libmysqlclient-dev<\/code><\/pre>\n<\/div>\n<p>centos7<\/p>\n<div>\n<pre><code>yum -y install git gcc make patch zlib-devel gdbm-devel openssl-devel sqlite-devel bzip2-devel readline-devel<\/code><\/pre>\n<\/div>\n<h3 id=\"2.\u5b89\u88c5pyenv###\"><span class=\"ez-toc-section\" id=\"2%E5%AE%89%E8%A3%85pyenv\"><\/span>2.\u5b89\u88c5pyenv###<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u5b89\u88c5\uff08\u4e0b\u9762\u4e00\u6761\u547d\u4ee4\u53ef\u4ee5\u628apyenv\u548cpyenv-virtualenv\u63d2\u4ef6\u90fd\u88c5\u4e0a\uff09\uff1a<\/p>\n<div>\n<pre><code>curl -L https:\/\/raw.githubusercontent.com\/yyuu\/pyenv-installer\/master\/bin\/pyenv-installer | bash<\/code><\/pre>\n<\/div>\n<p>\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<div>\n<pre><code>echo 'export PATH=\"$HOME\/.pyenv\/bin:$PATH\"' &gt;&gt; ~\/.bashrc\necho 'eval \"$(pyenv init -)\"' &gt;&gt; ~\/.bashrc\necho 'eval \"$(pyenv virtualenv-init -)\"' &gt;&gt; ~\/.bashrc\nsource ~\/.bashrc<\/code><\/pre>\n<\/div>\n<h3 id=\"\u56fd\u5185\u52a0\u901f\u4e0b\u8f7d\u5b89\u88c5python\"><span class=\"ez-toc-section\" id=\"%E5%9B%BD%E5%86%85%E5%8A%A0%E9%80%9F%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85python\"><\/span>\u56fd\u5185\u52a0\u901f\u4e0b\u8f7d\u5b89\u88c5python<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u641c\u72d0\u955c\u50cf\u6e90\u52a0\u901f\uff1a<a href=\"http:\/\/mirrors.sohu.com\/python\/\">http:\/\/mirrors.sohu.com\/python\/<\/a> <br \/>\n\u4e0b\u8f7d\u9700\u8981\u7684\u7248\u672c\u653e\u5230~\/.pyenv\/cache\u6587\u4ef6\u5939\u4e0b\u9762 <br \/>\n\u7136\u540e\u6267\u884c pyenv install \u7248\u672c\u53f7  \u5b89\u88c5\u5bf9\u5e94\u7684python\u7248\u672c<\/p>\n<div>\n<pre><code>wget http:\/\/mirrors.sohu.com\/python\/3.6.3\/Python-3.6.3.tar.xz -P ~\/.pyenv\/cache\/\npyenv install 3.6.3<\/code><\/pre>\n<\/div>\n<h3 id=\"pip \u914d\u7f6e\u4f7f\u7528\u56fd\u5185\u955c\u50cf\"><span class=\"ez-toc-section\" id=\"pip_%E9%85%8D%E7%BD%AE%E4%BD%BF%E7%94%A8%E5%9B%BD%E5%86%85%E9%95%9C%E5%83%8F\"><\/span>pip \u914d\u7f6e\u4f7f\u7528\u56fd\u5185\u955c\u50cf<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u521b\u5efa\u76ee\u5f55 mkdir ~\/.pip <br \/>\n\u7f16\u8f91 ~\/.pip\/pip.conf, \u8f93\u5165\u4e00\u4e0b\u5185\u5bb9<\/p>\n<div>\n<pre><code>[global]\nindex-url = http:\/\/mirrors.aliyun.com\/pypi\/simple\/\ntrusted-host = mirrors.aliyun.com<\/code><\/pre>\n<\/div>\n<h4 id=\"\u6ce8\u610f\"><span class=\"ez-toc-section\" id=\"%E6%B3%A8%E6%84%8F\"><\/span>\u6ce8\u610f<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u5347\u7ea7\uff1a\u53ef\u4ee5\u7528\u547d\u4ee4pyenv update <br \/>\n\u5378\u8f7d\uff1a\u76f4\u63a5\u5220\u9664\u76ee\u5f55rm -rf ~\/.pyenv\uff0c\u7136\u540e\u628a~\/.bash_profile\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u4e2d\u7684\u4e09\u884c\u5220\u6389<\/p>\n<p>\u9700\u8981\u4f7f\u73af\u5883\u53d8\u91cf\u751f\u6548\uff0c <br \/>\n\u8fd0\u884c\u547d\u4ee4exec &#8220;$SHELL&#8221;\uff0c\u5982\u679c\u8fd8\u6ca1\u6709\u6548\u679c\uff0c\u5c31\u9000\u51fa\u7ec8\u7aef\uff0c\u91cd\u65b0\u6253\u5f00\u3002<\/p>\n<h2 id=\"\u4f7f\u7528\"><span class=\"ez-toc-section\" id=\"%E4%BD%BF%E7%94%A8\"><\/span>\u4f7f\u7528<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3 id=\"1. pyenv\u4f7f\u7528\u6307\u5357\uff08OS X\u548cLinux\u547d\u4ee4\u901a\u7528\uff09\"><span class=\"ez-toc-section\" id=\"1_pyenv%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97%EF%BC%88OS_X%E5%92%8CLinux%E5%91%BD%E4%BB%A4%E9%80%9A%E7%94%A8%EF%BC%89\"><\/span>1. pyenv\u4f7f\u7528\u6307\u5357\uff08OS X\u548cLinux\u547d\u4ee4\u901a\u7528\uff09<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4 id=\"\u5217\u51fa\u53ef\u5b89\u88c5\u7248\u672c\"><span class=\"ez-toc-section\" id=\"%E5%88%97%E5%87%BA%E5%8F%AF%E5%AE%89%E8%A3%85%E7%89%88%E6%9C%AC\"><\/span>\u5217\u51fa\u53ef\u5b89\u88c5\u7248\u672c<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u9996\u5148\u6211\u4eec\u53ef\u4ee5\u67e5\u770b\u4e00\u4e0b\u6709\u54ea\u4e9b\u7248\u672c\u7684python \u53ef\u4ee5\u5b89\u88c5<\/p>\n<div>\n<pre><code>pyenv install --list<\/code><\/pre>\n<\/div>\n<h4 id=\"\u67e5\u770b\u5b89\u88c5\u7684python\u7248\u672c\"><span class=\"ez-toc-section\" id=\"%E6%9F%A5%E7%9C%8B%E5%AE%89%E8%A3%85%E7%9A%84python%E7%89%88%E6%9C%AC\"><\/span>\u67e5\u770b\u5b89\u88c5\u7684python\u7248\u672c<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>pyenv versions\u67e5\u770b\u7cfb\u7edf\u7684\u4e0a\u5b89\u88c5\u7684Python\u7248\u672c\u3002 \u5176\u4e2d\u524d\u9762\u7684*\u8868\u793a\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u6b63\u5728\u4f7f\u7528\u7684\u7248\u672c,\u5176\u4e2d \u7684 system\u8868\u793a\u7cfb\u7edf\u81ea\u5e26\u7684 Python \u7248\u672c\uff1a<\/p>\n<div>\n<pre><code>$ pyenv versions\n*system (set by \/Users\/yulongjun\/.pyenv\/version)<\/code><\/pre>\n<\/div>\n<h4 id=\"\u5b89\u88c5\u5176\u4ed6\u7248\u672c\"><span class=\"ez-toc-section\" id=\"%E5%AE%89%E8%A3%85%E5%85%B6%E4%BB%96%E7%89%88%E6%9C%AC\"><\/span>\u5b89\u88c5\u5176\u4ed6\u7248\u672c<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>pyenv install <version>\u5b89\u88c5\u5176\u4ed6\u7248\u672c\u7684Python\u3002\u4f8b\u5982\u5b89\u88c53.5.1\u548c3.4.4\u7248\u672c\uff1a<\/version><\/p>\n<div>\n<pre><code>$ pyenv install 3.5.1\n$ pyenv install 3.4.4\n$ pyenv versions #\u53ef\u4ee5\u770b\u52303\u4e2a\u7248\u672c\n*system (set by \/Users\/yulongjun\/.pyenv\/version)\n 3.4.4\n3.5.1<\/code><\/pre>\n<\/div>\n<h4 id=\"\u8bbe\u7f6e\u5168\u5c40\u7684 python \u7248\u672c\"><span class=\"ez-toc-section\" id=\"%E8%AE%BE%E7%BD%AE%E5%85%A8%E5%B1%80%E7%9A%84_python_%E7%89%88%E6%9C%AC\"><\/span>\u8bbe\u7f6e\u5168\u5c40\u7684 python \u7248\u672c<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<div>\n<pre><code>$ pyenv global anaconda3-4.1.0\n$ pyenv versions\nsystem\n* anaconda3-4.1.0 (set by \/home\/seisman\/.pyenv\/version)<\/code><\/pre>\n<\/div>\n<h4 id=\"\u672c\u5730\u6587\u4ef6\u5939\u8bbe\u7f6epython\u7248\u672c\"><span class=\"ez-toc-section\" id=\"%E6%9C%AC%E5%9C%B0%E6%96%87%E4%BB%B6%E5%A4%B9%E8%AE%BE%E7%BD%AEpython%E7%89%88%E6%9C%AC\"><\/span>\u672c\u5730\u6587\u4ef6\u5939\u8bbe\u7f6epython\u7248\u672c<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u4f7f\u7528 <code>pyenv local &lt;version&gt;<\/code> \u8bbe\u7f6e\u5f53\u524d\u6587\u4ef6\u5939python\u7248\u672c\u3002 <br \/>\n\u793a\u4f8b\uff1a\u521b\u5efa3.5<\/p>\n<div>\n<pre><code>$ cd                   #\u5230\u5bb6\u76ee\u5f55\n$ mkdir python35      #\u521b\u5efapython35\u7684\u5de5\u4f5c\u76ee\u5f55\n$ cd python35\n$ pyenv local 3.5.1    #\u4f7f\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u4f7f\u7528python3.5.1\u7248\u672c\n$ python -V            #\u67e5\u770b\u4e00\u4e0b\u5f53\u524d\u76ee\u5f55\u7528python\u7684\u7248\u672c\uff0c\u786e\u5b9e\u662f3.5.1\nPython3.5.1\n$ pip -V               #\u67e5\u770b\u4e00\u4e0bpip\u7248\u672c,\u662f3.5\u7684pip\npip 7.1.2 from \/usr\/local\/var\/pyenv\/versions\/3.5.1\/lib\/python3.5\/site-packages (python 3.5)<\/code><\/pre>\n<\/div>\n<p>\u793a\u4f8b\uff1a\u521b\u5efa3.4<\/p>\n<div>\n<pre><code>$ cd                   #\u56de\u5230\u5bb6\u76ee\u5f55\n$ mkdir python34     #\u521b\u5efapython3.4\u7684\u5de5\u4f5c\u76ee\u5f55\n$ cd python34\n$ pyenv local 3.4      #\u4f7f\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u4f7f\u7528python3.4.4\u7248\u672c\n$ python -V            #\u67e5\u770b\u4e00\u4e0b\u5f53\u524d\u76ee\u5f55\u7528python\u7684\u7248\u672c\uff0c\u786e\u5b9e\u662f3.5.1\nPython 3.4.4\n$ pip -V               #\u67e5\u770b\u4e00\u4e0bpip\u7248\u672c\uff0c\u662f3.4\u7684pip\npip 7.1.2 from \/usr\/local\/var\/pyenv\/versions\/3.4.4\/lib\/python3.4\/site-packages (python 3.4)<\/code><\/pre>\n<\/div>\n<p>\u5176\u4ed6\u7248\u672c\u7684\u5de5\u4f5c\u76ee\u5f55\u521b\u5efa\u65b9\u6cd5\u7c7b\u4f3c\u3002<\/p>\n<p>\u5982\u679c\u662f\u7528\u7cfb\u7edf\u81ea\u5e26\u7248\u672c\uff0c\u7528<code>pyenv local system<\/code>\u5373\u53ef\u4f7f\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u4f7f\u7528\u7cfb\u7edf\u81ea\u5e26\u7684Pytho\u7248\u672c<\/p>\n<h4 id=\"pyenv \u5176\u4ed6\u529f\u80fd\"><span class=\"ez-toc-section\" id=\"pyenv_%E5%85%B6%E4%BB%96%E5%8A%9F%E8%83%BD\"><\/span>pyenv \u5176\u4ed6\u529f\u80fd<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>pyenv uninstall \u5378\u8f7d\u67d0\u4e2a\u7248\u672c <br \/>\npyenv update \u66f4\u65b0 pyenv \u53ca\u5176\u63d2\u4ef6<\/p>\n<h3 id=\"2. pyenv-virtualenv\u4f7f\u7528\u6307\u5357\"><span class=\"ez-toc-section\" id=\"2_pyenv-virtualenv%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97\"><\/span>2. pyenv-virtualenv\u4f7f\u7528\u6307\u5357<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>pyenv-virtualenv\u662f\u7528\u6765\u521b\u5efa\u4e00\u4e2a\u5e72\u51c0\u7684\u865a\u62dfPython\u73af\u5883\u7684\u547d\u4ee4\uff0c\u901a\u5e38\u5728\u521b\u5efa\u5e72\u51c0\u7684\u65b0\u9879\u76ee\u65f6\u5019\u4f7f\u7528\u3002\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b:<\/p>\n<h4 id=\"\u521b\u5efa\u865a\u62df\u73af\u5883 pyenv virtualenv \u7248\u672c\u53f7 \u865a\u62df\u73af\u5883\u540d\u3002\"><span class=\"ez-toc-section\" id=\"%E5%88%9B%E5%BB%BA%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83_pyenv_virtualenv_%E7%89%88%E6%9C%AC%E5%8F%B7_%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83%E5%90%8D%E3%80%82\"><\/span>\u521b\u5efa\u865a\u62df\u73af\u5883 pyenv virtualenv \u7248\u672c\u53f7 \u865a\u62df\u73af\u5883\u540d\u3002<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<div>\n<pre><code>$ pyenv virtualenv 3.5.1 venv-3.5.1<\/code><\/pre>\n<\/div>\n<h4 id=\"\u4f7f\u7528\u865a\u62df\u73af\u5883\"><span class=\"ez-toc-section\" id=\"%E4%BD%BF%E7%94%A8%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83\"><\/span>\u4f7f\u7528\u865a\u62df\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u521b\u5efa\u9879\u76ee\uff0c\u8ba9\u9879\u76ee\u4f7f\u7528\u5e72\u51c0\u7684Python3.5.1\u7684\u865a\u62df\u73af\u5883\uff1a<\/p>\n<div>\n<pre><code>$ mkdir myproject\n$ cd myproject\n$ pyenv local venv-3.5.1\n\npyenv-virtualenv: deactivate\npyenv-virtualenv: activate venv-3.5.1<\/code><\/pre>\n<\/div>\n<p>\u6b64\u540e\uff0c\u6211\u4eec\u5c31\u4f1a\u53d1\u73b0\uff1a\u53ea\u8981\u6211\u4eec\u8fdb\u5165myproject\u76ee\u5f55\uff0c\u5c31\u4f1a\u81ea\u52a8\u6fc0\u6d3bvirtualenv\uff0c\u9000\u51famyproject\u76ee\u5f55\uff0c\u5c31\u4f1a\u5173\u95edvirtualenv\u3002<\/p>\n<p>\u5982\u679c\u8981\u5173\u95ed\u81ea\u52a8\u6fc0\u6d3b\uff0c\u53ef\u4ee5\u8fd0\u884c\u547d\u4ee4pyenv deactivate\uff0c\u8981\u91cd\u65b0\u542f\u7528\u7684\u8bdd\uff0c\u8fd0\u884cpyenv activate \u865a\u62df\u73af\u5883\u540d\u3002<\/p>\n<p><wiz_tmp_tag id=\"wiz-table-range-border\" contenteditable=\"false\" style=\"display: none;\"><\/p>\n<div id=\"wiz-table-col-line\" style=\"display: none;\"><\/div>\n<div id=\"wiz-table-row-line\" style=\"display: none;\"><\/div>\n<div id=\"wiz-table-range-border_start\" style=\"display: none;\">\n<div id=\"wiz-table-range-border_start_top\"><\/div>\n<div id=\"wiz-table-range-border_start_right\"><\/div>\n<div id=\"wiz-table-range-border_start_bottom\"><\/div>\n<div id=\"wiz-table-range-border_start_left\"><\/div>\n<div id=\"wiz-table-range-border_start_dot\"><\/div>\n<\/div>\n<div id=\"wiz-table-range-border_range\" style=\"display: none;\">\n<div id=\"wiz-table-range-border_range_top\"><\/div>\n<div id=\"wiz-table-range-border_range_right\"><\/div>\n<div id=\"wiz-table-range-border_range_bottom\"><\/div>\n<div id=\"wiz-table-range-border_range_left\"><\/div>\n<div id=\"wiz-table-range-border_range_dot\"><\/div>\n<\/div>\n<p><\/wiz_tmp_tag><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88c5 1. \u5b89\u88c5\u4f9d\u8d56\u5305 ubuntu16 sudo apt-get install curl git-core gcc make build-essential libssl-dev zlib1g-dev libbz2-dev \\ libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev li&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[89,86,4],"tags":[37,38,30],"class_list":["post-194","post","type-post","status-publish","format-standard","hentry","category-linux","category-python","category-skill","tag-pyenv","tag-pyenv-virtualenv","tag-python3"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/posts\/194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/comments?post=194"}],"version-history":[{"count":1,"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/posts\/194\/revisions"}],"predecessor-version":[{"id":711,"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/posts\/194\/revisions\/711"}],"wp:attachment":[{"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/media?parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/categories?post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chenbing.name\/blog\/wp-json\/wp\/v2\/tags?post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}