{"id":1009193,"date":"2024-12-27T11:09:38","date_gmt":"2024-12-27T03:09:38","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1009193.html"},"modified":"2024-12-27T11:09:40","modified_gmt":"2024-12-27T03:09:40","slug":"mac%e5%a6%82%e4%bd%95%e6%89%93%e5%bc%80python%e7%bb%88%e7%ab%af","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1009193.html","title":{"rendered":"Mac\u5982\u4f55\u6253\u5f00python\u7ec8\u7aef"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25084220\/29eaee93-8413-41c4-acf7-4e04ea921442.webp\" alt=\"Mac\u5982\u4f55\u6253\u5f00python\u7ec8\u7aef\" \/><\/p>\n<p><p> <strong>\u5728Mac\u4e0a\u6253\u5f00Python\u7ec8\u7aef\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u5185\u7f6e\u7684\u7ec8\u7aef\u5e94\u7528\u7a0b\u5e8f\u3001\u901a\u8fc7Anaconda\u6216\u5176\u4ed6Python\u73af\u5883\u7ba1\u7406\u5de5\u5177\u3001\u4f7f\u7528IDE\uff08\u5982PyCharm\u6216Visual Studio Code\uff09\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u5185\u7f6e\u7ec8\u7aef\u6253\u5f00Python\u7ec8\u7aef\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u5185\u7f6e\u7ec8\u7aef\u6253\u5f00Python\u7ec8\u7aef\u662f\u6700\u5e38\u7528\u4e14\u7b80\u5355\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u60a8\u53ef\u4ee5\u5728Mac\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u627e\u5230\u201c\u7ec8\u7aef\u201d\u5e76\u6253\u5f00\u5b83\u3002\u7ec8\u7aef\u662fMac\u7cfb\u7edf\u81ea\u5e26\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u5b83\u5141\u8bb8\u60a8\u901a\u8fc7\u547d\u4ee4\u884c\u4e0e\u8ba1\u7b97\u673a\u8fdb\u884c\u4ea4\u4e92\u3002\u6253\u5f00\u7ec8\u7aef\u540e\uff0c\u53ea\u9700\u8f93\u5165<code>python3<\/code>\u6216<code>python<\/code>\u547d\u4ee4\u5373\u53ef\u542f\u52a8Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0cmacOS\u7cfb\u7edf\u4e2d\u9ed8\u8ba4\u5b89\u88c5\u4e86Python\uff0c\u4f46\u901a\u5e38Python 2.x\u7248\u672c\u5df2\u4e0d\u518d\u63a8\u8350\u4f7f\u7528\uff0c\u56e0\u6b64\u5efa\u8bae\u4f7f\u7528<code>python3<\/code>\u6765\u542f\u52a8Python 3.x\u7248\u672c\u7684\u89e3\u91ca\u5668\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u6b65\u9aa4\u548c\u64cd\u4f5c\u8bf4\u660e\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u5185\u7f6e\u7ec8\u7aef\u5e94\u7528\u7a0b\u5e8f<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u7ec8\u7aef<\/strong><\/p>\n<\/p>\n<p><p>\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u6253\u5f00\u7ec8\u7aef\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u6587\u4ef6\u5939\u4e2d\u627e\u5230\u201c\u5b9e\u7528\u5de5\u5177\u201d\u6587\u4ef6\u5939\uff0c\u7136\u540e\u53cc\u51fb\u6253\u5f00\u201c\u7ec8\u7aef\u201d\u3002<\/li>\n<li>\u4f7f\u7528Spotlight\u641c\u7d22\uff1a\u6309\u4e0b\u201cCommand + \u7a7a\u683c\u201d\u952e\uff0c\u8f93\u5165\u201c\u7ec8\u7aef\u201d\uff0c\u7136\u540e\u6309\u56de\u8f66\u952e\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u542f\u52a8Python\u89e3\u91ca\u5668<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u7ec8\u7aef\u7a97\u53e3\u4e2d\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u542f\u52a8Python 3\u89e3\u91ca\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u7684\u7cfb\u7edf\u4e0aPython 3\u672a\u88ab\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u7248\u672c\uff0c\u90a3\u4e48\u8f93\u5165<code>python<\/code>\u53ef\u80fd\u4f1a\u542f\u52a8Python 2.x\u7248\u672c\u3002\u786e\u4fdd\u4f7f\u7528<code>python3<\/code>\u4ee5\u542f\u52a8Python 3\u7684\u89e3\u91ca\u5668\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9000\u51faPython\u89e3\u91ca\u5668<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4ea4\u4e92\u5f0f\u73af\u5883\u4e2d\uff0c\u60a8\u53ef\u4ee5\u6267\u884cPython\u4ee3\u7801\u3002\u8981\u9000\u51faPython\u89e3\u91ca\u5668\uff0c\u8bf7\u6309\u4e0b\u201cCtrl + D\u201d\u6216\u8f93\u5165<code>exit()<\/code>\u5e76\u6309\u56de\u8f66\u952e\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u901a\u8fc7Anaconda\u6216\u5176\u4ed6Python\u73af\u5883\u7ba1\u7406\u5de5\u5177<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Anaconda<\/strong><\/p>\n<\/p>\n<p><p>Anaconda\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python\u53d1\u884c\u7248\uff0c\u5305\u542b\u4e86\u5927\u91cf\u7684\u79d1\u5b66\u8ba1\u7b97\u5305\uff0c\u5e76\u4e14\u5e26\u6709\u73af\u5883\u7ba1\u7406\u5de5\u5177\u3002\u60a8\u53ef\u4ee5\u4eceAnaconda\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5b89\u88c5\u5305\u5e76\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Anaconda\u6253\u5f00Python\u7ec8\u7aef<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5Anaconda\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u542f\u52a8Python\u89e3\u91ca\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda activate base<\/p>\n<p>python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u542f\u52a8Anaconda\u7ba1\u7406\u7684Python\u73af\u5883\u4e2d\u7684\u89e3\u91ca\u5668\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528IDE\uff08\u5982PyCharm\u6216Visual Studio Code\uff09<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5IDE<\/strong><\/p>\n<\/p>\n<p><p>\u60a8\u53ef\u4ee5\u9009\u62e9\u5b89\u88c5\u4e00\u4e2a\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\uff0c\u5982PyCharm\u6216Visual Studio Code\uff0c\u8fd9\u4e9b\u5de5\u5177\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u4ee3\u7801\u7f16\u8f91\u548c\u8c03\u8bd5\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5728IDE\u4e2d\u914d\u7f6ePython\u89e3\u91ca\u5668<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728PyCharm\u4e2d\uff1a\u5728\u201cPreferences\u201d\u4e2d\u9009\u62e9\u201cProject Interpreter\u201d\uff0c\u7136\u540e\u9009\u62e9\u6216\u6dfb\u52a0Python\u89e3\u91ca\u5668\u3002<\/li>\n<li>\u5728Visual Studio Code\u4e2d\uff1a\u5b89\u88c5Python\u6269\u5c55\uff0c\u5e76\u4f7f\u7528\u547d\u4ee4\u9762\u677f\uff08Command Palette\uff09\u9009\u62e9Python\u89e3\u91ca\u5668\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u7ec8\u7aef<\/strong><\/p>\n<\/p>\n<p><p>\u5728IDE\u4e2d\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884cPython\u6587\u4ef6\u6216\u6253\u5f00\u7ec8\u7aef\u4ee5\u4f7f\u7528Python\u89e3\u91ca\u5668\u3002\u5927\u591a\u6570IDE\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684\u7ec8\u7aef\u6216\u96c6\u6210\u7ec8\u7aef\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u68c0\u67e5\u548c\u7ba1\u7406Python\u7248\u672c<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5Python\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u67e5\u770b\u7cfb\u7edf\u4e0a\u5b89\u88c5\u7684Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python --version<\/p>\n<p>python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u6216\u66f4\u65b0Python<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u7684\u7cfb\u7edf\u672a\u5b89\u88c5Python 3\uff0c\u6216\u60a8\u5e0c\u671b\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\uff0c\u60a8\u53ef\u4ee5\u4ecePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684Python\uff0c\u5e76\u6839\u636e\u5b89\u88c5\u5411\u5bfc\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8bbe\u7f6e\u9ed8\u8ba4Python\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u60a8\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539<code>.bash_profile<\/code>\u6216<code>.zshrc<\/code>\u6587\u4ef6\u6765\u5c06Python 3\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u7248\u672c\u3002\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">alias python=&quot;python3&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u6587\u4ef6\u540e\uff0c\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source ~\/.bash_profile<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source ~\/.zshrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u9700\u8981\u5728\u591a\u4e2aPython\u7248\u672c\u4e4b\u95f4\u5207\u6362\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pyenv<\/code>\u7b49\u5de5\u5177\u8fdb\u884c\u7248\u672c\u7ba1\u7406\u3002\u5b89\u88c5<code>pyenv<\/code>\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u548c\u5207\u6362Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv install 3.x.x<\/p>\n<p>pyenv global 3.x.x<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5728Mac\u4e0a\u6253\u5f00Python\u7ec8\u7aef\u5e76\u8fdb\u884cPython\u7f16\u7a0b\u3002\u9009\u62e9\u9002\u5408\u60a8\u5f00\u53d1\u73af\u5883\u548c\u5de5\u4f5c\u6d41\u7a0b\u7684\u65b9\u5f0f\u662f\u63d0\u9ad8\u751f\u4ea7\u529b\u7684\u5173\u952e\u3002\u65e0\u8bba\u662f\u901a\u8fc7\u5185\u7f6e\u7ec8\u7aef\u3001\u73af\u5883\u7ba1\u7406\u5de5\u5177\uff0c\u8fd8\u662fIDE\uff0c\u90fd\u53ef\u4ee5\u6ee1\u8db3\u4e0d\u540c\u5c42\u6b21\u7684Python\u5f00\u53d1\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Mac\u4e0a\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5728Mac\u4e0a\u5b89\u88c5Python\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684\u5b89\u88c5\u5305\u3002\u6b64\u5916\uff0cMac\u7cfb\u7edf\u901a\u5e38\u9884\u88c5\u6709Python 2.x\u7248\u672c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Homebrew\u5305\u7ba1\u7406\u5668\u8f7b\u677e\u5b89\u88c5\u6700\u65b0\u7684Python 3.x\u7248\u672c\u3002\u53ea\u9700\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>brew install python<\/code>\u5373\u53ef\u5b8c\u6210\u5b89\u88c5\u3002<\/p>\n<p><strong>\u6253\u5f00Python\u7ec8\u7aef\u540e\uff0c\u6211\u8be5\u5982\u4f55\u8fd0\u884cPython\u4ee3\u7801\uff1f<\/strong><br \/>\u4e00\u65e6\u60a8\u6253\u5f00\u4e86Python\u7ec8\u7aef\uff08\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\u6765\u542f\u52a8\uff09\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u5e76\u6309\u56de\u8f66\u952e\u6267\u884c\u3002\u5982\u679c\u60a8\u5e0c\u671b\u8fd0\u884c\u4e00\u4e2aPython\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>python filename.py<\/code>\u6216<code>python3 filename.py<\/code>\u6765\u6267\u884c\u8be5\u6587\u4ef6\uff0c\u786e\u4fdd\u5c06&quot;filename.py&quot;\u66ff\u6362\u4e3a\u60a8\u7684\u5b9e\u9645\u6587\u4ef6\u540d\u3002<\/p>\n<p><strong>Mac\u4e2d\u6709\u5176\u4ed6\u65b9\u5f0f\u53ef\u4ee5\u8fd0\u884cPython\u7a0b\u5e8f\u5417\uff1f<\/strong><br \/>\u9664\u4e86\u4f7f\u7528\u7ec8\u7aef\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u6765\u8fd0\u884cPython\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0cPyCharm\u3001Visual Studio Code\u548cJupyter Notebook\u90fd\u662f\u975e\u5e38\u6d41\u884c\u7684\u9009\u62e9\u3002\u8fd9\u4e9b\u5de5\u5177\u63d0\u4f9b\u4e86\u66f4\u53cb\u597d\u7684\u7528\u6237\u754c\u9762\u548c\u66f4\u591a\u529f\u80fd\uff0c\u4f7f\u5f97\u7f16\u5199\u548c\u8c03\u8bd5Python\u4ee3\u7801\u53d8\u5f97\u66f4\u52a0\u9ad8\u6548\u548c\u65b9\u4fbf\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Mac\u4e0a\u6253\u5f00Python\u7ec8\u7aef\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u5185\u7f6e\u7684\u7ec8\u7aef\u5e94\u7528\u7a0b\u5e8f\u3001\u901a\u8fc7Anaconda\u6216\u5176\u4ed6Python\u73af\u5883\u7ba1 [&hellip;]","protected":false},"author":3,"featured_media":1009196,"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\/1009193"}],"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=1009193"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1009193\/revisions"}],"predecessor-version":[{"id":1009200,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1009193\/revisions\/1009200"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1009196"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1009193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1009193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1009193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}