{"id":1009241,"date":"2024-12-27T11:10:06","date_gmt":"2024-12-27T03:10:06","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1009241.html"},"modified":"2024-12-27T11:10:08","modified_gmt":"2024-12-27T03:10:08","slug":"%e5%a6%82%e4%bd%95%e7%94%a8mac-%e7%bc%96%e8%be%91python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1009241.html","title":{"rendered":"\u5982\u4f55\u7528mac \u7f16\u8f91python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25084231\/ed696f74-45c5-49fa-9f3f-cd1d1745b4f1.webp\" alt=\"\u5982\u4f55\u7528mac \u7f16\u8f91python\" \/><\/p>\n<p><p> <strong>\u5728Mac\u4e0a\u7f16\u8f91Python\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u7684\u6587\u672c\u7f16\u8f91\u5668\u3001\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u4ee5\u53ca\u547d\u4ee4\u884c\u5de5\u5177\u3002\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u53d6\u51b3\u4e8e\u7528\u6237\u7684\u9700\u6c42\u548c\u7f16\u7a0b\u7ecf\u9a8c\u3002<\/strong>\u5176\u4e2d\uff0c\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u5982TextEdit\u3001\u96c6\u6210\u5f00\u53d1\u73af\u5883\u5982PyCharm\u3001\u4ee5\u53ca\u547d\u4ee4\u884c\u5de5\u5177\u5982Terminal\u662f\u5e38\u89c1\u7684\u9009\u62e9\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528PyCharm\u8fdb\u884cPython\u5f00\u53d1\u7684\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528PyCharm\u8fdb\u884cPython\u5f00\u53d1<\/strong><\/p>\n<\/p>\n<p><p>PyCharm\u662f\u7531JetBr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ns\u5f00\u53d1\u7684\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684Python\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3002\u5b83\u63d0\u4f9b\u4e86\u8bb8\u591a\u529f\u80fd\uff0c\u5305\u62ec\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u3001\u7248\u672c\u63a7\u5236\u7b49\uff0c\u4f7f\u5f97Python\u5f00\u53d1\u66f4\u52a0\u9ad8\u6548\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7d\u5b89\u88c5PyCharm<\/strong><\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u4eceJetBrains\u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5PyCharm\u3002\u6839\u636e\u60a8\u7684\u9700\u6c42\uff0c\u53ef\u4ee5\u9009\u62e9\u793e\u533a\u7248\uff08\u514d\u8d39\uff09\u6216\u4e13\u4e1a\u7248\uff08\u6536\u8d39\uff09\u3002\u5b89\u88c5\u8fc7\u7a0b\u975e\u5e38\u76f4\u89c2\uff0c\u6309\u7167\u5c4f\u5e55\u4e0a\u7684\u6307\u793a\u5373\u53ef\u5b8c\u6210\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u914d\u7f6ePython\u89e3\u91ca\u5668<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6253\u5f00PyCharm\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\u3002\u63a5\u7740\uff0c\u60a8\u9700\u8981\u914d\u7f6ePython\u89e3\u91ca\u5668\u3002PyCharm\u4f1a\u81ea\u52a8\u68c0\u6d4b\u7cfb\u7edf\u4e2d\u7684Python\u89e3\u91ca\u5668\uff0c\u4f46\u60a8\u4e5f\u53ef\u4ee5\u624b\u52a8\u6307\u5b9a\u8def\u5f84\u3002\u70b9\u51fb\u201cFile\u201d\u83dc\u5355\uff0c\u9009\u62e9\u201cSettings\u201d\u6216\u201cPreferences\u201d\uff08\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u4e0d\u540c\uff09\uff0c\u7136\u540e\u5728\u201cProject: [Your Project Name]\u201d\u4e0b\u9009\u62e9\u201cPython Interpreter\u201d\uff0c\u5728\u8fd9\u91cc\u53ef\u4ee5\u6dfb\u52a0\u6216\u9009\u62e9\u5408\u9002\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u548c\u7f16\u8f91Python\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u4e2d\uff0c\u53f3\u952e\u70b9\u51fb\u60a8\u7684\u9879\u76ee\u6587\u4ef6\u5939\uff0c\u9009\u62e9\u201cNew\u201d -&gt; \u201cPython File\u201d\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u6587\u4ef6\u3002\u8f93\u5165\u6587\u4ef6\u540d\u540e\uff0cPyCharm\u4f1a\u4e3a\u60a8\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u7684Python\u6587\u4ef6\u3002\u60a8\u53ef\u4ee5\u5728\u6b64\u6587\u4ef6\u4e2d\u7f16\u5199Python\u4ee3\u7801\u3002PyCharm\u63d0\u4f9b\u4e86\u4ee3\u7801\u8865\u5168\u3001\u9519\u8bef\u63d0\u793a\u7b49\u529f\u80fd\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u66f4\u5feb\u66f4\u51c6\u786e\u5730\u7f16\u5199\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u548c\u8c03\u8bd5Python\u7a0b\u5e8f<\/strong><\/p>\n<\/p>\n<p><p>PyCharm\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u8fd0\u884c\u548c\u8c03\u8bd5\u5de5\u5177\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u5de5\u5177\u680f\u4e0a\u7684\u7eff\u8272\u7bad\u5934\u6765\u8fd0\u884c\u7a0b\u5e8f\uff0c\u6216\u4f7f\u7528\u53f3\u952e\u83dc\u5355\u9009\u62e9\u201cRun [Your File Name]\u201d\u3002\u82e5\u9700\u8981\u8c03\u8bd5\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u5728\u4ee3\u7801\u884c\u53f7\u5904\u70b9\u51fb\uff0c\u8bbe\u7f6e\u65ad\u70b9\uff0c\u7136\u540e\u9009\u62e9\u201cDebug [Your File Name]\u201d\u6765\u542f\u52a8\u8c03\u8bd5\u6a21\u5f0f\u3002\u8c03\u8bd5\u6a21\u5f0f\u4e0b\uff0c\u60a8\u53ef\u4ee5\u9010\u6b65\u6267\u884c\u4ee3\u7801\uff0c\u67e5\u770b\u53d8\u91cf\u503c\uff0c\u5b9a\u4f4d\u95ee\u9898\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u7248\u672c\u63a7\u5236<\/strong><\/p>\n<\/p>\n<p><p>PyCharm\u96c6\u6210\u4e86\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08VCS\uff09\u652f\u6301\uff0c\u5982Git\u3001Subversion\u7b49\u3002\u60a8\u53ef\u4ee5\u5728\u201cVCS\u201d\u83dc\u5355\u4e2d\u8fdb\u884c\u7248\u672c\u63a7\u5236\u64cd\u4f5c\uff0c\u5982\u63d0\u4ea4\u4ee3\u7801\u3001\u67e5\u770b\u5386\u53f2\u8bb0\u5f55\u3001\u5408\u5e76\u5206\u652f\u7b49\u3002\u4f7f\u7528\u7248\u672c\u63a7\u5236\u53ef\u4ee5\u5e2e\u52a9\u60a8\u7ba1\u7406\u4ee3\u7801\u53d8\u66f4\uff0c\u63d0\u9ad8\u56e2\u961f\u534f\u4f5c\u6548\u7387\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u548c\u7ba1\u7406Python\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u5728PyCharm\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7Python\u5305\u7ba1\u7406\u5de5\u5177pip\u6765\u5b89\u88c5\u548c\u7ba1\u7406Python\u5e93\u3002\u5728\u201cTerminal\u201d\u7a97\u53e3\u4e2d\uff0c\u8f93\u5165<code>pip install [Library Name]<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002PyCharm\u4e5f\u63d0\u4f9b\u4e86\u56fe\u5f62\u5316\u7684\u5e93\u7ba1\u7406\u754c\u9762\uff0c\u60a8\u53ef\u4ee5\u5728\u201cFile\u201d -&gt; \u201cSettings\u201d\u6216\u201cPreferences\u201d\u4e2d\uff0c\u9009\u62e9\u201cProject: [Your Project Name]\u201d -&gt; \u201cPython Interpreter\u201d\uff0c\u5728\u53f3\u4fa7\u7684\u5305\u5217\u8868\u4e2d\u8fdb\u884c\u5e93\u7684\u5b89\u88c5\u3001\u66f4\u65b0\u548c\u5378\u8f7d\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p><strong>\u4f7f\u7528\u5176\u4ed6\u5de5\u5177\u8fdb\u884cPython\u5f00\u53d1<\/strong><\/p>\n<\/p>\n<p><p>\u867d\u7136PyCharm\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u5176\u4ed6\u7f16\u8f91\u5de5\u5177\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u9009\u62e9\uff1a<\/p>\n<\/p>\n<p><p>\u4e00\u3001<strong>\u4f7f\u7528TextEdit<\/strong><\/p>\n<\/p>\n<p><p>TextEdit\u662fMac\u7cfb\u7edf\u81ea\u5e26\u7684\u6587\u672c\u7f16\u8f91\u5668\uff0c\u9002\u5408\u7b80\u5355\u7684Python\u811a\u672c\u7f16\u5199\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u521b\u5efa\u6587\u4ef6<\/strong>\uff1a\u6253\u5f00TextEdit\uff0c\u9009\u62e9\u201c\u65b0\u5efa\u6587\u7a3f\u201d\uff0c\u7136\u540e\u5c06\u6587\u4ef6\u683c\u5f0f\u8bbe\u7f6e\u4e3a\u201c\u7eaf\u6587\u672c\u201d\u3002<\/li>\n<li><strong>\u7f16\u5199\u4ee3\u7801<\/strong>\uff1a\u5728TextEdit\u4e2d\u7f16\u5199Python\u4ee3\u7801\u3002<\/li>\n<li><strong>\u4fdd\u5b58\u6587\u4ef6<\/strong>\uff1a\u4fdd\u5b58\u6587\u4ef6\u65f6\uff0c\u8bf7\u786e\u4fdd\u6587\u4ef6\u6269\u5c55\u540d\u4e3a\u201c.py\u201d\u3002<\/li>\n<\/ul>\n<p><p>\u4e8c\u3001<strong>\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177<\/strong><\/p>\n<\/p>\n<p><p>Terminal\u662fMac\u7cfb\u7edf\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4e8e\u6267\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u6253\u5f00Terminal<\/strong>\uff1a\u5728\u201c\u5e94\u7528\u7a0b\u5e8f\u201d -&gt; \u201c\u5b9e\u7528\u5de5\u5177\u201d\u4e2d\u627e\u5230Terminal\u5e76\u6253\u5f00\u3002<\/li>\n<li><strong>\u7f16\u5199\u548c\u8fd0\u884c\u4ee3\u7801<\/strong>\uff1a\u60a8\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u7f16\u8f91\u5668\u5982nano\u3001vim\u7b49\u7f16\u5199\u4ee3\u7801\uff0c\u7136\u540e\u4f7f\u7528<code>python [\u6587\u4ef6\u540d].py<\/code>\u547d\u4ee4\u8fd0\u884cPython\u811a\u672c\u3002<\/li>\n<\/ul>\n<p><p>\u4e09\u3001<strong>\u4f7f\u7528\u5176\u4ed6IDE\u548c\u7f16\u8f91\u5668<\/strong><\/p>\n<\/p>\n<p><p>\u9664\u4e86PyCharm\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6IDE\u548c\u7f16\u8f91\u5668\uff0c\u5982Visual Studio Code\u3001Atom\u7b49\u3002\u6bcf\u79cd\u5de5\u5177\u90fd\u6709\u5176\u72ec\u7279\u7684\u529f\u80fd\u548c\u4f18\u7f3a\u70b9\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>Visual Studio Code<\/strong>\uff1a\u8f7b\u91cf\u7ea7\u3001\u591a\u8bed\u8a00\u652f\u6301\u3001\u4e30\u5bcc\u7684\u63d2\u4ef6\u751f\u6001\u3002<\/li>\n<li><strong>Atom<\/strong>\uff1a\u5f00\u6e90\u3001\u53ef\u9ad8\u5ea6\u5b9a\u5236\u5316\u3001\u652f\u6301\u534f\u4f5c\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p><p>\u56db\u3001<strong>\u5b89\u88c5\u548c\u914d\u7f6ePython\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u5728Mac\u4e0a\u8fdb\u884cPython\u5f00\u53d1\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u60a8\u7684Mac\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u3002macOS\u901a\u5e38\u81ea\u5e26Python 2.x\u7248\u672c\uff0c\u4f46\u5efa\u8bae\u5b89\u88c5Python 3.x\u7248\u672c\u4ee5\u83b7\u53d6\u6700\u65b0\u529f\u80fd\u548c\u6027\u80fd\u6539\u8fdb\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u5b89\u88c5\u548c\u914d\u7f6e\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5Python\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u6253\u5f00Terminal\u5e76\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u6765\u68c0\u67e5\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\u3002\u5efa\u8bae\u4f7f\u7528Python 3.x\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python 3.x<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u7684\u7cfb\u7edf\u4e0a\u6ca1\u6709\u5b89\u88c5Python 3.x\uff0c\u53ef\u4ee5\u901a\u8fc7Homebrew\u5b89\u88c5\u3002\u9996\u5148\uff0c\u786e\u4fddHomebrew\u5df2\u5b89\u88c5\uff0c\u6253\u5f00Terminal\u5e76\u8f93\u5165<code>brew install python<\/code>\u3002Homebrew\u4f1a\u81ea\u52a8\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7684Python 3.x\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528Python 3.x\u3002\u53ef\u4ee5\u5728Terminal\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5c06Python 3.x\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">echo &#39;alias python=python3&#39; &gt;&gt; ~\/.bash_profile<\/p>\n<p>source ~\/.bash_profile<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u522b\u540d\uff0c\u4f7f\u5f97\u6bcf\u6b21\u8f93\u5165<code>python<\/code>\u547d\u4ee4\u65f6\uff0c\u7cfb\u7edf\u5b9e\u9645\u4e0a\u6267\u884c\u7684\u662f<code>python3<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001<strong>\u4f7f\u7528Python\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u6709\u6548\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5e93\u7248\u672c\u51b2\u7a81\u3002\u4ee5\u4e0b\u662f\u521b\u5efa\u548c\u4f7f\u7528Python\u865a\u62df\u73af\u5883\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\uff0c\u6253\u5f00Terminal\u5e76\u8f93\u5165<code>python3 -m venv venv<\/code>\u6765\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cvenv\u201d\u7684\u865a\u62df\u73af\u5883\u3002\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u66f4\u6539\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u8f93\u5165<code>source venv\/bin\/activate<\/code>\u6765\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002\u6fc0\u6d3b\u540e\uff0c\u60a8\u5c06\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u524d\u770b\u5230\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\uff0c\u8868\u793a\u5f53\u524d\u5df2\u5904\u4e8e\u865a\u62df\u73af\u5883\u4e2d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u9879\u76ee\u4f9d\u8d56<\/strong><\/p>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u4f7f\u7528pip\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u5e93\u3002\u4f8b\u5982\uff0c\u8f93\u5165<code>pip install requests<\/code>\u6765\u5b89\u88c5requests\u5e93\u3002\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u7684\u5e93\u5bf9\u5f53\u524d\u9879\u76ee\u72ec\u7acb\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5168\u5c40Python\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u5b8c\u6210\u5f00\u53d1\u6216\u6d4b\u8bd5\u540e\uff0c\u8f93\u5165<code>deactivate<\/code>\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\uff0c\u6062\u590d\u5230\u5168\u5c40Python\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001<strong>\u7ba1\u7406Python\u9879\u76ee<\/strong><\/p>\n<\/p>\n<p><p>\u5728Mac\u4e0a\u8fdb\u884cPython\u9879\u76ee\u5f00\u53d1\u65f6\uff0c\u826f\u597d\u7684<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/23316.html\" target=\"_blank\">\u9879\u76ee\u7ba1\u7406<\/a>\u662f\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u4ee3\u7801\u8d28\u91cf\u7684\u5173\u952e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u7ba1\u7406Python\u9879\u76ee\u7684\u5efa\u8bae\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7ed3\u6784\u5316\u9879\u76ee\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u4fbf\u4e8e\u7ba1\u7406\uff0c\u5efa\u8bae\u5c06\u9879\u76ee\u6587\u4ef6\u548c\u76ee\u5f55\u7ed3\u6784\u5316\u3002\u901a\u5e38\u7684Python\u9879\u76ee\u7ed3\u6784\u5305\u62ec\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u9879\u76ee\u6839\u76ee\u5f55\n<ul>\n<li><code>venv\/<\/code>\uff08\u865a\u62df\u73af\u5883\uff09<\/li>\n<li><code>src\/<\/code>\uff08\u6e90\u4ee3\u7801\uff09<\/li>\n<li><code>tests\/<\/code>\uff08\u6d4b\u8bd5\u4ee3\u7801\uff09<\/li>\n<li><code>README.md<\/code>\uff08\u9879\u76ee\u8bf4\u660e\u6587\u6863\uff09<\/li>\n<li><code>requirements.txt<\/code>\uff08\u4f9d\u8d56\u5e93\u6e05\u5355\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u7248\u672c\u63a7\u5236<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528Git\u7b49\u7248\u672c\u63a7\u5236\u5de5\u5177\u7ba1\u7406\u4ee3\u7801\u53d8\u66f4\u3002\u521d\u59cb\u5316Git\u4ed3\u5e93\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7<code>.gitignore<\/code>\u6587\u4ef6\u6392\u9664\u4e0d\u9700\u8981\u7248\u672c\u63a7\u5236\u7684\u6587\u4ef6\uff0c\u5982<code>venv\/<\/code>\u76ee\u5f55\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6587\u6863\u7f16\u5199<\/strong><\/p>\n<\/p>\n<p><p>\u7f16\u5199\u826f\u597d\u7684\u6587\u6863\u6709\u52a9\u4e8e\u56e2\u961f\u534f\u4f5c\u548c\u9879\u76ee\u7ef4\u62a4\u3002\u4f7f\u7528Markdown\u683c\u5f0f\u7f16\u5199<code>README.md<\/code>\u6587\u4ef6\uff0c\u8be6\u7ec6\u8bf4\u660e\u9879\u76ee\u7684\u5b89\u88c5\u3001\u4f7f\u7528\u548c\u8d21\u732e\u6307\u5357\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4ee3\u7801\u6d4b\u8bd5<\/strong><\/p>\n<\/p>\n<p><p>\u7f16\u5199\u5355\u5143\u6d4b\u8bd5\u548c\u96c6\u6210\u6d4b\u8bd5\uff0c\u4ee5\u786e\u4fdd\u4ee3\u7801\u7684\u6b63\u786e\u6027\u548c\u7a33\u5b9a\u6027\u3002\u53ef\u4ee5\u4f7f\u7528unittest\u3001pytest\u7b49\u6d4b\u8bd5\u6846\u67b6\u7f16\u5199\u548c\u6267\u884c\u6d4b\u8bd5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e03\u3001<strong>\u4f18\u5316Python\u5f00\u53d1\u6548\u7387<\/strong><\/p>\n<\/p>\n<p><p>\u5728Mac\u4e0a\u8fdb\u884cPython\u5f00\u53d1\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u4f18\u5316\u5f00\u53d1\u6548\u7387\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u4ee3\u7801\u8865\u5168<\/strong><\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u4f7f\u7528\u54ea\u4e2a\u7f16\u8f91\u5668\u6216IDE\uff0c\u4ee3\u7801\u8865\u5168\u529f\u80fd\u90fd\u53ef\u4ee5\u5e2e\u52a9\u52a0\u5feb\u7f16\u5199\u901f\u5ea6\u3002\u5efa\u8bae\u9009\u62e9\u4e00\u4e2a\u652f\u6301\u667a\u80fd\u4ee3\u7801\u8865\u5168\u7684\u5de5\u5177\uff0c\u5982PyCharm\u6216Visual Studio Code\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5feb\u6377\u952e<\/strong><\/p>\n<\/p>\n<p><p>\u638c\u63e1\u5e38\u7528\u7684\u5feb\u6377\u952e\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u6548\u7387\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>Cmd + \/<\/code>\u53ef\u4ee5\u5feb\u901f\u6ce8\u91ca\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u81ea\u52a8\u5316\u5de5\u5177<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528Makefile\u6216\u5176\u4ed6\u81ea\u52a8\u5316\u5de5\u5177\u7b80\u5316\u6784\u5efa\u548c\u90e8\u7f72\u6d41\u7a0b\u3002\u5b9a\u4e49\u5e38\u7528\u7684\u6784\u5efa\u4efb\u52a1\uff0c\u5982\u8fd0\u884c\u6d4b\u8bd5\u3001\u751f\u6210\u6587\u6863\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6301\u7eed\u96c6\u6210<\/strong><\/p>\n<\/p>\n<p><p>\u914d\u7f6e\u6301\u7eed\u96c6\u6210\uff08CI\uff09\u5de5\u5177\uff0c\u5982GitHub Actions\u3001Travis CI\u7b49\uff0c\u81ea\u52a8\u6267\u884c\u6d4b\u8bd5\u548c\u90e8\u7f72\u4efb\u52a1\uff0c\u4fdd\u6301\u4ee3\u7801\u7684\u7a33\u5b9a\u6027\u548c\u4e00\u81f4\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u5408\u7406\u9009\u62e9\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u5e76\u4e0d\u65ad\u4f18\u5316\u5f00\u53d1\u6d41\u7a0b\uff0c\u53ef\u4ee5\u5728Mac\u4e0a\u66f4\u9ad8\u6548\u5730\u8fdb\u884cPython\u5f00\u53d1\u3002\u65e0\u8bba\u662f\u65b0\u624b\u8fd8\u662f\u7ecf\u9a8c\u4e30\u5bcc\u7684\u5f00\u53d1\u8005\uff0c\u90fd\u53ef\u4ee5\u901a\u8fc7\u5b9e\u8df5\u548c\u79ef\u7d2f\u63d0\u9ad8\u7f16\u7a0b\u6280\u80fd\u548c\u9879\u76ee\u7ba1\u7406\u80fd\u529b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Mac\u4e0a\u5b89\u88c5Python\u73af\u5883\uff1f<\/strong><br \/>\u5728Mac\u4e0a\u5b89\u88c5Python\u975e\u5e38\u7b80\u5355\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684\u5b89\u88c5\u7a0b\u5e8f\uff0c\u6216\u8005\u4f7f\u7528Homebrew\u5305\u7ba1\u7406\u5668\u6765\u5b89\u88c5\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>brew install python<\/code>\u547d\u4ee4\u5373\u53ef\u5b8c\u6210\u5b89\u88c5\u3002\u5b89\u88c5\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>python3 --version<\/code>\u6765\u9a8c\u8bc1\u662f\u5426\u6210\u529f\u5b89\u88c5\u3002<\/p>\n<p><strong>\u6709\u54ea\u4e9b\u63a8\u8350\u7684\u7f16\u8f91\u5668\u53ef\u4ee5\u5728Mac\u4e0a\u7f16\u5199Python\u4ee3\u7801\uff1f<\/strong><br \/>\u5728Mac\u4e0a\uff0c\u6709\u591a\u79cd\u7f16\u8f91\u5668\u53ef\u4ee5\u7528\u4e8e\u7f16\u5199Python\u4ee3\u7801\u3002\u5e38\u89c1\u7684\u5305\u62ecVisual Studio Code\u3001PyCharm\u3001Sublime Text\u548cAtom\u7b49\u3002Visual Studio Code\u56e0\u5176\u4e30\u5bcc\u7684\u63d2\u4ef6\u652f\u6301\u548c\u826f\u597d\u7684\u7528\u6237\u4f53\u9a8c\u800c\u53d7\u5230\u8bb8\u591a\u5f00\u53d1\u8005\u7684\u9752\u7750\u3002PyCharm\u5219\u662f\u4e13\u4e3aPython\u5f00\u53d1\u8bbe\u8ba1\u7684IDE\uff0c\u63d0\u4f9b\u5f3a\u5927\u7684\u8c03\u8bd5\u5de5\u5177\u548c\u4ee3\u7801\u8865\u5168\u529f\u80fd\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Mac\u4e0a\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u5728Mac\u4e0a\u8fd0\u884cPython\u811a\u672c\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Python\uff0c\u5e76\u5728\u7ec8\u7aef\u4e2d\u5bfc\u822a\u5230\u5305\u542bPython\u811a\u672c\u7684\u76ee\u5f55\u3002\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>python3 your_script.py<\/code>\u6765\u8fd0\u884c\u811a\u672c\u3002\u5982\u679c\u811a\u672c\u9700\u8981\u4f20\u9012\u53c2\u6570\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u540e\u6dfb\u52a0\u53c2\u6570\uff0c\u786e\u4fdd\u4f60\u7684\u4ee3\u7801\u80fd\u591f\u6b63\u786e\u5904\u7406\u8fd9\u4e9b\u8f93\u5165\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Mac\u4e0a\u7f16\u8f91Python\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u7684\u6587\u672c\u7f16\u8f91\u5668\u3001\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u4ee5\u53ca\u547d\u4ee4\u884c\u5de5\u5177\u3002\u9009\u62e9\u5408 [&hellip;]","protected":false},"author":3,"featured_media":1009251,"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\/1009241"}],"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=1009241"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1009241\/revisions"}],"predecessor-version":[{"id":1009252,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1009241\/revisions\/1009252"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1009251"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1009241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1009241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1009241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}