{"id":1022039,"date":"2024-12-27T13:29:54","date_gmt":"2024-12-27T05:29:54","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1022039.html"},"modified":"2024-12-27T13:29:56","modified_gmt":"2024-12-27T05:29:56","slug":"mac%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1022039.html","title":{"rendered":"mac\u4e2d\u5982\u4f55\u5b89\u88c5python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25164426\/f93c4847-592a-4777-8b0c-b23b04a8d57a.webp\" alt=\"mac\u4e2d\u5982\u4f55\u5b89\u88c5python\" \/><\/p>\n<p><p> \u5728Mac\u4e2d\u5b89\u88c5Python\u7684\u6b65\u9aa4\u5e76\u4e0d\u590d\u6742\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a<strong>\u4f7f\u7528\u7cfb\u7edf\u81ea\u5e26\u7684Python\u3001\u901a\u8fc7Homebrew\u5b89\u88c5\u3001\u4ecePython\u5b98\u7f51\u4e0b\u8f7d\u5e76\u5b89\u88c5\u3001\u4f7f\u7528Anaconda\u5b89\u88c5Python\u73af\u5883<\/strong>\u3002\u8fd9\u51e0\u79cd\u65b9\u6cd5\u5404\u6709\u4f18\u52a3\uff0c\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53ef\u4ee5\u6839\u636e\u4e2a\u4eba\u7684\u9700\u8981\u548c\u504f\u597d\u8fdb\u884c\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u51e0\u79cd\u65b9\u6cd5\uff0c\u5e76\u5bf9\u5176\u4e2d\u7684Homebrew\u5b89\u88c5\u65b9\u6cd5\u8fdb\u884c\u8be6\u7ec6\u8bf4\u660e\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528Homebrew\u5b89\u88c5Python\u662f\u4e00\u79cd\u5f88\u53d7\u6b22\u8fce\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3aHomebrew\u662fMac\u4e0a\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u5b89\u88c5\u548c\u7ba1\u7406\u5404\u79cd\u8f6f\u4ef6\u5305\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u4f60\u7684Mac\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Homebrew\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">\/bin\/bash -c &quot;$(curl -fsSL https:\/\/raw.githubusercontent.com\/Homebrew\/install\/HEAD\/install.sh)&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f7f\u7528Homebrew\u5b89\u88c5Python\u53ea\u9700\u7b80\u5355\u5730\u8f93\u5165\u4e00\u6761\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew install python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Homebrew\u4f1a\u81ea\u52a8\u4e0b\u8f7d\u5e76\u5b89\u88c5Python\u7684\u6700\u65b0\u7248\u672c\uff0c\u5e76\u4e14\u4f1a\u81ea\u52a8\u7ba1\u7406Python\u7684\u8def\u5f84\u8bbe\u7f6e\uff0c\u4f7f\u5f97Python\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u76f4\u63a5\u8c03\u7528\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e00\u3001\u4f7f\u7528\u7cfb\u7edf\u81ea\u5e26\u7684Python<\/p>\n<\/p>\n<p><p>MacOS\u7cfb\u7edf\u81ea\u5e26\u6709Python\uff0c\u4f46\u901a\u5e38\u662fPython 2.x\u7248\u672c\uff0c\u800cPython 2.x\u5df2\u7ecf\u505c\u6b62\u66f4\u65b0\u3002\u56e0\u6b64\uff0c\u5982\u679c\u4f60\u7684\u5f00\u53d1\u73af\u5883\u5bf9Python\u7248\u672c\u6709\u7279\u5b9a\u8981\u6c42\uff0c\u5efa\u8bae\u5b89\u88c5Python 3.x\u3002<\/p>\n<\/p>\n<p><p>1.1 \u68c0\u67e5\u7cfb\u7edf\u81ea\u5e26Python\u7248\u672c<\/p>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165 <code>python<\/code> \u6216 <code>python3<\/code> \u6765\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u81ea\u5e26\u7684Python\u7248\u672c\u3002\u901a\u5e38\uff0c<code>python<\/code>\u6307\u7684\u662fPython 2.x\uff0c\u800c<code>python3<\/code>\u6307\u7684\u662fPython 3.x\u3002<\/p>\n<\/p>\n<p><p>1.2 \u4f7f\u7528\u7cfb\u7edf\u81ea\u5e26Python\u7684\u5c40\u9650\u6027<\/p>\n<\/p>\n<p><p>\u867d\u7136\u7cfb\u7edf\u81ea\u5e26\u7684Python\u53ef\u4ee5\u6ee1\u8db3\u57fa\u672c\u7684\u4f7f\u7528\u9700\u6c42\uff0c\u4f46\u7531\u4e8e\u7248\u672c\u8f83\u65e7\uff0c\u53ef\u80fd\u4e0d\u652f\u6301\u4e00\u4e9b\u65b0\u7684\u5e93\u6216\u529f\u80fd\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u7cfb\u7edf\u81ea\u5e26\u7684Python\u8fdb\u884c\u5f00\u53d1\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4e0e\u5176\u4ed6\u8f6f\u4ef6\u7684\u517c\u5bb9\u6027\u95ee\u9898\u3002\u56e0\u6b64\uff0c\u5efa\u8bae\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\u5b89\u88c5Python 3.x\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u901a\u8fc7Homebrew\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>Homebrew\u662fMacOS\u4e0a\u6d41\u884c\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b89\u88c5\u548c\u7ba1\u7406\u5404\u79cd\u8f6f\u4ef6\u5305\uff0c\u5305\u62ecPython\u3002<\/p>\n<\/p>\n<p><p>2.1 \u5b89\u88c5Homebrew<\/p>\n<\/p>\n<p><p>\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u5b89\u88c5Homebrew\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">\/bin\/bash -c &quot;$(curl -fsSL https:\/\/raw.githubusercontent.com\/Homebrew\/install\/HEAD\/install.sh)&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165 <code>brew --version<\/code> \u6765\u9a8c\u8bc1\u662f\u5426\u6210\u529f\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><p>2.2 \u4f7f\u7528Homebrew\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u5b89\u88c5Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew install python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5b89\u88c5Python\u7684\u6700\u65b0\u7248\u672c\uff0c\u5e76\u81ea\u52a8\u914d\u7f6e\u597d\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><p>2.3 \u9a8c\u8bc1Python\u5b89\u88c5<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165 <code>python3 --version<\/code> \u6765\u68c0\u67e5Python\u662f\u5426\u5b89\u88c5\u6210\u529f\u4ee5\u53ca\u5b89\u88c5\u7684\u7248\u672c\u53f7\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4ecePython\u5b98\u7f51\u4e0b\u8f7d\u5e76\u5b89\u88c5<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u5e0c\u671b\u81ea\u5df1\u624b\u52a8\u7ba1\u7406Python\u7248\u672c\uff0c\u53ef\u4ee5\u76f4\u63a5\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7dPython\u5b89\u88c5\u5305\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><p>3.1 \u4e0b\u8f7dPython\u5b89\u88c5\u5305<\/p>\n<\/p>\n<p><p>\u8bbf\u95eePython\u5b98\u65b9\u7f51\u7ad9 <a href=\"https:\/\/www.python.org\/\">Python.org<\/a>\uff0c\u5728\u4e0b\u8f7d\u9875\u9762\u9009\u62e9\u9002\u5408MacOS\u7684Python\u5b89\u88c5\u5305\uff0c\u901a\u5e38\u4e3a.pkg\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>3.2 \u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u53cc\u51fb.pkg\u6587\u4ef6\u6309\u7167\u63d0\u793a\u8fdb\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u53ef\u4ee5\u9009\u62e9\u5b89\u88c5\u8def\u5f84\u4ee5\u53ca\u4e00\u4e9b\u5176\u4ed6\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><p>3.3 \u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u9700\u8981\u624b\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u53ef\u4ee5\u5c06Python\u7684\u8def\u5f84\u6dfb\u52a0\u5230\u7ec8\u7aef\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff08\u5982<code>.bash_profile<\/code>\u6216<code>.zshrc<\/code>\uff09\uff0c\u4ee5\u4fbf\u5728\u7ec8\u7aef\u4e2d\u76f4\u63a5\u4f7f\u7528<code>python3<\/code>\u547d\u4ee4\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528Anaconda\u5b89\u88c5Python\u73af\u5883<\/p>\n<\/p>\n<p><p>Anaconda\u662f\u4e00\u79cd\u5f00\u6e90\u7684Python\u53d1\u884c\u7248\uff0c\u5305\u542b\u4e86\u5f88\u591a\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u975e\u5e38\u9002\u5408\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u673a\u5668\u5b66\u4e60\u3002<\/p>\n<\/p>\n<p><p>4.1 \u4e0b\u8f7dAnaconda<\/p>\n<\/p>\n<p><p>\u8bbf\u95eeAnaconda\u5b98\u7f51 <a href=\"https:\/\/www.anaconda.com\/\">Anaconda.com<\/a>\uff0c\u4e0b\u8f7d\u9002\u5408MacOS\u7684Anaconda\u5b89\u88c5\u5305\u3002<\/p>\n<\/p>\n<p><p>4.2 \u5b89\u88c5Anaconda<\/p>\n<\/p>\n<p><p>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u53cc\u51fb\u5b89\u88c5\u5305\u5e76\u6309\u7167\u63d0\u793a\u8fdb\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u53ef\u4ee5\u9009\u62e9\u5b89\u88c5\u8def\u5f84\u4ee5\u53ca\u662f\u5426\u6dfb\u52a0Anaconda\u5230\u7cfb\u7edf\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><p>4.3 \u4f7f\u7528conda\u7ba1\u7406Python\u73af\u5883<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>conda<\/code>\u547d\u4ee4\u6765\u7ba1\u7406Python\u73af\u5883\u3002<code>conda<\/code>\u662fAnaconda\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u521b\u5efa\u3001\u7ba1\u7406\u548c\u5207\u6362\u4e0d\u540c\u7684Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u9009\u62e9\u9002\u5408\u81ea\u5df1\u7684Python\u5b89\u88c5\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u5b89\u88c5Python\u53d6\u51b3\u4e8e\u4f60\u7684\u5177\u4f53\u9700\u6c42\u548c\u504f\u597d\u3002\u5982\u679c\u4f60\u53ea\u662f\u8fdb\u884c\u4e00\u4e9b\u7b80\u5355\u7684Python\u5f00\u53d1\u5de5\u4f5c\uff0c\u4f7f\u7528Homebrew\u5b89\u88c5\u53ef\u80fd\u662f\u6700\u7b80\u5355\u548c\u65b9\u4fbf\u7684\u9009\u62e9\u3002\u5982\u679c\u4f60\u9700\u8981\u8fdb\u884c\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\uff0cAnaconda\u5219\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002\u5982\u679c\u4f60\u5e0c\u671b\u5b8c\u5168\u638c\u63a7Python\u5b89\u88c5\u7684\u7ec6\u8282\uff0c\u53ef\u4ee5\u9009\u62e9\u4ecePython\u5b98\u7f51\u4e0b\u8f7d\u5e76\u624b\u52a8\u5b89\u88c5\u3002\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u786e\u4fdd\u4f60\u7684\u5f00\u53d1\u73af\u5883\u662f\u6700\u65b0\u548c\u7a33\u5b9a\u7684\uff0c\u8fd9\u5c06\u6709\u52a9\u4e8e\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u9ebb\u70e6\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Mac\u4e0a\u68c0\u67e5\u662f\u5426\u5df2\u7ecf\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5728Mac\u4e0a\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165<code>python3 --version<\/code>\u6216<code>python --version<\/code>\u6765\u68c0\u67e5Python\u662f\u5426\u5df2\u5b89\u88c5\u3002\u5982\u679c\u60a8\u770b\u5230Python\u7684\u7248\u672c\u53f7\uff0c\u8bf4\u660e\u5b83\u5df2\u6210\u529f\u5b89\u88c5\u3002\u5982\u679c\u672a\u5b89\u88c5\uff0c\u7cfb\u7edf\u4f1a\u63d0\u793a\u60a8\u3002<\/p>\n<p><strong>Mac\u4e0a\u5b89\u88c5Python\u7684\u6b65\u9aa4\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u4e3a\u4e86\u5b89\u88c5Python\uff0c\u60a8\u53ef\u4ee5\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684\u5b89\u88c5\u5305\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u53cc\u51fb\u5b89\u88c5\u5305\u5e76\u6309\u7167\u5c4f\u5e55\u4e0a\u7684\u6307\u793a\u5b8c\u6210\u5b89\u88c5\u3002\u6b64\u5916\uff0c\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528Homebrew\u8fd9\u4e00\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u901a\u8fc7\u7ec8\u7aef\u8f93\u5165<code>brew install python<\/code>\u6765\u7b80\u5316\u5b89\u88c5\u8fc7\u7a0b\u3002<\/p>\n<p><strong>\u5728Mac\u4e0a\u5b89\u88c5Python\u540e\uff0c\u5982\u4f55\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff1f<\/strong><br \/>\u5b89\u88c5Python\u540e\uff0c\u901a\u5e38\u9700\u8981\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u4ee5\u4fbf\u5728\u7ec8\u7aef\u4e2d\u76f4\u63a5\u4f7f\u7528Python\u3002\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u6253\u5f00<code>~\/.bash_profile<\/code>\u6216<code>~\/.zshrc<\/code>\u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<code>export PATH=&quot;\/usr\/local\/bin:$PATH&quot;<\/code>\u3002\u4fdd\u5b58\u6587\u4ef6\u540e\uff0c\u6267\u884c<code>source ~\/.bash_profile<\/code>\u6216<code>source ~\/.zshrc<\/code>\u4ee5\u5e94\u7528\u66f4\u6539\u3002\u8fd9\u5c06\u786e\u4fdd\u60a8\u53ef\u4ee5\u76f4\u63a5\u5728\u7ec8\u7aef\u4e2d\u8c03\u7528Python\u547d\u4ee4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Mac\u4e2d\u5b89\u88c5Python\u7684\u6b65\u9aa4\u5e76\u4e0d\u590d\u6742\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u7cfb\u7edf\u81ea\u5e26\u7684Python\u3001\u901a\u8fc7Homebrew [&hellip;]","protected":false},"author":3,"featured_media":1022045,"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\/1022039"}],"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=1022039"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1022039\/revisions"}],"predecessor-version":[{"id":1022048,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1022039\/revisions\/1022048"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1022045"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1022039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1022039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1022039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}