{"id":137,"date":"2025-05-30T17:14:18","date_gmt":"2025-06-04T10:08:17","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=137"},"modified":"2025-06-04T17:14:18","modified_gmt":"2025-06-04T10:08:17","slug":"137","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/python\/137\/","title":{"rendered":"\u89e3\u6c7a CompilerSelectionError\uff1a\u5982\u4f55\u5728 macOS \u4e0a\u5b89\u88dd Python 3.8"},"content":{"rendered":"<p>\u5728\u4f7f\u7528 Homebrew \u5b89\u88dd Python \u6642\uff0c\u4f60\u53ef\u80fd\u6703\u9047\u5230\u4ee5\u4e0b\u932f\u8aa4\u4fe1\u606f\uff1a<\/p>\n<p>&#8220;`<br \/>\nError: An exception occurred within a child process:<br \/>\n  CompilerSelectionError: python@3.8 cannot be built with any available compilers.<br \/>\n&#8220;`<\/p>\n<p>\u9019\u500b\u932f\u8aa4\u901a\u5e38\u8868\u793a\u4f60\u7684\u7cfb\u7d71\u4e2d\u7f3a\u5c11\u53ef\u7528\u7684\u7de8\u8b6f\u5668\u6216\u7de8\u8b6f\u5668\u7248\u672c\u4e0d\u517c\u5bb9\u3002\u672c\u6587\u5c07\u6307\u5c0e\u4f60\u5982\u4f55\u89e3\u6c7a\u9019\u500b\u554f\u984c\uff0c\u4e26\u78ba\u4fdd\u4f60\u80fd\u9806\u5229\u5b89\u88dd Python 3.8\u3002<\/p>\n<p>### \u6b65\u9a5f\u4e00\uff1a\u5b89\u88dd\u6240\u9700\u7684\u7de8\u8b6f\u5668<\/p>\n<p>\u9996\u5148\uff0c\u5efa\u8b70\u5b89\u88dd GCC \u7de8\u8b6f\u5668\uff0c\u9019\u662f\u4e00\u500b\u5e38\u898b\u7684 C\/C++ \u7de8\u8b6f\u5668\uff0c\u80fd\u5e6b\u52a9\u4f60\u7de8\u8b6f Python \u53ca\u5176\u64f4\u5c55\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd GCC\uff1a<\/p>\n<p>&#8220;`bash<br \/>\nbrew install gcc@7<br \/>\n&#8220;`<\/p>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u78ba\u8a8d GCC \u662f\u5426\u6b63\u78ba\u5b89\u88dd\uff1a<\/p>\n<p>&#8220;`bash<br \/>\ngcc &#8211;version<br \/>\n&#8220;`<\/p>\n<p>### \u6b65\u9a5f\u4e8c\uff1a\u5b89\u88dd Python 3.8<\/p>\n<p>\u73fe\u5728\u4f60\u53ef\u4ee5\u5617\u8a66\u518d\u6b21\u5b89\u88dd Python 3.8\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>&#8220;`bash<br \/>\nbrew install python@3.8<br \/>\n&#8220;`<\/p>\n<p>### \u6b65\u9a5f\u4e09\uff1a\u8a2d\u5b9a\u74b0\u5883\u8b8a\u6578<\/p>\n<p>\u5982\u679c\u4f60\u4ecd\u7136\u9047\u5230\u932f\u8aa4\uff0c\u53ef\u80fd\u9700\u8981\u8a2d\u5b9a\u4e00\u4e9b\u74b0\u5883\u8b8a\u6578\u4ee5\u78ba\u4fdd\u7cfb\u7d71\u80fd\u627e\u5230\u6b63\u78ba\u7684\u7de8\u8b6f\u5668\u3002\u4f60\u53ef\u4ee5\u5728\u4f60\u7684 `.bash_profile` \u6216 `.zshrc` \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<p>&#8220;`bash<br \/>\nexport PATH=&#8221;\/usr\/local\/opt\/gcc@7\/bin:$PATH&#8221;<br \/>\n&#8220;`<\/p>\n<p>\u8a18\u5f97\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u5f8c\uff0c\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\u4f86\u4f7f\u8b8a\u66f4\u751f\u6548\uff1a<\/p>\n<p>&#8220;`bash<br \/>\nsource ~\/.bash_profile  # \u6216\u8005 source ~\/.zshrc<br \/>\n&#8220;`<\/p>\n<p>### \u5e38\u898b\u932f\u8aa4\u6392\u9664<\/p>\n<p>1. **\u7de8\u8b6f\u5668\u672a\u627e\u5230**\uff1a\u78ba\u4fdd\u4f60\u5df2\u7d93\u5b89\u88dd\u4e86 GCC \u4e26\u4e14\u74b0\u5883\u8b8a\u6578\u5df2\u6b63\u78ba\u8a2d\u5b9a\u3002<br \/>\n2. **\u7248\u672c\u885d\u7a81**\uff1a\u6aa2\u67e5\u662f\u5426\u6709\u5176\u4ed6\u7248\u672c\u7684 Python \u6216 GCC \u5f71\u97ff\u4e86\u5b89\u88dd\u3002<\/p>\n<p>### \u5ef6\u4f38\u61c9\u7528<\/p>\n<p>\u4e00\u65e6\u6210\u529f\u5b89\u88dd Python 3.8\uff0c\u4f60\u53ef\u4ee5\u8003\u616e\u5b89\u88dd\u865b\u64ec\u74b0\u5883\u4f86\u7ba1\u7406\u4e0d\u540c\u9805\u76ee\u7684\u4f9d\u8cf4\u3002\u4f7f\u7528\u4ee5\u4e0b\u6307\u4ee4\u5b89\u88dd `venv` \u6a21\u7d44\uff1a<\/p>\n<p>&#8220;`bash<br \/>\npython3.8 -m pip install virtualenv<br \/>\n&#8220;`<\/p>\n<p>\u9019\u6a23\u53ef\u4ee5\u8b93\u4f60\u5728\u4e0d\u540c\u7684\u9805\u76ee\u4e2d\u4f7f\u7528\u4e0d\u540c\u7684 Python \u5305\u7248\u672c\uff0c\u907f\u514d\u885d\u7a81\u3002<\/p>\n<p>![Python \u5b89\u88dd](https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2020\/11\/cup-1-1.png &#8220;Python \u5b89\u88dd\u904e\u7a0b&#8221;)<\/p>\n<p>\u82e5\u60f3\u6df1\u5165\u4e86\u89e3 Python \u7684\u4f7f\u7528\uff0c\u53ef\u4ee5\u53c3\u8003 [\u9019\u88e1\u7684\u6559\u5b78\u6587\u7ae0](https:\/\/vocus.cc\/article\/63a8f1c6fd89780001f7c568)\u3002\u9019\u5c07\u5e6b\u52a9\u4f60\u638c\u63e1\u66f4\u591a Python \u7684\u958b\u767c\u6280\u5de7\u3002<\/p>\n<p>### Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/p>\n<p>**Q1: \u70ba\u4ec0\u9ebc\u6211\u4e0d\u80fd\u5b89\u88dd\u8f03\u65b0\u7248\u672c\u7684 Python\uff1f**<br \/>\nA1: \u67d0\u4e9b\u820a\u7248\u7684 macOS \u53ef\u80fd\u4e0d\u652f\u63f4\u8f03\u65b0\u7248\u672c\u7684 Python\uff0c\u8acb\u78ba\u4fdd\u4f60\u7684\u7cfb\u7d71\u66f4\u65b0\u81f3\u6700\u65b0\u7248\u672c\u3002<\/p>\n<p>**Q2: \u5b89\u88dd Python 3.8 \u6709\u54ea\u4e9b\u597d\u8655\uff1f**<br \/>\nA2: Python 3.8 \u5f15\u5165\u4e86\u591a\u9805\u65b0\u7279\u6027\uff0c\u5305\u62ec\u904b\u7b97\u7b26\u512a\u5148\u7d1a\u6539\u9032\u8207\u66f4\u597d\u7684\u6027\u80fd\uff0c\u80fd\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u9ad8\u6548\u5730\u7de8\u5beb\u7a0b\u5f0f\u3002<\/p>\n<p>**Q3: \u5982\u679c\u9084\u662f\u9047\u5230\u554f\u984c\uff0c\u6211\u8a72\u600e\u9ebc\u8fa6\uff1f**<br \/>\nA3: \u5efa\u8b70\u67e5\u770b Homebrew \u7684 GitHub \u9801\u9762\uff0c\u641c\u7d22\u4f60\u7684\u932f\u8aa4\u4fe1\u606f\uff0c\u6216\u5728\u76f8\u95dc\u8ad6\u58c7\u5c0b\u6c42\u5e6b\u52a9\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4f7f\u7528 Homebrew \u5b89\u88dd Python \u6642\uff0c&#8230;<\/p>\n","protected":false},"author":1,"featured_media":559,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18],"tags":[],"class_list":["post-137","post","type-post","status-publish","format-aside","has-post-thumbnail","hentry","category-python","post_format-post-format-aside"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2020\/11\/cup-1-1.png","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/scFK27-137","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=137"}],"version-history":[{"count":3,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/137\/revisions"}],"predecessor-version":[{"id":13074,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/137\/revisions\/13074"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/559"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}