﻿{"id":2092,"date":"2020-08-17T18:52:52","date_gmt":"2020-08-17T10:52:52","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=2092"},"modified":"2025-02-11T14:40:50","modified_gmt":"2025-02-11T06:40:50","slug":"pyenv-%e8%ae%a9-python-%e7%89%88%e6%9c%ac%e5%ae%8c%e7%be%8e%e5%88%87%e6%8d%a2","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/linux\/2092","title":{"rendered":"pyenv \u8ba9 python \u7248\u672c\u5b8c\u7f8e\u5207\u6362"},"content":{"rendered":"<div>\n<h2>\u524d\u8a00<\/h2>\n\u6211\u89c9\u5f97\u5982\u679c\u4f7f\u7528 python \u5f00\u53d1\u7684\u8bdd\uff0c\u8fd8\u662f\u5728 unix\/linux \u7684\u73af\u5883\u4e0b\u5427\uff0cshell \u5de5\u5177\u7684\u6548\u7387\u6bd4 windows \u9ad8\u5f97\u591a\uff0c\u5c3d\u7ba1 windows \u4e0b\u4e5f\u6709 cmder \u8fd9\u79cd\u795e\u5668\uff0c\u800c\u4e14\u73b0\u5728 windows store \u4e5f\u5f88\u597d\u7684\u5f00\u53d1\u51fa\u4e86 linux \u5b50\u7cfb\u7edf\uff0c\u4f46\u662f\u7455\u75b5\u975e\u5e38\u591a\uff0cunix\/linux \u624d\u662f\u5b8c\u7f8e\u7684\u73af\u5883\u3002\u672c\u6587\u7528\u5230\u7684\u662f archlinux \uff0c\u53e6\u5916 debian\/ubuntu\u3001centos \u4e5f\u5b8c\u5168\u9002\u7528\u3002mac \u7528\u6237\u4e5f\u53ef\u4ee5\u53c2\u8003\uff0c\u4e0d\u8fc7 homebrew \u4e5f\u63d0\u4f9b\u4e86\u975e\u5e38\u65b9\u4fbf\u7684\u5b89\u88c5\u65b9\u6cd5\uff0c\u4f46\u662f\u5efa\u8bae\u4f7f\u7528\u6587\u672c\u505a\u6cd5\u3002\n<h2>\u80cc\u666f<\/h2>\npython \u7248\u672c\u6bd4\u8f83\u591a\uff0c2 \u548c 3 \u76f8\u5dee\u975e\u5e38\u5927\uff0c\u5f88\u591a\u9879\u76ee\u9700\u8981\u8dd1\u5728\u540c\u4e00\u53f0\u670d\u52a1\u5668\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u76f4\u63a5\u8fd0\u884c\uff0c\u4e5f\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528 docker\u3002\u5982\u679c\u7528 docker \u90a3\u5c31\u4e0d\u9700\u8981\u9694\u79bb\u73af\u5883\u4e86\uff0c\u5982\u679c\u8981\u76f4\u63a5\u8fd0\u884c\u5728\u670d\u52a1\u5668\u4e0a\uff0c\u90a3\u5c31\u5fc5\u987b\u6709\u9694\u79bb\u73af\u5883\u3002\u6bd4\u5982\u6709\u7684\u9879\u76ee\u4f7f\u7528 python 3.5\uff0c\u6709\u7684\u9879\u76ee\u4f7f\u7528 python 3.7\uff0c\u6b64\u65f6\u6211\u4eec\u53ef\u4ee5\u501f\u52a9 pyenv \u5e2e\u52a9\u6211\u4eec\u5b8c\u7f8e\u7684\u9694\u79bb\u73af\u5883\uff0c\u8ba9\u591a\u4e2a\u7248\u672c\u7684 python \u6ca1\u6709\u4efb\u4f55\u51b2\u7a81\uff0c\u5b8c\u7f8e\u5171\u5b58\u3002\n<h2>\u4efb\u52a1<\/h2>\n\u4f7f\u7528 pyenv \u548c pyenv-virtualenv \uff0c\u5728 linux \u4e0b\u5b8c\u7f8e\u9694\u79bb python \u5404\u4e2a\u7248\u672c\n<h2>\u7b2c 1 \u7ae0\uff1a\u4f7f\u7528\u73af\u5883<\/h2>\n<ul>\n    <li>\u64cd\u4f5c\u7cfb\u7edf\uff1a<a href=\"https:\/\/www.archlinux.org\/\" target=\"_blank\" rel=\"nofollow noopener\">archlinux<\/a><\/li>\n    <li>shell\uff1a<a href=\"https:\/\/github.com\/robbyrussell\/oh-my-zsh\" target=\"_blank\" rel=\"nofollow noopener\">zsh<\/a><\/li>\n<\/ul>\n<strong>\u8bf7\u6ce8\u610f\uff0c\u63a5\u4e0b\u6765\u6240\u6709\u7684\u64cd\u4f5c\u90fd\u5728 archlinux \u4e0b\u8fdb\u884c\uff0c\u672c\u6587\u4e0d\u6d89\u53ca windows<\/strong>\n<h3>\u6e05\u5355<\/h3>\n<ol>\n    <li>git<\/li>\n    <li>zsh \u6216\u8005 bash<\/li>\n    <li><a href=\"https:\/\/github.com\/pyenv\/pyenv.git\" target=\"_blank\" rel=\"nofollow noopener\">pyenv<\/a><\/li>\n    <li><a href=\"https:\/\/github.com\/pyenv\/pyenv-virtualenv.git\" target=\"_blank\" rel=\"nofollow noopener\">pyenv-virtualenv<\/a><\/li>\n<\/ol>\n<h3>1\u3001\u5b89\u88c5 git<\/h3>\n\u5728\u5404\u5927 linux \u7684\u53d1\u884c\u7248\u4e0b\u5b89\u88c5 git \u90fd\u975e\u5e38\u7b80\u5355\uff0c\u6b64\u5904\u53ea\u5c55\u793a\u90e8\u5206\u793a\u4f8b\n<h4>archlinux<\/h4>\n<code>sudo pacman -S git<\/code>\n<h4>debian\/ubuntu<\/h4>\n<code>sudo apt-get install git<\/code>\n<h4>centos<\/h4>\n<code>sudo yum install git<\/code>\n<h3>2\u3001\u5f00\u542f\u7ec8\u7aef<\/h3>\n\u672c\u6587\u4f7f\u7528 zsh\n<h3>3\u3001\u5b89\u88c5 pyenv<\/h3>\n<strong><em>\u8bf4\u660e\uff1a\u672c\u6587\u7684\u6240\u6709\u5b89\u88c5\u90fd\u4e25\u683c\u9075\u5b88\u5b98\u65b9\u6587\u6863\uff0c\u4e0e\u5b98\u65b9\u6587\u6863\u5b8c\u5168\u4fdd\u6301\u4e00\u81f4\u3002<\/em><\/strong>\n\ngit \u5730\u5740\uff1a<a href=\"https:\/\/github.com\/pyenv\/pyenv\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/github.com\/pyenv\/pyenv<\/a>\n\n\u5728\u4f60\u7684\u7ec8\u7aef\u4e2d\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff0c\u5b89\u5168\u65e0\u6bd2\uff0c\u8bf7\u653e\u5fc3\u98df\u7528\uff1a\n\n\u9996\u5148\u628a\u9879\u76ee\u514b\u9686\u4e0b\u6765\uff0c\u653e\u5728\u5bb6\u76ee\u5f55\u4e0b\u7684\u9690\u85cf\u6587\u4ef6\u5939\u4e2d\uff1a.pyenv\n\n<code>git clone https:\/\/github.com\/pyenv\/pyenv.git ~\/.pyenv<\/code>\n\n\u7136\u540e\u914d\u7f6e\u73af\u5883\u53d8\u91cf\n<h5>\u5982\u679c\u4f60\u4f7f\u7528 bash\uff0c\u5c31\u4f9d\u6b21\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/h5>\n<code>echo 'export PYENV_ROOT=&quot;$HOME\/.pyenv&quot;' &gt;&gt; ~\/.bashrc<\/code>\n\n<code>echo 'export PATH=&quot;$PYENV_ROOT\/bin:$PATH&quot;' &gt;&gt; ~\/.bashrc<\/code>\n\n<code>echo -e 'if command -v pyenv 1&gt;\/dev\/null 2&gt;&amp;1; then\\n eval &quot;$(pyenv init -)&quot;\\nfi' &gt;&gt; ~\/.bashrc<\/code>\n<h5>\u5982\u679c\u4f60\u4f7f\u7528 zsh\uff0c\u5c31\u4f9d\u6b21\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/h5>\n<code>echo 'export PYENV_ROOT=&quot;$HOME\/.pyenv&quot;' &gt;&gt; ~\/.zshrc<\/code>\n\n<code>echo 'export PATH=&quot;$PYENV_ROOT\/bin:$PATH&quot;' &gt;&gt; ~\/.zshrc<\/code>\n\n<code>echo -e 'if command -v pyenv 1&gt;\/dev\/null 2&gt;&amp;1; then\\n eval &quot;$(pyenv init -)&quot;\\nfi' &gt;&gt; ~\/.zshrc<\/code>\n\necho \u547d\u4ee4\u7684\u542b\u4e49\u662f\uff1a\u5c06\u5f15\u53f7\u4e2d\u5185\u5bb9\u5199\u5165\u67d0\u6587\u4ef6\u4e2d\n\u8bf7\u6ce8\u610f\uff0c\u4ee5\u4e0a\u7684\u4e09\u6761 echo \u547d\u4ee4\u7684\u6700\u540e\u4e00\u6761\u957f\u957f\u7684\u547d\u4ee4\uff0c\u8bf7\u4f60\u4fdd\u8bc1\u5b83\u5f15\u53f7\u4e2d\u7684\u5185\u5bb9\u5904\u4e8e ~\/.bashrc \u6216\u8005 ~\/.zshrc \u7684\u6700\u5e95\u90e8\u3002\n\u56e0\u4e3a\u5728 pyenv \u521d\u59cb\u5316\u671f\u95f4\u4f1a\u64cd\u4f5c path \u73af\u5883\u53d8\u91cf\uff0c\u5bfc\u81f4\u4e0d\u53ef\u9884\u6d4b\u7684\u884c\u4e3a\u3002\n\u67e5\u770b\u6587\u4ef6\u7684\u5e95\u90e8\u5185\u5bb9\uff0c\u53ef\u4ee5\u4f7f\u7528 tail \u547d\u4ee4\uff0c\u7528\u6cd5\uff1atail ~\/.bashrc \u6216\u8005 tail ~\/.zshrc\uff0c\u7f16\u8f91\u6587\u4ef6\u53ef\u4ee5\u4f7f\u7528 vim \u6216\u8005 vscode\n\n\u6700\u540e\uff0c\u5728\u4f7f\u7528 pyenv \u4e4b\u524d\uff0c\u91cd\u65b0\u521d\u59cb\u5316 shell \u73af\u5883\uff0c\u6267\u884c\u5982\u4e0b\u547d\u4ee4\n\n<code>exec $SHELL<\/code>\n\n\u4e0d\u6267\u884c\u8be5\u547d\u4ee4\u4e5f\u662f\u5b8c\u5168\u53ef\u4ee5\u7684\uff0c\u4f60\u53ef\u4ee5\u5173\u95ed\u5f53\u524d\u7684\u7ec8\u7aef\u7a97\u53e3\uff0c\u91cd\u65b0\u542f\u52a8\u4e00\u4e2a\u5c31\u53ef\u4ee5\u4e86\u3002\n\n\u6b64\u65f6\uff0c\u4f60\u5df2\u7ecf\u5b8c\u6210\u4e86 pyenv \u7684\u5b89\u88c5\u4e86\uff0c\u4f60\u4f7f\u7528\u53ef\u4ee5\u5b83\u7684\u5168\u90e8\u547d\u4ee4\u4e86\uff0c\u4f46\u662f\u6211\u5efa\u8bae\u4f60\u5148\u522b\u6025\u7740\u7528\uff0c\u4e00\u53e3\u6c14\u88c5\u5b8c pyenv \u7684\u4e00\u4e2a\u63d2\u4ef6\uff0c\u90a3\u5c31\u662f pyenv-virtualenv\n<h3>4\u3001\u5b89\u88c5 pyenv-virtualenv<\/h3>\ngit \u5730\u5740\uff1a<a href=\"https:\/\/github.com\/pyenv\/pyenv-virtualenv\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/github.com\/pyenv\/pyenv-virtualenv<\/a>\n\n\u628a\u63d2\u4ef6\u514b\u9686\u5728\u521a\u624d\u5df2\u7ecf\u5b89\u88c5\u5b8c\u6bd5\u7684 pyenv \u7684 plugins \u6587\u4ef6\u5939\u4e2d\n\n<code>git clone https:\/\/github.com\/pyenv\/pyenv-virtualenv.git $(pyenv root)\/plugins\/pyenv-virtualenv<\/code>\n\n\u7136\u540e\u914d\u7f6e\u73af\u5883\u53d8\u91cf\n<h5>\u5982\u679c\u4f60\u4f7f\u7528 bash\uff0c\u5c31\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/h5>\n<code>echo 'eval &quot;$(pyenv virtualenv-init -)&quot;' &gt;&gt; ~\/.bashrc<\/code>\n<h5>\u5982\u679c\u4f60\u4f7f\u7528 zsh\uff0c\u5c31\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/h5>\n<code>echo 'eval &quot;$(pyenv virtualenv-init -)&quot;' &gt;&gt; ~\/.zshrc<\/code>\n\n\u6700\u540e\uff0c\u5728\u4f7f\u7528 pyenv \u4e4b\u524d\uff0c\u91cd\u65b0\u521d\u59cb\u5316 shell \u73af\u5883\uff0c\u6267\u884c\u5982\u4e0b\u547d\u4ee4\n\n<code>exec $SHELL<\/code>\n\n\u4e0d\u6267\u884c\u8be5\u547d\u4ee4\u4e5f\u662f\u5b8c\u5168\u53ef\u4ee5\u7684\uff0c\u4f60\u53ef\u4ee5\u5173\u95ed\u5f53\u524d\u7684\u7ec8\u7aef\u7a97\u53e3\uff0c\u91cd\u65b0\u542f\u52a8\u4e00\u4e2a\u5c31\u53ef\u4ee5\u4e86\u3002\n\n\u5230\u6b64\uff0c\u6211\u4eec\u7684\u6240\u6709\u91cd\u8981\u5b89\u88c5\u5df2\u7ecf\u5168\u90e8\u5b8c\u6210\u4e86\uff0c\u53ef\u4ee5\u5f00\u59cb\u4f53\u9a8c\u4e86\u3002\n<h2>\u7b2c 2 \u7ae0\uff1a\u4f7f\u7528 pyenv<\/h2>\n<strong><em>\u6b64\u5904\u4ec5\u4ec5\u5c55\u793a pyenv \u548c virtualenv \u7684\u65e5\u5e38\u7528\u6cd5<\/em><\/strong>\n<h3>\u68c0\u67e5\u5b89\u88c5\u662f\u5426\u6b63\u786e<\/h3>\n\u68c0\u67e5 pyenv \u7684\u7248\u672c\n\n<code>pyenv version<\/code>\n\n\u67e5\u770b pyenv \u5df2\u7ecf\u6258\u7ba1\u4e86\u54ea\u4e9b python \u7248\u672c\n\n<code>pyenv versions<\/code>\n\n\u5982\u679c\u4f60\u770b\u5230\u4e86\u6b63\u5e38\u7684\u7248\u672c\u4fe1\u606f\uff0c\u5c31\u8bf4\u660e\u53ef\u4ee5\u4e86\uff0c\u5982\u679c\u770b\u5230\u4e86\u7c7b\u4f3c\u4e8e command not found \u4e4b\u7c7b\u7684\uff0c\u5c31\u8bf4\u660e\u5b89\u88c5\u5931\u8d25\u4e86\u3002\n<h3>\u5b89\u88c5 3.6.6 \u7248\u672c\u7684 python<\/h3>\nsudo apt-get install libbz2-dev <span style=\"font-size: revert; color: initial;\">libssl-dev<\/span>\n<span style=\"font-size: revert; color: initial;\"> libreadline6-dev<\/span>\n<span style=\"font-size: revert; color: initial;\"> libsqlite3-dev libffi-dev libncurses-dev libzip-dev liblzma-dev\u00a0 \u00a0\u00a0<\/span>\n\n<code>pyenv install 3.6.6<\/code>\n\n\u8fd9\u91cc\u6709\u4e2a\u95ee\u9898\uff0c\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4f1a\u5b89\u88c5\u5931\u8d25\uff0c\u62a5\u9519\u5c31\u544a\u8bc9\u4f60 Build failed\n\n\u8fd9\u4e2a\u65f6\u5019\uff0cpyenv \u5df2\u7ecf\u5728\u5b83\u7684 github wiki \u91cc\u9762\u4e3a\u6211\u4eec\u51c6\u5907\u4e86\u4e00\u7bc7\u9519\u8bef\u5e94\u5bf9\u65b9\u6848\uff0c\u539f\u6587\u5730\u5740 <a href=\"https:\/\/github.com\/pyenv\/pyenv\/wiki\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/github.com\/pyenv\/pyenv\/wiki<\/a>\n\n\u5927\u610f\u5982\u4e0b\uff0c\u53ea\u9700\u8981\u6267\u884c\u5bf9\u5e94\u7684\u547d\u4ee4\u5373\u53ef\uff1a\n\n<strong>archlinux \u7528\u6237<\/strong>\n\n<code>sudo pacman -S base-devel openssl zlib<\/code>\n\n<strong>mac \u7528\u6237<\/strong>\n\n<code>brew install openssl readline sqlite3 xz zlib<\/code>\n\n<strong>Ubuntu\/Debian\/Mint \u7528\u6237<\/strong>\n\n<code>sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev<\/code>\n\n<strong>CentOS\/Fedora <= 21 \u7528\u6237\uff0c\u8bf7\u4f60\u4fdd\u8bc1\u5df2\u7ecf\u5b89\u88c5\u4e86 xz \u5de5\u5177<\/strong>\n\n<code>sudo yum install gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel<\/code>\n\n<strong>Fedora >= 22 \u7528\u6237\uff0c\u8bf7\u4f60\u4fdd\u8bc1\u5df2\u7ecf\u5b89\u88c5\u4e86 xz \u5de5\u5177<\/strong>\n\n<code>sudo dnf install -y gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel<\/code>\n\n<strong>openSUSE \u7528\u6237<\/strong>\n\n<code>zypper install gcc automake openssl-devel ncurses-devel readline-devel zlib-devel tk-devel<\/code>\n\n<strong>Solus \u7528\u6237<\/strong>\n\n<code>sudo eopkg it -c system.devel<\/code>\n\n<code>sudo eopkg install git gcc make zlib-devel bzip2-devel readline-devel sqlite3-devel openssl-devel tk-devel<\/code>\n\n<strong>Linuxbrew \u7528\u6237<\/strong>\n\n<code>brew install bzip2 openssl readline sqlite xz<\/code>\n\n\u5b89\u88c5\u5b8c\u8fd9\u4e9b\u8865\u5145\u7684\u5de5\u5177\u4e4b\u540e\uff0c\u518d\u6b21\u6267\u884c\uff1a\n\n<code>pyenv install 3.6.6<\/code>\n\n\u5c31\u53ef\u4ee5\u6210\u529f\u4e86\uff0c\u4f60\u53ef\u4ee5\u4e0d\u65ad\u7684\u4f7f\u7528\n\n<code>pyenv versions<\/code>\n\n\u6765\u67e5\u770b\u88ab pyenv \u6258\u7ba1\u7684 python \u7248\u672c\n\n\u800c\u4e14\u4f60\u60f3\u88c5\u4ec0\u4e48\u7248\u672c\u5c31\u88c5\u4ec0\u4e48\u7248\u672c\uff0c\u60f3\u88c5\u51e0\u4e2a\u88c5\u51e0\u4e2a\uff0c\u90fd\u662f\u5b8c\u7f8e\u5171\u5b58\uff0c\u5b8c\u7f8e\u9694\u79bb\uff0c\u4f60\u53ef\u4ee5\u5728\u7ec8\u7aef\u91cc\u8f93\u5165\n\n<code>pyenv install<\/code>\n\n\u7136\u540e\u6309\u4e0b tab \u952e\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u6240\u6709\u53ef\u9009\u7684\u5b89\u88c5\u7248\u672c\u4e86\n<h3>\u4f7f\u7528\u521a\u624d\u5b89\u88c5\u7684 python 3.6.6<\/h3>\n\u9996\u5148\u6211\u4eec\u9700\u8981\u660e\u786e\u4e00\u4e2a\u6982\u5ff5\uff0cpyenv \u548c pyenv-virtualenv \u4ed6\u4eec\u662f\u5982\u4f55\u534f\u4f5c\u7684\uff0c\u4f60\u53ef\u4ee5\u8fd9\u4e48\u8ba4\u4e3a\uff1a\n\n<strong>pyenv \u6258\u7ba1 python \u7248\u672c\uff0cvirtualenv \u4f7f\u7528 python \u7248\u672c<\/strong>\n\n\u597d\u4e86\uff0c\u4e4b\u524d\u5df2\u7ecf\u88c5\u597d\u4e86\u7248\u672c\uff0c\u90a3\u4e48\u73b0\u5728\u5c31\u6765\u4f7f\u7528\u5427\n<h4>\u7b2c 1 \u6b65\uff1a\u521b\u5efa\u865a\u62df\u73af\u5883<\/h4>\n\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\uff0c\u6267\u884c\u547d\u4ee4\uff1a\n\n<code>pyenv virtualenv 3.6.6 my-env<\/code>\n\n\u5b83\u7684\u683c\u5f0f\u5c31\u662f\u8fd9\u6837\u56fa\u5b9a\u7684\uff0c\u6700\u540e\u4e00\u4e2a\u662f\u4f60\u81ea\u5df1\u60f3\u8981\u7684\u73af\u5883\u7684\u540d\u5b57\uff0c\u53ef\u4ee5\u968f\u4fbf\u53d6\u3002\u7a0d\u7b49\u7247\u523b\uff0c\u4f60\u5c06\u4f1a\u770b\u5230\uff1a\n\n<strong><em>Looking in links: \/tmp\/tmp0eywgc7v<\/em><\/strong>\n<strong><em>Requirement already satisfied: setuptools in \/home\/joit\/.pyenv\/versions\/3.6.6\/envs\/my-env\/lib\/python3.6\/site-packages (39.0.1)<\/em><\/strong>\n<strong><em>Requirement already satisfied: pip in \/home\/joit\/.pyenv\/versions\/3.6.6\/envs\/my-env\/lib\/python3.6\/site-packages (10.0.1)<\/em><\/strong>\n\n\u7c7b\u4f3c\u4e8e\u8fd9\u6837\u7684\u56de\u663e\u4fe1\u606f\uff0c\u8bf4\u660e\u73af\u5883\u5df2\u7ecf\u521b\u5efa\u6210\u529f\u4e86\uff0c\u5b83\u8fd8\u544a\u8bc9\u4e86\u4f60\uff0c\u8be5\u865a\u62df\u73af\u5883\u7684\u7edd\u5bf9\u8def\u5f84\uff0c\u5982\u679c\u4f60\u8fdb\u53bb\u770b\u4e86\uff0c\u4f60\u5c31\u4f1a\u53d1\u73b0\uff0c\u6240\u8c13\u7684\u865a\u62df\u73af\u5883\uff0c\u5c31\u662f\u628a python \u88c5\u5728 pyenv \u7684\u5b89\u88c5\u76ee\u5f55\u7684\u67d0\u4e2a\u6587\u4ef6\u5939\u4e2d\uff0c\u4ee5\u4f9b\u5b83\u81ea\u5df1\u8c03\u7528\u3002\n<h4>\u7b2c 2 \u6b65\uff1a\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/h4>\n\u5728\u4efb\u610f\u76ee\u5f55\u4e0b\uff0c\u6267\u884c\u547d\u4ee4\uff1a\n\n<code>pyenv activate my-env<\/code>\n\n\u4f60\u4f1a\u53d1\u73b0\uff0c\u5728\u4f60\u7684\u7ec8\u7aef\u91cc\u9762\uff0c\u591a\u4e86\u4e00\u4e2a\u7c7b\u4f3c\u4e8e <code>(my-env)<\/code> \u8fd9\u6837\u7684\u4e00\u4e2a\u4e1c\u897f\uff0c\u8fd9\u65f6\u5019\u4f60\u5982\u679c\u6267\u884c\uff1a\n\n<code>python --version<\/code>\n\n\u90a3\u5c31\u662f python 3.6.6 \u4e86\n\n\u5982\u679c\u4f60\u6267\u884c\uff1a\n\n<code>pip --version<\/code>\n\n\u5b83\u4f1a\u544a\u8bc9\u4f60 pip \u5305\u5b89\u88c5\u7684\u7edd\u5bf9\u8def\u5f84\uff0c\u4e5f\u662f pyenv \u5b89\u88c5\u76ee\u5f55\u4e0b\u7684\u67d0\u4e2a\u6587\u4ef6\u5939\n\n\u5982\u679c\u4f60\u5173\u6389\u4e86\u7ec8\u7aef\uff0c\u90a3\u4e48\u4e0b\u6b21\u542f\u52a8\u4f60\u53c8\u5f97\u91cd\u65b0\u6fc0\u6d3b\u4e00\u6b21\u4e86\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1a\n\n\u9996\u5148 cd \u5230\u67d0\u4e00\u4e2a\u76ee\u5f55\uff0c\u6bd4\u5982 ~\/test\n\n<code>cd ~\/test<\/code>\n\n\u7136\u540e\u5728\u8be5\u76ee\u5f55\u4e0b\u6267\u884c\uff1a\n\n<code>pyenv local my-env<\/code>\n\n\u4f60\u4f1a\u53d1\u73b0\u5df2\u7ecf\u88ab\u6fc0\u6d3b\u4e86\uff0c\u90a3\u4e48 local \u547d\u4ee4\u548c\u521a\u624d\u6709\u5565\u4e0d\u540c\u5462\u3002\u5982\u679c\u4f60\u6267\u884c\uff1a\n\n<code>ls -al<\/code>\n\n\u4f60\u5c31\u4f1a\u53d1\u73b0\uff0c\u5728 ~\/test \u76ee\u5f55\u4e0b\uff0c\u6709\u4e2a\u9690\u85cf\u6587\u4ef6 .python-version\uff0c\u4f60\u53ef\u4ee5\u770b\u5230\u8fd9\u4e2a\u6587\u4ef6\u91cc\u9762\uff0c\u53ea\u5199\u4e86\u4e00\u53e5\u8bdd my-env\n\n\u8fd9\u6837\u4f60\u53ea\u8981\u8fdb\u5165 ~\/test \u76ee\u5f55\uff0c\u5c31\u4f1a\u81ea\u52a8\u6fc0\u6d3b\u865a\u62df\u73af\u5883\n\n\u5728\u865a\u62df\u73af\u5883\u4e0b\uff0c\u4f60\u5982\u679c\u76f4\u63a5\u6267\u884c\n\n<code>python<\/code>\n\n\u5c31\u4f1a\u8fdb\u5165\u5230 python \u7684\u4ea4\u4e92\u73af\u5883\n\n\u5982\u679c\u4f60\u5199\u4e86\u4e00\u4e2a\u6587\u4ef6\uff0c\u540d\u5b57\u53eb\u505a app.py \uff0c\u91cc\u9762\u7684\u5185\u5bb9\u53ea\u6709\u4e00\u53e5\u4ee3\u7801\uff1aprint(1)\n\n\u7136\u540e\u6267\u884c\uff1a\n\n<code>python app.py<\/code>\n\n\u8fd9\u65f6\u5019\uff0c\u7cfb\u7edf\u5c31\u4f1a\u8c03\u7528\u865a\u62df\u73af\u5883\u4e2d\u7684 python \u89e3\u91ca\u5668\u6765\u6267\u884c\u8fd9\u4e9b\u4ee3\u7801\u4e86\n<h2>\u7b2c 3 \u7ae0\uff1a\u66f4\u65b0 pyenv<\/h2>\n\u7531\u4e8e\u6211\u4eec\u662f git \u514b\u9686\u7684\uff0c\u6240\u4ee5\u66f4\u65b0\u975e\u5e38\u7b80\u5355\n\n<code>cd ~\/.pyenv<\/code> \u6216\u8005 <code>cd $(pyenv root)<\/code>\n<code>git pull<\/code>\n<h2>\u7b2c 4 \u7ae0\uff1a\u5378\u8f7d pyenv<\/h2>\n\u7531\u4e8e pyenv \u628a\u4e00\u5207\u90fd\u653e\u5728 ~\/.pyenv \u4e0b\u4e86\uff0c\u6240\u4ee5\u5378\u8f7d\u5f88\u65b9\u4fbf\uff0c\u4e24\u4e2a\u6b65\u9aa4\u5c31\u884c\u4e86\n\n\u9996\u5148\u4f60\u9700\u8981\u5220\u9664\u73af\u5883\u53d8\u91cf\n\n\u7136\u540e\u4f60\u9700\u8981\u6267\u884c\uff1a\n\n<code>rm -rf ~\/.pyenv<\/code> \u6216\u8005 <code>rm -rf $(pyenv root)<\/code>\n\n<\/div>\n<h1><\/h1>\n<h1 id=\"articleContentId\" class=\"title-article\">\u89e3\u51b3 pyenv install \u56fd\u5185\u4e0b\u8f7d\u7f13\u6162\u7684\u95ee\u9898<\/h1>\n<p>wget <a href=\"https:\/\/registry.npmmirror.com\/-\/binary\/python\/3.9.0\/Python-3.9.0.tar.xz\">https:\/\/registry.npmmirror.com\/-\/binary\/python\/3.9.0\/Python-3.9.0.tar.xz<\/a> -P ~\/.pyenv\/cache\/<\/p>\n<p>pyenv install 3.9.0<\/p>","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u6211\u89c9\u5f97\u5982\u679c\u4f7f\u7528 python \u5f00\u53d1\u7684\u8bdd\uff0c\u8fd8\u662f\u5728 unix\/linux \u7684\u73af\u5883\u4e0b\u5427\uff0cshell \u5de5\u5177\u7684\u6548\u7387\u6bd4 windows \u9ad8\u5f97\u591a\uff0c\u5c3d\u7ba1 windows \u4e0b\u4e5f\u6709 cmder \u8fd9\u79cd\u795e\u5668\uff0c\u800c\u4e14\u73b0\u5728 &#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,340,274],"tags":[506,275],"class_list":["post-2092","post","type-post","status-publish","format-standard","hentry","category-linux","category-mac-os","category-python","tag-pyenv","tag-python-2"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=2092"}],"version-history":[{"count":3,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2092\/revisions"}],"predecessor-version":[{"id":2766,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2092\/revisions\/2766"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=2092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=2092"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=2092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}