{"id":730,"date":"2020-10-20T20:45:16","date_gmt":"1000-01-01T00:00:00","guid":{"rendered":"https:\/\/blog.humh.cn\/?p=730"},"modified":"2021-12-07T15:33:02","modified_gmt":"2021-12-07T07:33:02","slug":"python%e7%89%88%e6%9c%ac%e7%ae%a1%e7%90%86%e4%b8%8e%e8%99%9a%e6%8b%9f%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/blog.humh.cn\/?p=730","title":{"rendered":"python\u7248\u672c\u7ba1\u7406\u4e0e\u865a\u62df\u73af\u5883"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\"><p>\u603b\u7ed3\u4e0b\u5173\u4e8epyenv\u4ee5\u53cavirtualenv\u7684\u7406\u89e3<\/p><\/blockquote>\n\n\n\n<p>\u4e00\u822c\u7cfb\u7edf\u4f1a\u81ea\u5e26\u4e00\u4e2apython2\u7248\u672c\u7684python\uff0c\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u5f80\u5f80\u53ef\u80fd\u4f7f\u7528python3\uff0c\u5e76\u4e14\u591a\u4e2a\u9879\u76eepython\u7248\u672c\u8981\u6c42\u4e0d\u4e00\u6837\u3002\u5982\u679c\u540c\u65f6\u5f00\u53d1\u591a\u4e2a\u4e0d\u540c\u7248\u672c\u8981\u6c42\u7684\u9879\u76ee\uff0c\u76f4\u63a5\u5b89\u88c5\u591a\u4e2a\u7248\u672c\u7684python\u662f\u4e0d\u884c\u7684\u3002\u6240\u4ee5\u53ea\u8981\u89e3\u51b3\u4e00\u4e2a\u673a\u5668\u4e0a\u5982\u4f55\u5e76\u5b58\u591a\u4e2a\u7248\u672c\u7684python\u5373\u53ef\uff0cpyenv\u5b55\u80b2\u800c\u51fa\u3002<\/p>\n\n\n\n<h2>\u4e00\u3001pyenv<\/h2>\n\n\n\n<p>pyenv\u662f\u4e00\u4e2a\u7ba1\u7406python\u7248\u672c\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u540c\u65f6\u7ba1\u7406\u591a\u4e2a\u4e0d\u540c\u7248\u672c\u7684python\uff0c\u5e76\u5f88\u5bb9\u6613\u5730\u5728\u591a\u7248\u672c\u4e4b\u95f4\u5207\u6362\uff0c\u968f\u65f6\u968f\u5730\u4f7f\u7528\u4efb\u610f\u7248\u672c\u7684python\u3002<\/p>\n\n\n\n<h3>1\u3001\u5b89\u88c5<\/h3>\n\n\n\n<p>\u5982\u679c\u4f60\u662fmac\u7cfb\u7edf\u5e76\u5b89\u88c5\u4e86homebrew\u7684\u8bdd\uff0c\u76f4\u63a5<code>brew install pyenv<\/code>\u5373\u53ef\u3002\u5982\u679c\u662f\u5176\u4ed6\u7684\u8bdd\uff0c\u53ef\u4ee5\u76f4\u63a5clone\u4ed3\u5e93\u5b89\u88c5\uff0c\u5f53\u7136\u56e0\u4e3a\u6211\u8fd9\u91cc\u4f7f\u7528\u7684\u662fmac\uff0c\u6240\u4ee5\u4e3b\u8981\u9610\u8ff0mac\u4e0b\u64cd\u4f5c\u7684\u60c5\u51b5\uff08\u8865\u5145\uff1aUbuntu\u7684\u8bdd\uff0c\u8fd0\u884c<code>curl -L https:\/\/github.com\/pyenv\/pyenv-installer\/raw\/master\/bin\/pyenv-installer | bash<\/code>\uff09\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u9047\u5230\u4e0e<strong>openssl<\/strong>\u76f8\u5173\u7684\u7f16\u8bd1\u62a5\u9519\uff0c\u5219\u662f\u56e0\u4e3ahomebrew\u5b89\u88c5pyenv\u65f6\u4f1a\u9644\u5e26\u5b89\u88c5\u4e00\u4e2a\u7248\u672c\u7684openssl\uff0c\u53ef\u4ee5<code>brew uninstall openssl<\/code>\uff0c\u7136\u540e<code>pyenv install v<\/code> \u65f6\u4f1a\u9ed8\u8ba4\u4e0b\u8f7d\u5176\u6240\u9700\u7248\u672c\u7684openssl\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u279c  ~ pyenv -v\npyenv 1.2.19<\/pre>\n\n\n\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8981\u60f3\u975e\u8def\u5f84\u4f7f\u7528\uff0c\u9700\u8981\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff08~\/.bashrc\u6216~\/.zshrc\u7b49\uff09\uff0c<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">export PATH=\"\/home\/humh\/.pyenv\/bin:$PATH\"\neval \"$(pyenv init -)\"<\/pre>\n\n\n\n<p>\u8fd9\u91cc\u6211mac\u5b89\u88c5pyenv\u540e\u547d\u4ee4\u96c6\u9ed8\u8ba4\u4f4d\u4e8e <strong>\/usr\/local\/bin<\/strong> , \u6240\u4ee5\u76f4\u63a5 <code>export PATH=\"\/usr\/local\/bin:$PATH\"<\/code> \u3002<br>\u914d\u7f6e\u5b8c\u6210\u540e\uff0csource\u4e00\u4e0b\u3002\u952e\u5165<code>pyenv -v<\/code>\uff0c\u5982\u679c\u51fa\u73b0pyenv\u7248\u672c\u53f7\uff0c\u5373\u5b89\u88c5\u6210\u529f\u3002<\/p>\n\n\n\n<h3>2\u3001\u4f7f\u7528<\/h3>\n\n\n\n<h4>2.1\u3001pyenv install<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u279c  ~ pyenv install --list\nAvailable versions:\n  2.1.3\n  2.2.3\n  2.3.7\n  2.4.0\n  2.4.1\n  2.4.2\n  .....\n\u279c  ~ pyenv install 2.1.3<\/pre>\n\n\n\n<p><code>pyenv install --list<\/code>\u53ef\u4ee5\u67e5\u770b\u5230\u652f\u6301\u5b89\u88c5\u7684\u6240\u6709python\u7248\u672c\uff0c\u7136\u540e<code>pyenv install 2.1.3<\/code>\u5373\u53ef\u5b89\u88c52.1.3\u7684\u7248\u672c\uff0c\u5f53\u7136\u4f60\u53ef\u4ee5\u5c062.1.3\u6362\u6210\u5176\u4ed6\u7248\u672c\u53f7\u3002<\/p>\n\n\n\n<h4>2.2\u3001pyenv versions<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u279c  ~ pyenv versions\n  system\n* 2.7.12 (set by \/Users\/humh\/.pyenv\/version)\n  3.7.0<\/pre>\n\n\n\n<p><code>pyenv versions<\/code>\u53ef\u4ee5\u67e5\u770b\u901a\u8fc7pyenv \u5b89\u88c5\u7684\u6240\u6709\u7248\u672cpython\uff08\u5305\u542b\u7cfb\u7edf\u81ea\u5e26\uff09\u3002\u5f53\u524d\u751f\u6548\u7684python\u7248\u672c\u524d\u4f1a\u663e\u793a\u201c<strong>*<\/strong>\u201d\uff0c\u7528\u4e8e\u6807\u8bb0\u3002<\/p>\n\n\n\n<h4>2.3\u3001pyenv version<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u279c  ~ pyenv version\n2.7.12 (set by \/Users\/humh\/.pyenv\/version)<\/pre>\n\n\n\n<p><code>pyenv version<\/code>\u4ec5\u8f93\u51fa\u5f53\u524d\u751f\u6548\u7684python\u7248\u672c\u3002<\/p>\n\n\n\n<h4>2.4\u3001pyenv global<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u279c  ~ pyenv version\n2.7.12 (set by \/Users\/humh\/.pyenv\/version)\n\u279c  ~ pyenv versions\n  system\n* 2.7.12 (set by \/Users\/humh\/.pyenv\/version)\n  3.7.0\n\u279c  ~ python -V\nPython 2.7.12\n\u279c  ~ pyenv global 3.7.0\n\u279c  ~ pyenv versions\n  system\n  2.7.12\n* 3.7.0 (set by \/Users\/humh\/.pyenv\/version)\n\u279c  ~ python -V\nPython 3.7.0<\/pre>\n\n\n\n<p><code>pyenv global<\/code>\u53ef\u4ee5\u8bbe\u7f6e\u5168\u5c40python\uff0c\u5373\u6307\u5b9a\u67d0\u4e00\u7248\u672c\u5728\u5168\u5c40\u751f\u6548\u3002\u5982\u4e0a\u64cd\u4f5c\uff0c\u53ef\u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n\n\n\n<p>\u5982\u679cpyenv global $v \u540e\uff0cpyenv versions \u67e5\u770b\u751f\u6548\u4e86\uff0c\u4f46python\uff0c\u672a\u751f\u6548\uff0c\u9700\u8981\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u914d\u7f6e <strong>$HOME\/.pyenv\/bin<\/strong>\uff0c\u6700\u7ec8\u8f93\u5165python\uff0c\u4f1a\u901a\u8fc7\u57ab\u7247\u673a\u5236\uff0c\u4f1a\u5148\u627e\u5230pyenv\u4e2d\u914d\u7f6e\u7684python version\uff0c\u4f7f\u7528\u5bf9\u5e94\u7248\u672cpython\u3002<\/p>\n\n\n\n<p>\u5173\u4e8e<code>pyenv local<\/code>\u7684\u4f7f\u7528\uff0c\u89c1\u4e0b\u6587\u9610\u8ff0\u3002<\/p>\n\n\n\n<h2>\u4e8c\u3001pyenv virtualenv<\/h2>\n\n\n\n<p>\u5f80\u5f80\u5728\u5f00\u53d1\u4e2d\uff0c\u4f60\u53ef\u80fd\u9047\u5230\u8fd9\u6837\u4e00\u79cd\u60c5\u51b5\uff0c\u591a\u4e2a\u9879\u76ee\u5171\u7528\u7684\u662f\u540c\u4e00\u4e2a\u7248\u672c\u7684python\uff0c\u5982\u679c\u4e0d\u540c\u9879\u76ee\u4e2d\u90fd\u4f7f\u7528\u4e86\u67d0\u4e2apip\u4f9d\u8d56\uff0c\u4f46\u7248\u672c\u5374\u4e0d\u540c\uff0c\u8fd9\u662f\u5c31\u65e0\u6cd5\u89e3\u51b3\u4e86\uff0c\u5c31\u7b97\u6ca1\u6709\u7248\u672c\u51b2\u7a81\uff0c\u591a\u4e2a\u9879\u76ee\u7684\u4f9d\u8d56\u5305\u4e5f\u4f1a\u6253\u5165\u540c\u4e00<strong>site-package<\/strong>\u8def\u5f84\u4e0b\uff0c\u8fd9\u6837\u4f1a\u5f88\u81c3\u80bf\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u51fa\u73b0\u4e86<strong>virtualenv<\/strong>\u5de5\u5177\uff0c\u5b83\u5728\u540c\u4e00python\u7248\u672c\u7684\u57fa\u7840\u4e0a\uff0c\u5f88\u597d\u9694\u79bb\u9879\u76ee\u73af\u5883\u3002\u4f1a\u5728\u9879\u76ee\u8def\u5f84\u4e0b\uff0c\u751f\u6210venv\u76ee\u5f55\u3002\u539f\u7406\u5c31\u662f\uff0c\u5b83\u76f8\u5f53\u4e8e\u4e3a\u6bcf\u4e00\u4e2a\u9879\u76ee\uff0c\u62f7\u8d1d\u4e86\u4e00\u4efdpython\u81f3\u9879\u76ee\u4e0b\uff0c\u6240\u4ee5\u770b\u4f3c\u662f\u4f7f\u7528\u7684\u540c\u4e00\u4e2apython\uff0c\u5b9e\u5219\u662f\u4f7f\u7528\u62f7\u8d1d\u7684python\u3002\u8fd9\u6837\u6bcf\u4e2a\u9879\u76ee\u7684\u4f9d\u8d56\u5305\u90fd\u4f1a\u5b58\u5728\u9879\u76ee\u81ea\u8eab\u7684python\u8def\u5f84\u4e2d\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8epyenv\u6765\u8bf4\uff0c\u540c\u6837\u5b58\u5728\u8fd9\u6837\u9700\u6c42\uff0c\u6839\u636e\u7c7b\u4f3c\u7684\u539f\u7406\uff0c\u51fa\u73b0\u4e86pyenv-virtualenv\u5de5\u5177\u3002<\/p>\n\n\n\n<h3>1\u3001 \u5b89\u88c5<\/h3>\n\n\n\n<p>\u4ee5mac\u4e3a\u4f8b\uff0c\u901a\u8fc7<code>brew install pyenv-virtualenv<\/code>\u5373\u53ef\u5b89\u88c5\u3002\u5176\u4ed6\u60c5\u51b5\uff0c\u53ef\u81ea\u884c\u767e\u5ea6\uff0c\u6682\u672a\u5b9e\u8df5\u3002<\/p>\n\n\n\n<h4>2\u3001\u4f7f\u7528<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u279c  ~ pyenv virtualenv 3.7.0 humh_python\nLooking in links: \/var\/folders\/..\nRequirement already satisfied: setuptools in \/Users\/humh\/.pyenv\/versions\/3.7.0\/envs\/humh_python\/lib\/python3.7\/site-packages (39.0.1)\nRequirement already satisfied: pip in \/Users\/humh\/.pyenv\/versions\/3.7.0\/envs\/humh_python\/lib\/python3.7\/site-packages (10.0.1)\n\u279c  ~ pyenv versions\n  system\n  2.7.12\n* 3.7.0 (set by \/Users\/humh\/.pyenv\/version)\n  3.7.0\/envs\/humh_python\n  humh_python<\/pre>\n\n\n\n<p>\u5728\u901a\u8fc7pyenv\u5df2\u7ecf\u5b89\u88c5\u4e86\u67d0\u4e2a\u7248\u672c\u7684python\u540e\uff0c\u901a\u8fc7<code>pyenv virtualenv 3.7.0 humh_python<\/code>\u5373\u53ef\u521b\u5efa\u4e00\u4e2a\u4f7f\u7528\u7248\u672c3.7.0\u7684\u865a\u62df\u73af\u5883\uff0c\u8fd9\u91cc\u4f60\u53ea\u9700\u5c063.7.0\u548chumh_python \u6362\u6210\u4f60\u9700\u8981\u7684python\u7248\u672c\u53f7\u4ee5\u53ca\u865a\u62df\u73af\u5883\u540d\u5373\u53ef\uff0c\u4e00\u822c\u865a\u62df\u73af\u5883\u540d\u8ddf\u4f60\u7684\u9879\u76ee\u540d\u5173\u8054\u547d\u540d\u3002<\/p>\n\n\n\n<p><code>pyenv versions<\/code>\u4f1a\u8f93\u51fa\u4f60\u7684\u865a\u62df\u73af\u5883\u201chumh_python\u201d\uff0c\u8fd9\u91cc\u4f60\u5e94\u8be5\u6ce8\u610f\u5230\u4e86\uff0c\u8fd8\u989d\u5916\u8f93\u51fa\u4e86\u201c3.7.0\/envs\/humh_python\u201d\uff0c\u4f60\u53ef\u80fd\u4f1a\u597d\u5947\u8fd9\u662f\u4ec0\u4e48\uff0c\u6211\u4eec\u4e0d\u59a8\u8fdb\u5165pyenv\u7684\u76ee\u5f55\u4e2d\u770b\u770b\uff0c\u8fdb\u5165\u4f60\u5f53\u524d\u7528\u6237\u7684\u5bb6\u76ee\u5f55\uff0cpyenv\u5de5\u4f5c\u76ee\u5f55\u4e3a\u201c<strong>.pyenv<\/strong>\u201d (<code>ls -a ~\/<\/code>\u5373\u53ef\u770b\u5230)<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u279c  ~ cd .pyenv\n\u279c  .pyenv ls\ncache    shims    version  versions\n\u279c  .pyenv ls cache\nPython-2.7.12.tar.xz   Python-2.7.12.tar.xz.1 Python-2.7.12.tar.xz.2 Python-2.7.12.tar.xz.3 Python-2.7.12.tar.xz.4 Python-3.7.0.tar.xz    openssl-1.0.2k.tar.gz\n\u279c  .pyenv ls shims\n......\n\u279c  .pyenv cat version\n3.7.0\n\u279c  .pyenv pyenv version\n3.7.0 (set by \/Users\/humh\/.pyenv\/version)\n\u279c  .pyenv ls versions\n2.7.12      3.7.0       humh_python\n\u279c  .pyenv ls versions\/3.7.0\nbin     envs    include lib     share\n\u279c  .pyenv ls versions\/3.7.0\/envs\/\ncvdata      humh_python test\n\u279c  .pyenv ls versions\/3.7.0\/envs\/humh_python\nbin        include    lib        pyvenv.cfg\n\u279c  .pyenv ll versions\/\ntotal 64\ndrwxr-xr-x  8 humh  staff   272B  7 16 09:16 2.7.12\ndrwxr-xr-x  7 humh  staff   238B  8 30 15:24 3.7.0\nlrwxr-xr-x  1 humh  staff    50B 10 20 19:58 humh_python -&gt; \/Users\/humh\/.pyenv\/versions\/3.7.0\/envs\/humh_python<\/pre>\n\n\n\n<p>\u7ed3\u5408\u4e0a\u8ff0shell\u5185\u5bb9\uff0c\u9610\u8ff0\u4e0bpyenv\u7684\u76ee\u5f55\u7ed3\u6784\u3002<\/p>\n\n\n\n<ul><li>cache\uff1a\u8be5\u76ee\u5f55\u4e0b\uff0c\u4e3a\u901a\u8fc7pyenv\u5b89\u88c5\u7684\u6240\u6709\u7248\u672cpython\u5b89\u88c5\u5305\u3002<\/li><li>shims\uff1a\u672a\u77e5<\/li><li>version\uff1a\u6ce8\u610f\uff0c\u975e\u76ee\u5f55\uff0c\u800c\u662ffile\uff0cfile\u5185\u5bb9\u4e3a\u5f53\u524d\u5168\u5c40python\u7248\u672c\u53f7\uff0c\u5373\u5bf9\u5e94<code>pyenv global<\/code><\/li><li>versions\uff1a\u8be5\u76ee\u5f55\u4e0b\u5305\u542b\u4e86\u5b89\u88c5\u540e\u7684\u4e0d\u540c\u7248\u672cpython\uff0c\u5e76\u4e14\u8fd8\u6709\u521b\u5efa\u7684\u865a\u62df\u73af\u5883\u5185\u5bb9\u3002\u62ff3.7.0\u7248\u672c\u4e3a\u4f8b\uff0c\u53ef\u4ee5\u770b\u5230\u9664\u4e863.7.0python\u81ea\u8eab\u7684\u76ee\u5f55\uff08bin\/\u3001include\/\u3001lib\/ \u4ee5\u53ca share\/\uff09\uff0c\u591a\u4e86\u4e00\u4e2a\u201c<strong>envs\/<\/strong>\u201d\u76ee\u5f55\uff0c\u8be5\u76ee\u5f55\u4e0b\u5305\u542b\u4e86\u4e00\u4e2a\u201chumh_python\u201d\u7684\u76ee\u5f55\uff0c\u5176\u76ee\u5f55\u4e0b\u7684\u5185\u5bb9\u53c8\u4e0e3.7.0 python\u81ea\u8eab\u5185\u5bb9\u4e00\u81f4\u3002\u800cversions\u4e0b\u7684\u201chumh_python\u201d\u53c8\u662f\u8f6f\u94fe\u81f33.7.0\/envs\/humh_python\u7684\u3002\u6240\u4ee5\u4e0d\u96be\u7406\u89e3\uff0cpyenv-virtualenv \u5de5\u5177\u7684\u4f5c\u7528\u4e0evirtualenv\u7c7b\u4f3c\uff0c\u4e5f\u662f\u5c06\u865a\u62df\u73af\u5883\u5bf9\u5e94python\u62f7\u8d1d\u4e86\u4e00\u4efd\uff0c\u865a\u62df\u73af\u5883\u64cd\u4f5c\u7684\u662f\u62f7\u8d1d\u540e\u7684python\uff0c\u5df2\u8fbe\u5230python\u9694\u79bb\u7684\u76ee\u7684\u3002<\/li><\/ul>\n\n\n\n<p>\u90a3\u4e48\u5982\u4f55\u4f7f\u5f97\u865a\u62df\u73af\u5883\u751f\u6548\u5462\uff1fpyenv virtualenv\u63d0\u4f9b\u4e86\u4e24\u79cd\u65b9\u5f0f\uff08\u8fd9\u91cc\u5747\u4ee5\u201chumh_python\u201d\u4f5c\u4e3a\u865a\u62df\u73af\u5883\u540d\u4e3e\u4f8b\uff09\uff1a<\/p>\n\n\n\n<p><strong>pyenv activate &#8216;\u865a\u62df\u73af\u5883\u540d&#8217;  &amp;&amp; pyenv deactivate &#8216;\u865a\u62df\u73af\u5883\u540d&#8217;<\/strong><\/p>\n\n\n\n<p>\u5982\u540cvirtualenv\u7684\u4f7f\u7528\u662f\u4e00\u6837\u7684\uff0c\u5f53\u8fdb\u5165\u9879\u76ee\u8def\u5f84\u4e0b\uff0c<code>pyenv activate humh_python<\/code>\u5c31\u53ef\u4ee5\u6fc0\u6d3b\u201chumh_python\u201d\u7684\u865a\u62df\u73af\u5883\uff0c<code>pyenv deactivate humh_python<\/code>\u9000\u51fa\u201chumh_python\u201d\u7684\u865a\u62df\u73af\u5883\u3002<\/p>\n\n\n\n<p><strong>pyenv local &#8216;\u865a\u62df\u73af\u5883\u540d&#8217;<\/strong><\/p>\n\n\n\n<p>\u5728\u9879\u76ee\u8def\u5f84\u4e0b\uff0c\u952e\u5165<code>pyenv local humh_python<\/code>\u5373\u53ef\u4f7f\u5f53\u524d\u9879\u76ee\u542f\u7528humh_python\u7684\u865a\u62df\u73af\u5883\u3002<\/p>\n\n\n\n<p><strong>\u4e8c\u8005\u7684\u533a\u522b\uff01\uff01<\/strong><\/p>\n\n\n\n<p>\u6ce8\u610f\uff0c\u4e0a\u8ff0\u4e24\u79cd\u65b9\u5f0f\uff0c\u5747\u53ef\u4ee5\u6ee1\u8db3\u4f60\u5bf9\u865a\u62df\u73af\u5883\u7684\u9700\u6c42\uff0c\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\uff0c\u4f5c\u7528\u57df\u4e0e\u539f\u7406\u4e0d\u540c\u3002<br><code>pyenv activate<\/code>\u662f\u5728\u5f53\u524d\u4f1a\u8bddsession\u5168\u5c40\u4e0b\u542f\u7528\u6b64\u865a\u62df\u73af\u5883\uff0c\u65e0\u8bba\u4f60\u662f\u5426\u5728\u4f60\u7684\u9879\u76ee\u76ee\u5f55\u4e0b\uff0c\u53ea\u8981\u6ca1\u6709deactivate\uff0c\u4e00\u76f4\u4f7f\u7528\u7684\u662f\u6b64\u865a\u62df\u73af\u5883\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/file.blog.humh.cn\/2020\/11\/d2b5ca33bd970f64a6301fa75ae2eb22-11.png\"><img width=\"1166\" height=\"234\" class=\"wp-image-831 lazyload\" title=\"python\u7248\u672c\u7ba1\u7406\u4e0e\u865a\u62df\u73af\u5883\" src=\"data:image\/gif;base64,R0lGODlhAgABAIAAALGxsQAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==\" data-src=\"https:\/\/file.blog.humh.cn\/2020\/11\/d2b5ca33bd970f64a6301fa75ae2eb22-11.png\" alt=\"https:\/\/file.blog.humh.cn\/2020\/11\/d2b5ca33bd970f64a6301fa75ae2eb22-11.png\" data-srcset=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2020\/11\/d2b5ca33bd970f64a6301fa75ae2eb22-11.png 1166w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2020\/11\/d2b5ca33bd970f64a6301fa75ae2eb22-11-300x60.png 300w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2020\/11\/d2b5ca33bd970f64a6301fa75ae2eb22-11-1024x206.png 1024w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2020\/11\/d2b5ca33bd970f64a6301fa75ae2eb22-11-768x154.png 768w\" sizes=\"(max-width: 1166px) 100vw, 1166px\"><\/a><\/figure><\/div>\n\n\n\n<p>\u5982\u4e0a\u56fe\uff0c\u53ef\u4ee5\u770b\u5230\uff0c\u5728\u5de6\u8fb9\u4f1a\u8bdd\u4e2d\uff0c\u5728test\u9879\u76ee\u4e0b\u5f00\u542f\u865a\u62df\u73af\u5883\uff0c\u53f3\u8fb9\u4f1a\u8bdd\u662f\u4e0d\u4f1a\u8d77\u4f5c\u7528\u7684\u3002\u540c\u65f6\uff0c\u5de6\u8fb9\u4f1a\u8bdd\u5207\u51fa\u9879\u76ee\u76ee\u5f55\uff0c\u865a\u62df\u73af\u5883\u4ecd\u7136\u751f\u6548\u3002\u53ef\u4ee5\u7406\u89e3<code>pyenv active<\/code>\u539f\u7406\u662f\u6539\u53d8\u4e86\u5f53\u524d\u7528\u6237\u73af\u5883\u53d8\u91cf\u4e2d\u7684python\u53d8\u91cf\u3002<\/p>\n\n\n\n<p>\u5728\u6307\u5b9a\u9879\u76ee\u8def\u5f84\u4e0b\uff0c<code>pyenv local<\/code>\uff0c\u8be5python version\u4ec5\u5728\u5f53\u524d\u8def\u5f84\u4e0b\u6709\u6548,\u9000\u51fa\u5219\u4e3a\u7cfb\u7edfversion\uff0c\u65e0\u9700\u5728pyenv activate \u548cdeactivate\uff0c\u5982\u4e0b\u56fe\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/file.blog.humh.cn\/2020\/11\/d2b5ca33bd970f64a6301fa75ae2eb22-12.png\"><img width=\"431\" height=\"275\" class=\"wp-image-832 lazyload\" title=\"python\u7248\u672c\u7ba1\u7406\u4e0e\u865a\u62df\u73af\u5883\" src=\"data:image\/gif;base64,R0lGODlhAgABAIAAALGxsQAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==\" data-src=\"https:\/\/file.blog.humh.cn\/2020\/11\/d2b5ca33bd970f64a6301fa75ae2eb22-12.png\" alt=\"https:\/\/file.blog.humh.cn\/2020\/11\/d2b5ca33bd970f64a6301fa75ae2eb22-12.png\" data-srcset=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2020\/11\/d2b5ca33bd970f64a6301fa75ae2eb22-12.png 574w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2020\/11\/d2b5ca33bd970f64a6301fa75ae2eb22-12-300x191.png 300w\" sizes=\"(max-width: 431px) 100vw, 431px\"><\/a><\/figure><\/div>\n\n\n\n<p><code>pyenv local<\/code>\u7684\u539f\u7406\u662f\u5728\u5f53\u524d\u9879\u76ee\u8def\u5f84\u4e0b\uff0c\u751f\u6210\u4e00\u4e2a\u201c.python-version\u201d\u6587\u4ef6\uff0c\u5185\u5bb9\u5c31\u662f\u9700\u751f\u6548\u7684python\u865a\u62df\u73af\u5883\u540d\u3002\u5f53\u8fdb\u5165\u9879\u76ee\u8def\u5f84\u4e0b\uff0c\u5982\u679c\u5b58\u5728\u8fd9\u4e2a\u6587\u4ef6\uff0c\u5219\u5c31\u4f1a\u6539\u53d8python\u73af\u5883\u53d8\u91cf\uff0c\u5c31\u50cf\u4e00\u4e2a\u5c40\u90e8\u53d8\u91cf\u4e00\u6837\uff0c\u8fd9\u4e5f\u5c31\u5bfc\u81f4<code>pyenv local<\/code>\u7684\u865a\u62df\u73af\u5883\u53ea\u80fd\u5728\u67d0\u4e2a\u76ee\u5f55\u4e0b\u751f\u6548\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u603b\u7ed3\u4e0b\u5173\u4e8epyenv\u4ee5\u53cavirtualenv\u7684\u7406\u89e3 \u4e00\u822c\u7cfb\u7edf\u4f1a\u81ea\u5e26\u4e00\u4e2apython2\u7248\u672c\u7684python\uff0c\u5728\u5b9e\u9645 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":835,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[66],"tags":[65],"_links":{"self":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/730"}],"collection":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=730"}],"version-history":[{"count":15,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/730\/revisions"}],"predecessor-version":[{"id":1158,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/730\/revisions\/1158"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/media\/835"}],"wp:attachment":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}