{"id":1002532,"date":"2024-12-27T10:09:28","date_gmt":"2024-12-27T02:09:28","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1002532.html"},"modified":"2024-12-27T10:09:30","modified_gmt":"2024-12-27T02:09:30","slug":"mac%e4%b8%ad%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1002532.html","title":{"rendered":"mac\u4e2d\u5982\u4f55\u4f7f\u7528python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25080234\/20b2bed2-a030-4642-9f8b-d0120defd169.webp\" alt=\"mac\u4e2d\u5982\u4f55\u4f7f\u7528python\" \/><\/p>\n<p><p> <strong>\u5728Mac\u4e2d\u4f7f\u7528Python\u7684\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\uff1a\u901a\u8fc7\u7ec8\u7aef\u8fd0\u884cPython\u89e3\u91ca\u5668\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u6216VSCode\u3001\u901a\u8fc7Homebrew\u5b89\u88c5\u548c\u7ba1\u7406Python\u7248\u672c\u3002<\/strong>\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u91cd\u70b9\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u7ec8\u7aef\u8fd0\u884cPython\u89e3\u91ca\u5668\u3002<\/p>\n<\/p>\n<p><p>\u5728Mac\u4e0a\uff0cPython\u901a\u5e38\u5df2\u7ecf\u9884\u88c5\u5728\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u76f4\u63a5\u8fd0\u884c\u3002\u8981\u5728\u7ec8\u7aef\u4e2d\u6253\u5f00Python\u89e3\u91ca\u5668\uff0c\u53ea\u9700\u6253\u5f00\u7ec8\u7aef\u5e94\u7528\u7a0b\u5e8f\u5e76\u8f93\u5165<code>python3<\/code>\u547d\u4ee4\u3002\u8fd9\u5c06\u542f\u52a8Python\u7684\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u6a21\u5f0f\uff0c\u60a8\u53ef\u4ee5\u5728\u5176\u4e2d\u8f93\u5165Python\u4ee3\u7801\u5e76\u7acb\u5373\u67e5\u770b\u7ed3\u679c\u3002\u8fd9\u79cd\u65b9\u5f0f\u5bf9\u4e8e\u5feb\u901f\u6d4b\u8bd5\u4ee3\u7801\u7247\u6bb5\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8ePython\u7684\u5f00\u53d1\u548c\u4f7f\u7528\uff0c\u4e86\u89e3\u5982\u4f55\u5728Mac\u4e0a\u6b63\u786e\u5b89\u88c5\u548c\u914d\u7f6ePython\u73af\u5883\uff0c\u4ee5\u53ca\u5982\u4f55\u9009\u62e9\u9002\u5408\u81ea\u5df1\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5728Mac\u4e2d\u4f7f\u7528Python\u7684\u5404\u4e2a\u65b9\u9762\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884cPython<\/h3>\n<\/p>\n<p><h4>1.1 \u68c0\u67e5Python\u7248\u672c<\/h4>\n<\/p>\n<p><p>\u5728Mac\u4e0a\uff0c\u901a\u5e38\u4f1a\u9884\u88c5Python\uff0c\u4f46\u9ed8\u8ba4\u7248\u672c\u53ef\u80fd\u662fPython 2.x\u3002\u4e3a\u4e86\u4f7f\u7528Python 3\uff0c\u6211\u4eec\u9700\u8981\u786e\u8ba4\u5f53\u524d\u7684Python\u7248\u672c\u3002\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\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<p><p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c<code>python<\/code>\u547d\u4ee4\u6307\u5411Python 2.x\uff0c\u800c<code>python3<\/code>\u6307\u5411Python 3.x\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5Python 3\uff0c\u53ef\u4ee5\u901a\u8fc7Homebrew\u6765\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>1.2 \u5b89\u88c5Python 3<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684Mac\u4e0a\u6ca1\u6709\u5b89\u88c5Python 3\uff0c\u53ef\u4ee5\u4f7f\u7528Homebrew\u8fdb\u884c\u5b89\u88c5\u3002Homebrew\u662fMac\u4e0a\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b89\u88c5\u548c\u7ba1\u7406\u8f6f\u4ef6\u5305\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684Homebrew\u5df2\u7ecf\u5b89\u88c5\u548c\u66f4\u65b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew update<\/p>\n<p>brew install python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c<code>python3<\/code>\u547d\u4ee4\u5c06\u6307\u5411\u6700\u65b0\u5b89\u88c5\u7684Python 3\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h4>1.3 \u4f7f\u7528Python\u89e3\u91ca\u5668<\/h4>\n<\/p>\n<p><p>\u5728\u7ec8\u7aef\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165<code>python3<\/code>\u8fdb\u5165Python\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>\u5728Python\u63d0\u793a\u7b26<code>&gt;&gt;&gt;<\/code>\u4e0b\uff0c\u4f60\u53ef\u4ee5\u8f93\u5165Python\u4ee3\u7801\u5e76\u7acb\u5373\u770b\u5230\u7ed3\u679c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">&gt;&gt;&gt; print(&quot;Hello, World!&quot;)<\/p>\n<p>Hello, World!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8981\u9000\u51fa\u89e3\u91ca\u5668\uff0c\u53ef\u4ee5\u8f93\u5165<code>exit()<\/code>\u6216\u8005\u6309\u4e0b<code>Ctrl+D<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/h3>\n<\/p>\n<p><h4>2.1 \u9009\u62e9\u5408\u9002\u7684IDE<\/h4>\n<\/p>\n<p><p>\u5728Mac\u4e0a\u4f7f\u7528Python\u5f00\u53d1\uff0c\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002\u5e38\u89c1\u7684Python IDE\u5305\u62ec\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>PyCharm<\/strong>\uff1a\u5f3a\u5927\u7684Python\u5f00\u53d1\u73af\u5883\uff0c\u652f\u6301\u8c03\u8bd5\u3001\u8bed\u6cd5\u9ad8\u4eae\u3001Project\u7ba1\u7406\u7b49\u529f\u80fd\uff0c\u975e\u5e38\u9002\u5408\u5927\u578b\u9879\u76ee\u3002<\/li>\n<li><strong>Visual Studio Code (VSCode)<\/strong>\uff1a\u8f7b\u91cf\u7ea7\u7f16\u8f91\u5668\uff0c\u914d\u5408Python\u6269\u5c55\u53ef\u4ee5\u63d0\u4f9b\u5f3a\u5927\u7684\u529f\u80fd\u652f\u6301\u3002<\/li>\n<li><strong>Jupyter Notebook<\/strong>\uff1a\u9002\u5408\u6570\u636e\u5206\u6790\u548c\u79d1\u5b66\u8ba1\u7b97\u7684\u5de5\u5177\uff0c\u652f\u6301\u4ea4\u4e92\u5f0f\u7f16\u7a0b\u3002<\/li>\n<\/ul>\n<p><h4>2.2 \u5b89\u88c5\u548c\u914d\u7f6ePyCharm<\/h4>\n<\/p>\n<p><p>PyCharm\u5206\u4e3a\u793e\u533a\u7248\uff08\u514d\u8d39\uff09\u548c\u4e13\u4e1a\u7248\uff08\u6536\u8d39\uff09\u3002\u53ef\u4ee5\u6839\u636e\u9700\u8981\u4eceJetBr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ns\u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6253\u5f00PyCharm\u5e76\u914d\u7f6ePython\u89e3\u91ca\u5668\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u542f\u52a8PyCharm\uff0c\u521b\u5efa\u65b0\u9879\u76ee\u3002<\/li>\n<li>\u5728\u201cNew Project\u201d\u7a97\u53e3\u4e2d\uff0c\u9009\u62e9Python\u89e3\u91ca\u5668\uff0c\u786e\u4fdd\u9009\u62e9\u7684\u662f\u5b89\u88c5\u7684Python 3\u7248\u672c\u3002<\/li>\n<li>\u5b8c\u6210\u9879\u76ee\u521b\u5efa\u540e\uff0c\u53ef\u4ee5\u5728PyCharm\u4e2d\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\u3002<\/li>\n<\/ol>\n<p><h4>2.3 \u4f7f\u7528VSCode<\/h4>\n<\/p>\n<p><p>VSCode\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u7f16\u8f91\u5668\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5Python\u6269\u5c55\u6765\u652f\u6301Python\u5f00\u53d1\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u4eceVSCode\u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5VSCode\u3002<\/li>\n<li>\u542f\u52a8VSCode\u5e76\u6253\u5f00\u6269\u5c55\u7ba1\u7406\u5668\uff0c\u641c\u7d22\u5e76\u5b89\u88c5\u201cPython\u201d\u6269\u5c55\u3002<\/li>\n<li>\u6253\u5f00\u547d\u4ee4\u9762\u677f\uff08Cmd+Shift+P\uff09\uff0c\u8f93\u5165\u201cPython: Select Interpreter\u201d\uff0c\u9009\u62e9Python 3\u89e3\u91ca\u5668\u3002<\/li>\n<li>\u73b0\u5728\u53ef\u4ee5\u5728VSCode\u4e2d\u7f16\u5199\u548c\u8c03\u8bd5Python\u4ee3\u7801\u3002<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u901a\u8fc7Homebrew\u7ba1\u7406Python\u7248\u672c<\/h3>\n<\/p>\n<p><h4>3.1 \u5b89\u88c5\u548c\u4f7f\u7528Homebrew<\/h4>\n<\/p>\n<p><p>Homebrew\u662fMac\u4e0a\u7684\u4e00\u4e2a\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u7528\u4e8e\u7b80\u5316\u8f6f\u4ef6\u5305\u7684\u5b89\u88c5\u548c\u7ba1\u7406\u3002\u8981\u5b89\u88c5Homebrew\uff0c\u53ef\u4ee5\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\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\u4f7f\u7528<code>brew<\/code>\u547d\u4ee4\u6765\u5b89\u88c5\u548c\u7ba1\u7406Python\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h4>3.2 \u5b89\u88c5\u7279\u5b9a\u7248\u672c\u7684Python<\/h4>\n<\/p>\n<p><p>Homebrew\u9ed8\u8ba4\u4f1a\u5b89\u88c5\u6700\u65b0\u7684Python\u7248\u672c\uff0c\u4f46\u6709\u65f6\u6211\u4eec\u9700\u8981\u5b89\u88c5\u7279\u5b9a\u7248\u672c\u7684Python\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u53ef\u7528\u7684Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew search python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u7279\u5b9a\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew install python@3.x<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u73af\u5883\u53d8\u91cf\u6765\u5207\u6362\u4e0d\u540c\u7248\u672c\u7684Python\u3002<\/p>\n<\/p>\n<p><h4>3.3 \u7ba1\u7406Python\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Homebrew\u5b89\u88c5Python\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip3<\/code>\u6765\u7ba1\u7406Python\u5305\u3002<code>pip3<\/code>\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Python\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip3 install package-name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7<code>pip3<\/code>\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b89\u88c5\u3001\u66f4\u65b0\u548c\u5378\u8f7dPython\u5305\uff0c\u4fbf\u4e8e\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56<\/h3>\n<\/p>\n<p><h4>4.1 \u521b\u5efa\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u5728\u5f00\u53d1Python\u9879\u76ee\u65f6\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\uff08virtual environment\uff09\u53ef\u4ee5\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5e93\u51b2\u7a81\u3002Python\u81ea\u5e26\u7684<code>venv<\/code>\u6a21\u5757\u53ef\u4ee5\u7528\u6765\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u8981\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u53ef\u4ee5\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 -m venv venv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>venv<\/code>\u7684\u5b50\u76ee\u5f55\uff0c\u5305\u542b\u72ec\u7acb\u7684Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h4>4.2 \u6fc0\u6d3b\u548c\u4f7f\u7528\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u521b\u5efa\u865a\u62df\u73af\u5883\u540e\uff0c\u9700\u8981\u6fc0\u6d3b\u5b83\u624d\u80fd\u4f7f\u7528\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source venv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u540e\uff0c\u7ec8\u7aef\u63d0\u793a\u7b26\u4f1a\u663e\u793a\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\uff0c\u8868\u793a\u5df2\u7ecf\u8fdb\u5165\u865a\u62df\u73af\u5883\u3002\u6b64\u65f6\uff0c\u4f7f\u7528<code>pip<\/code>\u5b89\u88c5\u7684\u4efb\u4f55\u5305\u90fd\u5c06\u5b89\u88c5\u5230\u865a\u62df\u73af\u5883\u4e2d\uff0c\u800c\u4e0d\u662f\u5168\u5c40Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h4>4.3 \u9000\u51fa\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u5b8c\u6210\u5de5\u4f5c\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u9000\u51fa\u540e\uff0c\u7ec8\u7aef\u5c06\u8fd4\u56de\u5168\u5c40Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528Jupyter Notebook\u8fdb\u884c\u6570\u636e\u5206\u6790<\/h3>\n<\/p>\n<p><h4>5.1 \u5b89\u88c5Jupyter Notebook<\/h4>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u4e2a\u57fa\u4e8eWeb\u7684\u4ea4\u4e92\u5f0f\u5f00\u53d1\u73af\u5883\uff0c\u9002\u5408\u6570\u636e\u5206\u6790\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u548c\u79d1\u5b66\u8ba1\u7b97\u3002\u53ef\u4ee5\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5Jupyter Notebook\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip3 install notebook<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5.2 \u542f\u52a8\u548c\u4f7f\u7528Jupyter Notebook<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8Jupyter Notebook\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">jupyter notebook<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u542f\u52a8Jupyter\u670d\u52a1\u5668\uff0c\u5e76\u5728\u9ed8\u8ba4\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00Jupyter Notebook\u754c\u9762\u3002\u5728\u754c\u9762\u4e2d\uff0c\u53ef\u4ee5\u521b\u5efa\u548c\u7f16\u8f91Notebook\u6587\u4ef6\uff0c\u8f93\u5165\u548c\u8fd0\u884cPython\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>5.3 Jupyter Notebook\u7684\u4f18\u52bf<\/h4>\n<\/p>\n<p><p>Jupyter Notebook\u652f\u6301Markdown\u548cLaTeX\uff0c\u4fbf\u4e8e\u64b0\u5199\u6587\u6863\u548c\u5c55\u793a\u7ed3\u679c\u3002\u6b64\u5916\uff0cNotebook\u652f\u6301\u53ef\u89c6\u5316\u5e93\uff0c\u5982Matplotlib\u548cSeaborn\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u7ed8\u5236\u56fe\u8868\u548c\u53ef\u89c6\u5316\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Mac\u4e0a\u4f7f\u7528Python\u5f00\u53d1\uff0c\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u9009\u62e9\uff0c\u5305\u62ec\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884cPython\u89e3\u91ca\u5668\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u901a\u8fc7Homebrew\u7ba1\u7406Python\u7248\u672c\uff0c\u4ee5\u53ca\u4f7f\u7528\u865a\u62df\u73af\u5883\u548cJupyter Notebook\u7b49\u5de5\u5177\u3002\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u548c\u5de5\u5177\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\uff0c\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u5e76\u8f7b\u677e\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u3002\u5728\u4f7f\u7528Python\u65f6\uff0c\u91cd\u8981\u7684\u662f\u4fdd\u6301\u73af\u5883\u7684\u6574\u6d01\u548c\u4f9d\u8d56\u7684\u53ef\u7ba1\u7406\u6027\uff0c\u4ee5\u4fbf\u4e8e\u9879\u76ee\u7684\u7ef4\u62a4\u548c\u6269\u5c55\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\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u8fdb\u884c\u3002\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528Homebrew\uff0c\u4e00\u4e2a\u6d41\u884c\u7684\u5305\u7ba1\u7406\u5de5\u5177\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684Mac\u4e0a\u5df2\u5b89\u88c5Homebrew\u3002\u5982\u679c\u6ca1\u6709\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a  <\/p>\n<pre><code class=\"language-bash\">\/bin\/bash -c &quot;$(curl -fsSL https:\/\/raw.githubusercontent.com\/Homebrew\/install\/HEAD\/install.sh)&quot;\n<\/code><\/pre>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8f93\u5165<code>brew install python<\/code>\u5373\u53ef\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Python\u3002\u6b64\u5916\uff0c\u4e5f\u53ef\u4ee5\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u76f4\u63a5\u4e0b\u8f7d\u5e76\u5b89\u88c5\u9002\u5408Mac\u7684\u5b89\u88c5\u5305\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Mac\u4e0a\u521b\u5efa\u548c\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u521b\u5efa\u548c\u8fd0\u884cPython\u811a\u672c\u975e\u5e38\u7b80\u5355\u3002\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982TextEdit\uff09\u6216\u66f4\u4e13\u4e1a\u7684\u7f16\u8f91\u5668\uff08\u5982Visual Studio Code\u3001Sublime Text\u7b49\uff09\u6765\u7f16\u5199\u4ee3\u7801\u3002\u5c06\u6587\u4ef6\u4fdd\u5b58\u4e3a<code>.py<\/code>\u683c\u5f0f\u3002\u8981\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u6b64\u811a\u672c\uff0c\u9996\u5148\u6253\u5f00\u7ec8\u7aef\uff0c\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\uff0c\u4f7f\u7528\u547d\u4ee4<code>python3 your_script.py<\/code>\u8fd0\u884c\u811a\u672c\u3002\u786e\u4fdd\u4f7f\u7528<code>python3<\/code>\u800c\u4e0d\u662f<code>python<\/code>\uff0c\u56e0\u4e3aMac\u9ed8\u8ba4\u53ef\u80fd\u4f1a\u5c06<code>python<\/code>\u6307\u5411Python 2.x\u7248\u672c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Mac\u4e0a\u7ba1\u7406Python\u5e93\u548c\u73af\u5883\uff1f<\/strong><br \/>\u4f7f\u7528<code>pip<\/code>\uff0cPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b89\u88c5\u548c\u7ba1\u7406\u5e93\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>pip install package_name<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002\u4e3a\u4e86\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5e93\u51b2\u7a81\uff0c\u5efa\u8bae\u4f7f\u7528\u865a\u62df\u73af\u5883\u3002\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c<code>python3 -m venv myenv<\/code>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\u3002\u6fc0\u6d3b\u73af\u5883\u540e\uff08\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>source myenv\/bin\/activate<\/code>\uff09\uff0c\u53ef\u4ee5\u5728\u8fd9\u4e2a\u9694\u79bb\u7684\u73af\u5883\u4e2d\u5b89\u88c5\u548c\u7ba1\u7406\u5e93\u3002\u5b8c\u6210\u540e\uff0c\u4f7f\u7528<code>deactivate<\/code>\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Mac\u4e2d\u4f7f\u7528Python\u7684\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\uff1a\u901a\u8fc7\u7ec8\u7aef\u8fd0\u884cPython\u89e3\u91ca\u5668\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCh [&hellip;]","protected":false},"author":3,"featured_media":1002540,"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\/1002532"}],"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=1002532"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1002532\/revisions"}],"predecessor-version":[{"id":1002543,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1002532\/revisions\/1002543"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1002540"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1002532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1002532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1002532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}