{"id":930373,"date":"2024-12-26T17:15:10","date_gmt":"2024-12-26T09:15:10","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/930373.html"},"modified":"2024-12-26T17:15:13","modified_gmt":"2024-12-26T09:15:13","slug":"mac%e5%a6%82%e4%bd%95%e5%88%87%e6%8d%a2python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/930373.html","title":{"rendered":"mac\u5982\u4f55\u5207\u6362python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065134\/7bfd3df4-5fe8-445d-8acb-3e487edb88be.webp\" alt=\"mac\u5982\u4f55\u5207\u6362python\" \/><\/p>\n<p><p> <strong>\u5728macOS\u4e0a\u5207\u6362Python\u7248\u672c\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u201cpyenv\u201d\u3001\u4fee\u6539\u7cfb\u7edf\u8def\u5f84\u3001\u4f7f\u7528\u201cvirtualenv\u201d\u3001\u4f7f\u7528\u201cAnaconda\u201d\u7b49\u3002\u5176\u4e2d\uff0c\u201cpyenv\u201d\u662f\u6700\u7075\u6d3b\u548c\u63a8\u8350\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u5728\u4e0d\u540c\u9879\u76ee\u95f4\u8f7b\u677e\u5207\u6362Python\u7248\u672c\uff0c\u5e76\u4e14\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u7684Python\u73af\u5883\u3002<\/strong><\/p>\n<\/p>\n<p><p><strong>pyenv\u7684\u8be6\u7ec6\u4f7f\u7528\u65b9\u6cd5\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5pyenv<\/strong>\uff1a\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684macOS\u4e2d\u5b89\u88c5\u4e86Homebrew\uff08\u4e00\u4e2a\u6d41\u884c\u7684macOS\u5305\u7ba1\u7406\u5668\uff09\u3002\u6253\u5f00\u7ec8\u7aef\u5e76\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5pyenv\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew update<\/p>\n<p>brew install pyenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u914d\u7f6eshell\u73af\u5883<\/strong>\uff1a\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u9700\u8981\u914d\u7f6eshell\u4ee5\u4fbf\u5728\u6bcf\u6b21\u542f\u52a8\u65f6\u90fd\u80fd\u4f7f\u7528pyenv\u3002\u6dfb\u52a0\u4ee5\u4e0b\u51e0\u884c\u5230\u4f60\u7684shell\u914d\u7f6e\u6587\u4ef6\u4e2d\uff08\u5982<code>.bash_profile<\/code>\u3001<code>.bashrc<\/code>\u6216<code>.zshrc<\/code>\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u4f60\u4f7f\u7528\u7684shell\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">echo &#39;export PYENV_ROOT=&quot;$HOME\/.pyenv&quot;&#39; &gt;&gt; ~\/.bash_profile<\/p>\n<p>echo &#39;export PATH=&quot;$PYENV_ROOT\/bin:$PATH&quot;&#39; &gt;&gt; ~\/.bash_profile<\/p>\n<p>echo &#39;eval &quot;$(pyenv init --path)&quot;&#39; &gt;&gt; ~\/.bash_profile<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5237\u65b0\u914d\u7f6e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source ~\/.bash_profile<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python\u7248\u672c<\/strong>\uff1a\u4f7f\u7528pyenv\u5b89\u88c5\u4f60\u9700\u8981\u7684Python\u7248\u672c\u3002\u4f8b\u5982\uff0c\u8981\u5b89\u88c5Python 3.8.10\uff0c\u53ef\u4ee5\u6267\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv install 3.8.10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u5168\u5c40\u6216\u672c\u5730Python\u7248\u672c<\/strong>\uff1a\u4f60\u53ef\u4ee5\u9009\u62e9\u8bbe\u7f6e\u5168\u5c40\u7684Python\u7248\u672c\uff0c\u6216\u8005\u4e3a\u7279\u5b9a\u9879\u76ee\u8bbe\u7f6e\u672c\u5730\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p>\u8bbe\u7f6e\u5168\u5c40\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv global 3.8.10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u8bbe\u7f6e\u672c\u5730\u7248\u672c\uff08\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u8fd0\u884c\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv local 3.8.10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5728macOS\u4e0a\u5207\u6362\u4e0d\u540c\u7684Python\u7248\u672c\uff0c\u5e76\u4e14\u53ef\u4ee5\u4e3a\u4e0d\u540c\u9879\u76ee\u6307\u5b9a\u4e0d\u540c\u7684Python\u7248\u672c\uff0c\u8fd9\u6837\u4e0d\u4f1a\u56e0\u4e3a\u7248\u672c\u95ee\u9898\u800c\u5bfc\u81f4\u9879\u76ee\u65e0\u6cd5\u8fd0\u884c\u3002<\/p>\n<\/p>\n<hr>\n<p><p><strong>I\u3001PYENV\u7684\u5b89\u88c5\u548c\u914d\u7f6e<\/strong><\/p>\n<\/p>\n<p><p>pyenv\u662f\u4e00\u4e2a\u7528\u4e8e\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u7684\u5de5\u5177\uff0c\u5c24\u5176\u9002\u5408\u5f00\u53d1\u8005\u5728\u4e0d\u540c\u9879\u76ee\u4e2d\u9700\u8981\u4e0d\u540c\u7248\u672c\u7684Python\u65f6\u4f7f\u7528\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5b89\u88c5pyenv<\/strong>\uff1a\u9996\u5148\uff0c\u786e\u4fddHomebrew\u5df2\u7ecf\u5b89\u88c5\uff0c\u56e0\u4e3a\u5b83\u662f\u5b89\u88c5pyenv\u7684\u524d\u63d0\u3002\u4f7f\u7528Homebrew\u53ef\u4ee5\u7b80\u5355\u5feb\u901f\u5730\u5b89\u88c5pyenv\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew update<\/p>\n<p>brew install pyenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u914d\u7f6eshell\u73af\u5883<\/strong>\uff1a\u4e3a\u4e86\u8ba9pyenv\u5728\u6bcf\u6b21\u542f\u52a8\u7ec8\u7aef\u65f6\u90fd\u80fd\u88ab\u6b63\u786e\u52a0\u8f7d\uff0c\u9700\u8981\u5728shell\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u548c\u521d\u59cb\u5316\u547d\u4ee4\u3002\u8fd9\u5c06\u786e\u4fddpyenv\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u6b63\u5e38\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">echo &#39;export PYENV_ROOT=&quot;$HOME\/.pyenv&quot;&#39; &gt;&gt; ~\/.bash_profile<\/p>\n<p>echo &#39;export PATH=&quot;$PYENV_ROOT\/bin:$PATH&quot;&#39; &gt;&gt; ~\/.bash_profile<\/p>\n<p>echo &#39;eval &quot;$(pyenv init --path)&quot;&#39; &gt;&gt; ~\/.bash_profile<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5237\u65b0\u914d\u7f6e<\/strong>\uff1a\u5b8c\u6210\u914d\u7f6e\u540e\uff0c\u4f7f\u7528source\u547d\u4ee4\u5237\u65b0shell\u914d\u7f6e\u6587\u4ef6\uff0c\u4f7f\u5176\u7acb\u5373\u751f\u6548\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source ~\/.bash_profile<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p><strong>II\u3001\u4f7f\u7528PYENV\u5b89\u88c5\u548c\u7ba1\u7406Python\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>pyenv\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u5b83\u53ef\u4ee5\u8f7b\u677e\u5b89\u88c5\u548c\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\uff0c\u4f7f\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5feb\u901f\u5207\u6362\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5b89\u88c5\u7279\u5b9aPython\u7248\u672c<\/strong>\uff1a\u4f7f\u7528pyenv\u7684install\u547d\u4ee4\u53ef\u4ee5\u5b89\u88c5\u4efb\u610f\u7248\u672c\u7684Python\u3002\u6bd4\u5982\uff0c\u8981\u5b89\u88c5Python 3.8.10\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv install 3.8.10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770b\u53ef\u7528\u7684Python\u7248\u672c<\/strong>\uff1a\u5728\u5b89\u88c5\u4e4b\u524d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770bpyenv\u652f\u6301\u7684\u6240\u6709Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv install --list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u5168\u5c40\u6216\u672c\u5730Python\u7248\u672c<\/strong>\uff1apyenv\u5141\u8bb8\u4f60\u8bbe\u7f6e\u5168\u5c40\u9ed8\u8ba4\u7684Python\u7248\u672c\uff0c\u4e5f\u53ef\u4ee5\u4e3a\u7279\u5b9a\u76ee\u5f55\uff08\u9879\u76ee\uff09\u8bbe\u7f6e\u672c\u5730\u7248\u672c\u3002\u8fd9\u6837\uff0c\u4e0d\u540c\u9879\u76ee\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p>\u8bbe\u7f6e\u5168\u5c40\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv global 3.8.10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u8bbe\u7f6e\u672c\u5730\u7248\u672c\uff08\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u8fd0\u884c\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv local 3.8.10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><p><strong>III\u3001\u8c03\u6574\u7cfb\u7edfPATH\u53d8\u91cf<\/strong><\/p>\n<\/p>\n<p><p>\u5728macOS\u4e0a\uff0c\u7cfb\u7edf\u7684PATH\u53d8\u91cf\u51b3\u5b9a\u4e86\u7ec8\u7aef\u547d\u4ee4\u884c\u5de5\u5177\u7684\u67e5\u627e\u8def\u5f84\u3002\u8c03\u6574PATH\u53ef\u4ee5\u6539\u53d8Python\u7684\u9ed8\u8ba4\u7248\u672c\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u67e5\u770b\u5f53\u524dPython\u8def\u5f84<\/strong>\uff1a\u4f7f\u7528which\u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u7ec8\u7aef\u4f7f\u7528\u7684Python\u8def\u5f84\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">which python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4fee\u6539PATH\u53d8\u91cf<\/strong>\uff1a\u5982\u679c\u5e0c\u671b\u624b\u52a8\u8bbe\u7f6ePython\u7248\u672c\uff0c\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539PATH\u73af\u5883\u53d8\u91cf\uff0c\u5c06\u65b0\u7248\u672c\u7684Python\u8def\u5f84\u6dfb\u52a0\u5230\u524d\u9762\u3002\u5bf9\u4e8e\u67d0\u4e9b\u7528\u6237\u6765\u8bf4\uff0c\u8fd9\u662f\u4e00\u79cd\u7b80\u5355\u6709\u6548\u7684\u65b9\u6cd5\uff0c\u4f46\u4e5f\u6709\u53ef\u80fd\u5e26\u6765\u4e0d\u4fbf\uff0c\u56e0\u4e3a\u9700\u8981\u624b\u52a8\u7ba1\u7406\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PATH=&quot;\/usr\/local\/python3.8\/bin:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u4fee\u6539<\/strong>\uff1a\u786e\u4fdd\u4fee\u6539\u751f\u6548\uff0c\u53ef\u4ee5\u518d\u6b21\u4f7f\u7528which\u547d\u4ee4\u67e5\u770bPython\u8def\u5f84\uff0c\u786e\u8ba4\u662f\u5426\u4e3a\u671f\u671b\u7684\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><p><strong>IV\u3001\u4f7f\u7528VIRTUALENV\u8fdb\u884c\u73af\u5883\u9694\u79bb<\/strong><\/p>\n<\/p>\n<p><p>virtualenv\u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u72ec\u7acbPython\u73af\u5883\u7684\u5de5\u5177\uff0c\u9002\u7528\u4e8e\u9700\u8981\u9694\u79bb\u9879\u76ee\u4f9d\u8d56\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5b89\u88c5virtualenv<\/strong>\uff1a\u9996\u5148\u786e\u4fddpip\u5df2\u7ecf\u5b89\u88c5\uff0c\u7136\u540e\u4f7f\u7528pip\u5b89\u88c5virtualenv\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install virtualenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\uff0c\u4f7f\u7528virtualenv\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\u3002\u53ef\u4ee5\u6307\u5b9aPython\u7248\u672c\u8def\u5f84\u6765\u521b\u5efa\u7279\u5b9a\u7248\u672c\u7684\u73af\u5883\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">virtualenv -p \/usr\/local\/bin\/python3.8 venv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u6240\u6709\u7684Python\u64cd\u4f5c\uff08\u5982\u5b89\u88c5\u5e93\u3001\u8fd0\u884c\u811a\u672c\uff09\u90fd\u5c06\u5728\u8be5\u73af\u5883\u4e2d\u8fdb\u884c\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u5168\u5c40Python\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source venv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5b8c\u6210\u5f00\u53d1\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\uff0c\u8fd4\u56de\u5168\u5c40Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p><strong>V\u3001\u4f7f\u7528Anaconda\u8fdb\u884cPython\u7248\u672c\u7ba1\u7406<\/strong><\/p>\n<\/p>\n<p><p>Anaconda\u662f\u4e00\u4e2a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684Python\u53d1\u884c\u7248\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u9886\u57df\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5b89\u88c5Anaconda<\/strong>\uff1a\u4eceAnaconda\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u9002\u5408macOS\u7684\u5b89\u88c5\u5305\uff0c\u5e76\u6309\u7167\u8bf4\u660e\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efaConda\u73af\u5883<\/strong>\uff1a\u4f7f\u7528conda\u547d\u4ee4\u53ef\u4ee5\u521b\u5efa\u6307\u5b9aPython\u7248\u672c\u7684\u65b0\u73af\u5883\u3002\u8fd9\u5bf9\u4e8e\u9700\u8981\u4f7f\u7528\u7279\u5b9a\u7248\u672cPython\u7684\u9879\u76ee\u6765\u8bf4\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda create --name myenv python=3.8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3bConda\u73af\u5883<\/strong>\uff1a\u6fc0\u6d3b\u540e\uff0c\u6240\u6709\u7684Python\u64cd\u4f5c\u90fd\u5c06\u5728\u8be5\u73af\u5883\u4e2d\u8fdb\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda activate myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ba1\u7406\u73af\u5883<\/strong>\uff1aConda\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u547d\u4ee4\u6765\u7ba1\u7406\u73af\u5883\uff0c\u5305\u62ec\u5b89\u88c5\u5305\u3001\u66f4\u65b0Python\u7248\u672c\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda install numpy<\/p>\n<p>conda update python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9000\u51faConda\u73af\u5883<\/strong>\uff1a\u5b8c\u6210\u5de5\u4f5c\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u9000\u51fa\u5f53\u524d\u73af\u5883\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p><strong>VI\u3001\u603b\u7ed3\u4e0e\u6700\u4f73\u5b9e\u8df5<\/strong><\/p>\n<\/p>\n<p><p>\u5728macOS\u4e0a\u5207\u6362Python\u7248\u672c\u7684\u591a\u79cd\u65b9\u6cd5\u4e2d\uff0cpyenv\u548cAnaconda\u662f\u6700\u4e3a\u63a8\u8350\u7684\u5de5\u5177\u3002\u524d\u8005\u9002\u5408\u5f00\u53d1\u8005\u7075\u6d3b\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\uff0c\u800c\u540e\u8005\u5219\u5728\u6570\u636e\u79d1\u5b66\u9886\u57df\u6709\u7740\u5e7f\u6cdb\u5e94\u7528\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177<\/strong>\uff1a\u6839\u636e\u9879\u76ee\u9700\u6c42\u9009\u62e9\u9002\u5408\u7684\u7248\u672c\u7ba1\u7406\u5de5\u5177\u3002pyenv\u9002\u5408\u9700\u8981\u9891\u7e41\u5207\u6362\u7248\u672c\u7684\u5f00\u53d1\u8005\uff0c\u800cAnaconda\u5219\u9002\u5408\u6570\u636e\u79d1\u5b66\u5bb6\u548c\u7814\u7a76\u4eba\u5458\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4fdd\u6301\u7cfb\u7edf\u73af\u5883\u6574\u6d01<\/strong>\uff1a\u5c3d\u91cf\u907f\u514d\u76f4\u63a5\u4fee\u6539\u7cfb\u7edf\u7684Python\u7248\u672c\uff0c\u4ee5\u9632\u6b62\u5f71\u54cdmacOS\u7cfb\u7edf\u7684\u6b63\u5e38\u8fd0\u884c\u3002\u4f7f\u7528\u5de5\u5177\u521b\u5efa\u9694\u79bb\u7684\u73af\u5883\u662f\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b9a\u671f\u66f4\u65b0\u548c\u7ef4\u62a4<\/strong>\uff1a\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u5de5\u5177\uff0c\u90fd\u9700\u8981\u5b9a\u671f\u66f4\u65b0\uff0c\u786e\u4fdd\u4f7f\u7528\u6700\u65b0\u7684Python\u7248\u672c\u548c\u5e93\uff0c\u4ee5\u83b7\u5f97\u6700\u4f73\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u4e86\u89e3\u548c\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u7ba1\u7406macOS\u4e0a\u7684Python\u73af\u5883\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u9879\u76ee\u7684\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Mac\u4e0a\u5b89\u88c5\u591a\u4e2a\u7248\u672c\u7684Python\uff1f<\/strong><br \/>\u5728Mac\u4e0a\u5b89\u88c5\u591a\u4e2a\u7248\u672c\u7684Python\u53ef\u4ee5\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u5982Homebrew\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u5b89\u88c5Homebrew\u3002\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u5b89\u88c5\u6240\u9700\u7684Python\u7248\u672c\uff0c\u6bd4\u5982<code>brew install python@3.9<\/code>\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>brew link python@3.9 --force<\/code>\u6765\u5207\u6362\u5230\u8be5\u7248\u672c\u3002\u4e3a\u4e86\u65b9\u4fbf\u7ba1\u7406\uff0c\u53ef\u4ee5\u4f7f\u7528pyenv\u5de5\u5177\uff0c\u5b83\u5141\u8bb8\u7528\u6237\u8f7b\u677e\u5730\u5b89\u88c5\u548c\u5207\u6362\u4e0d\u540c\u7248\u672c\u7684Python\u3002<\/p>\n<p><strong>\u5728Mac\u4e0a\u5982\u4f55\u68c0\u67e5\u5f53\u524dPython\u7248\u672c\uff1f<\/strong><br \/>\u8981\u68c0\u67e5\u5f53\u524d\u6b63\u5728\u4f7f\u7528\u7684Python\u7248\u672c\uff0c\u53ef\u4ee5\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u3002\u8fd9\u5c06\u663e\u793a\u5f53\u524d\u9ed8\u8ba4\u7684Python\u7248\u672c\u3002\u5982\u679c\u540c\u65f6\u5b89\u88c5\u4e86\u591a\u4e2a\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>which python<\/code>\u6216<code>which python3<\/code>\u547d\u4ee4\u6765\u67e5\u770b\u5f53\u524d\u4f7f\u7528\u7684Python\u89e3\u91ca\u5668\u8def\u5f84\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Mac\u4e0a\u5207\u6362Python\u7248\u672c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u9879\u76ee\u9700\u6c42\uff1f<\/strong><br \/>\u5728Mac\u4e0a\u5207\u6362Python\u7248\u672c\u53ef\u4ee5\u4f7f\u7528pyenv\u6216virtualenv\u7b49\u5de5\u5177\u3002\u901a\u8fc7pyenv\uff0c\u7528\u6237\u53ef\u4ee5\u5b89\u88c5\u591a\u4e2aPython\u7248\u672c\u5e76\u901a\u8fc7\u547d\u4ee4<code>pyenv global &lt;version&gt;<\/code>\u6216<code>pyenv local &lt;version&gt;<\/code>\u6765\u8bbe\u7f6e\u5168\u5c40\u6216\u9879\u76ee\u7279\u5b9a\u7684Python\u7248\u672c\u3002\u4f7f\u7528virtualenv\u5219\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u786e\u4fdd\u9879\u76ee\u4e4b\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u4e0d\u4f1a\u76f8\u4e92\u5e72\u6270\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728macOS\u4e0a\u5207\u6362Python\u7248\u672c\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u201cpyenv\u201d\u3001\u4fee\u6539\u7cfb\u7edf\u8def\u5f84\u3001\u4f7f\u7528\u201cvirtualenv\u201d\u3001\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":930374,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/930373"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=930373"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/930373\/revisions"}],"predecessor-version":[{"id":930375,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/930373\/revisions\/930375"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/930374"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=930373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=930373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=930373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}