{"id":962062,"date":"2024-12-27T04:04:47","date_gmt":"2024-12-26T20:04:47","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/962062.html"},"modified":"2024-12-27T04:04:49","modified_gmt":"2024-12-26T20:04:49","slug":"%e5%a6%82%e4%bd%95%e6%9f%a5macbook%e8%87%aa%e5%b8%a6python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/962062.html","title":{"rendered":"\u5982\u4f55\u67e5MacBook\u81ea\u5e26python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25104129\/be56c5f4-a2a4-4bd7-9bd9-454c8d4419ed.webp\" alt=\"\u5982\u4f55\u67e5MacBook\u81ea\u5e26python\" \/><\/p>\n<p><p> <strong>\u8981\u67e5\u627eMacBook\u81ea\u5e26\u7684Python\u7248\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165\u547d\u4ee4\u6765\u5b9e\u73b0\u3002\u901a\u5e38\uff0cMacBook\u4e0a\u9884\u88c5\u7684Python\u7248\u672c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u5de5\u5177\u6765\u67e5\u770b\u3001\u9a8c\u8bc1\u548c\u4f7f\u7528\uff0c\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u6253\u5f00\u7ec8\u7aef\u3001\u8f93\u5165Python\u7248\u672c\u67e5\u8be2\u547d\u4ee4\u3001\u4e86\u89e3Python\u7248\u672c\u3001\u914d\u7f6ePython\u73af\u5883\u7b49\u3002<\/strong> \u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u5b8c\u6210\u8fd9\u4e9b\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u6253\u5f00\u7ec8\u7aef<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5982\u4f55\u627e\u5230\u7ec8\u7aef\u5e94\u7528\uff1a<\/strong><br \/>MacBook\u4e2d\uff0c\u7ec8\u7aef\u5e94\u7528\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u901a\u8fc7\u201c\u5e94\u7528\u7a0b\u5e8f\u201d\u4e2d\u7684\u201c\u5b9e\u7528\u5de5\u5177\u201d\u6587\u4ef6\u5939\u627e\u5230\u5b83\u3002\u60a8\u4e5f\u53ef\u4ee5\u901a\u8fc7Spotlight\u641c\u7d22\uff08\u6309\u4e0bCommand + \u7a7a\u683c\u952e\uff09\u5e76\u8f93\u5165\u201c\u7ec8\u7aef\u201d\u6765\u5feb\u901f\u627e\u5230\u5e76\u6253\u5f00\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ec8\u7aef\u7684\u4f5c\u7528\uff1a<\/strong><br \/>\u7ec8\u7aef\u662fMacOS\u4e0b\u7684\u547d\u4ee4\u884c\u754c\u9762\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u8fd9\u91cc\u8f93\u5165\u547d\u4ee4\uff0c\u6267\u884c\u5305\u62ec\u6587\u4ef6\u64cd\u4f5c\u3001\u8f6f\u4ef6\u5b89\u88c5\u3001\u7cfb\u7edf\u914d\u7f6e\u7b49\u4efb\u52a1\u3002\u4e86\u89e3\u5982\u4f55\u4f7f\u7528\u7ec8\u7aef\u662f\u4f7f\u7528Mac\u7cfb\u7edf\u7684\u91cd\u8981\u6280\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u8f93\u5165Python\u7248\u672c\u67e5\u8be2\u547d\u4ee4<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770b\u7cfb\u7edf\u9884\u88c5\u7684Python\u7248\u672c\uff1a<\/strong><br \/>\u5728\u7ec8\u7aef\u4e2d\uff0c\u8f93\u5165 <code>python --version<\/code> \u6216 <code>python -V<\/code>\uff0c\u7136\u540e\u6309Enter\u952e\u3002\u8fd9\u4e9b\u547d\u4ee4\u5c06\u8fd4\u56de\u7cfb\u7edf\u9ed8\u8ba4\u5b89\u88c5\u7684Python\u7248\u672c\u3002\u901a\u5e38\uff0cMacOS\u7cfb\u7edf\u81ea\u5e26\u7684\u662fPython 2.x\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770bPython 3\u7684\u7248\u672c\uff1a<\/strong><br \/>\u5982\u679c\u60a8\u5df2\u7ecf\u5b89\u88c5\u4e86Python 3\uff0c\u53ef\u4ee5\u8f93\u5165 <code>python3 --version<\/code> \u6216 <code>python3 -V<\/code> \u6765\u67e5\u770bPython 3\u7684\u7248\u672c\u3002\u73b0\u4ee3\u5f00\u53d1\u4e2d\uff0c\u5927\u591a\u6570\u65b0\u7684\u9879\u76ee\u548c\u5e93\u90fd\u5efa\u8bae\u4f7f\u7528Python 3\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4e86\u89e3Python\u7248\u672c<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Python 2\u4e0ePython 3\u7684\u533a\u522b\uff1a<\/strong><br \/>Python 2.x\u548cPython 3.x\u5728\u8bed\u6cd5\u548c\u529f\u80fd\u4e0a\u6709\u4e00\u4e9b\u5173\u952e\u533a\u522b\uff0c\u4f8b\u5982print\u8bed\u53e5\u3001\u6574\u6570\u9664\u6cd5\u3001Unicode\u5b57\u7b26\u4e32\u5904\u7406\u7b49\u3002Python 2\u7684\u5b98\u65b9\u652f\u6301\u5df2\u57282020\u5e74\u7ed3\u675f\uff0c\u56e0\u6b64\u5efa\u8bae\u4f7f\u7528Python 3\u8fdb\u884c\u5f00\u53d1\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4e3a\u4f55\u9700\u8981\u786e\u8ba4Python\u7248\u672c\uff1a<\/strong><br \/>\u4e0d\u540c\u7684Python\u7248\u672c\u53ef\u80fd\u5bfc\u81f4\u4ee3\u7801\u7684\u517c\u5bb9\u6027\u95ee\u9898\uff0c\u56e0\u6b64\u5728\u5f00\u59cb\u9879\u76ee\u4e4b\u524d\u786e\u8ba4Python\u7248\u672c\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u786e\u8ba4\u7248\u672c\u540e\uff0c\u60a8\u53ef\u4ee5\u786e\u4fdd\u60a8\u7684\u4ee3\u7801\u5728\u76f8\u5e94\u7684Python\u73af\u5883\u4e2d\u6b63\u786e\u8fd0\u884c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u914d\u7f6ePython\u73af\u5883<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u548c\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\uff1a<\/strong><br \/>\u5982\u679c\u60a8\u9700\u8981\u4f7f\u7528\u4e0d\u540c\u7684Python\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pyenv<\/code>\u6765\u7ba1\u7406\u3002\u9996\u5148\uff0c\u901a\u8fc7Homebrew\u5b89\u88c5<code>pyenv<\/code>\uff0c\u7136\u540e\u4f7f\u7528<code>pyenv install<\/code>\u547d\u4ee4\u6765\u5b89\u88c5\u6240\u9700\u7248\u672c\uff0c\u5e76\u4f7f\u7528<code>pyenv global<\/code>\u6216<code>pyenv local<\/code>\u547d\u4ee4\u6765\u8bbe\u7f6ePython\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u865a\u62df\u73af\u5883\uff1a<\/strong><br \/>\u4e3a\u4e86\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u4f9d\u8d56\u51b2\u7a81\uff0c\u63a8\u8350\u4f7f\u7528<code>virtualenv<\/code>\u6216<code>venv<\/code>\u6765\u521b\u5efa\u72ec\u7acb\u7684Python\u73af\u5883\u3002\u901a\u8fc7\u8fd9\u4e9b\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u5728\u6bcf\u4e2a\u9879\u76ee\u7684\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u9694\u79bb\u7684\u73af\u5883\uff0c\u5e76\u5728\u5176\u4e2d\u5b89\u88c5\u6240\u9700\u7684\u4f9d\u8d56\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001Python\u5f00\u53d1\u5de5\u5177\u548c\u8d44\u6e90<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\uff1a<\/strong><br \/>\u4f7f\u7528IDE\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002\u5e38\u89c1\u7684Python IDE\u6709PyCharm\u3001Visual Studio Code\u548cSpyder\u7b49\uff0c\u8fd9\u4e9b\u5de5\u5177\u63d0\u4f9b\u4e86\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u548c\u7248\u672c\u63a7\u5236\u7b49\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5728\u7ebf\u8d44\u6e90\u548c\u793e\u533a\u652f\u6301\uff1a<\/strong><br \/>Python\u62e5\u6709\u5e7f\u6cdb\u7684\u5728\u7ebf\u8d44\u6e90\u548c\u6d3b\u8dc3\u7684\u793e\u533a\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7Python\u5b98\u65b9\u6587\u6863\u3001Stack Overflow\u548cGitHub\u7b49\u5e73\u53f0\u83b7\u53d6\u5e2e\u52a9\u548c\u5b66\u4e60\u8d44\u6e90\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u5b9e\u8df5\u548c\u5e38\u89c1\u95ee\u9898<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\uff1a<\/strong><br \/>\u5728\u4f7f\u7528Python\u7684\u8fc7\u7a0b\u4e2d\uff0c\u60a8\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u7684\u95ee\u9898\uff0c\u4f8b\u5982\u5e93\u7684\u517c\u5bb9\u6027\u3001\u8def\u5f84\u914d\u7f6e\u9519\u8bef\u7b49\u3002\u901a\u8fc7\u67e5\u9605\u5b98\u65b9\u6587\u6863\u548c\u793e\u533a\u8bba\u575b\uff0c\u60a8\u53ef\u4ee5\u627e\u5230\u5927\u591a\u6570\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6301\u7eed\u5b66\u4e60\u548c\u66f4\u65b0\uff1a<\/strong><br \/>Python\u662f\u4e00\u4e2a\u4e0d\u65ad\u53d1\u5c55\u7684\u8bed\u8a00\uff0c\u65b0\u7684\u7248\u672c\u548c\u5e93\u4e0d\u65ad\u63a8\u51fa\u3002\u4e3a\u4e86\u4fdd\u6301\u7f16\u7a0b\u6280\u80fd\u7684\u66f4\u65b0\uff0c\u5efa\u8bae\u5b9a\u671f\u5173\u6ce8Python\u7684\u66f4\u65b0\u65e5\u5fd7\u548c\u5f00\u53d1\u8005\u5927\u4f1a\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u67e5\u627e\u548c\u7ba1\u7406MacBook\u4e0a\u7684Python\u7248\u672c\uff0c\u5e76\u4e3a\u5f00\u53d1\u5de5\u4f5c\u505a\u597d\u51c6\u5907\u3002\u65e0\u8bba\u662f\u521d\u5b66\u8005\u8fd8\u662f\u7ecf\u9a8c\u4e30\u5bcc\u7684\u5f00\u53d1\u8005\uff0c\u638c\u63e1\u8fd9\u4e9b\u6280\u5de7\u90fd\u5c06\u6709\u52a9\u4e8e\u66f4\u9ad8\u6548\u5730\u4f7f\u7528Python\u8fdb\u884c\u8f6f\u4ef6\u5f00\u53d1\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u786e\u8ba4\u6211\u7684MacBook\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Python\uff1f<\/strong><br \/>\u8981\u786e\u8ba4\u60a8\u7684MacBook\u4e0a\u662f\u5426\u5df2\u7ecf\u5b89\u88c5\u4e86Python\uff0c\u53ef\u4ee5\u6253\u5f00\u201c\u7ec8\u7aef\u201d\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u547d\u4ee4<code>python --version<\/code>\u6216<code>python3 --version<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u3002\u5982\u679c\u60a8\u770b\u5230Python\u7684\u7248\u672c\u53f7\uff0c\u8bf4\u660e\u5b83\u5df2\u7ecf\u5b89\u88c5\u3002\u5982\u679c\u6ca1\u6709\uff0c\u7cfb\u7edf\u4f1a\u63d0\u793a\u60a8\u8be5\u547d\u4ee4\u672a\u627e\u5230\u3002<\/p>\n<p><strong>MacBook\u81ea\u5e26\u7684Python\u7248\u672c\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5927\u90e8\u5206\u73b0\u4ee3MacBook\u90fd\u9884\u88c5\u4e86Python 2\u548cPython 3\u3002\u5177\u4f53\u7248\u672c\u53d6\u51b3\u4e8e\u60a8\u7684macOS\u7cfb\u7edf\u7248\u672c\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python --version<\/code>\u548c<code>python3 --version<\/code>\u6765\u67e5\u770b\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\u3002<\/p>\n<p><strong>\u6211\u8be5\u5982\u4f55\u66f4\u65b0MacBook\u4e0a\u7684Python\uff1f<\/strong><br \/>\u5982\u679c\u60a8\u9700\u8981\u66f4\u65b0MacBook\u4e0a\u7684Python\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177Homebrew\u3002\u9996\u5148\uff0c\u786e\u4fdd\u60a8\u5df2\u5b89\u88c5Homebrew\uff0c\u7136\u540e\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>brew update<\/code>\u548c<code>brew upgrade python<\/code>\u5373\u53ef\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u6b64\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u76f4\u63a5\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6700\u65b0\u7684\u5b89\u88c5\u5305\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u67e5\u627eMacBook\u81ea\u5e26\u7684Python\u7248\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165\u547d\u4ee4\u6765\u5b9e\u73b0\u3002\u901a\u5e38\uff0cMacBook\u4e0a\u9884\u88c5\u7684Py [&hellip;]","protected":false},"author":3,"featured_media":962066,"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\/962062"}],"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=962062"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/962062\/revisions"}],"predecessor-version":[{"id":962070,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/962062\/revisions\/962070"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/962066"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=962062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=962062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=962062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}