{"id":943345,"date":"2024-12-26T22:37:27","date_gmt":"2024-12-26T14:37:27","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/943345.html"},"modified":"2024-12-26T22:37:29","modified_gmt":"2024-12-26T14:37:29","slug":"macos%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/943345.html","title":{"rendered":"macos\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\/25080801\/b8bb75f1-556e-4e19-9961-6d26185c0a37.webp\" alt=\"macos\u5982\u4f55\u4f7f\u7528python\" \/><\/p>\n<p><p> <strong>\u5728macOS\u4e0a\u4f7f\u7528Python\u4e3b\u8981\u5305\u62ec\u5b89\u88c5Python\u3001\u4f7f\u7528\u7ec8\u7aef\u8fd0\u884cPython\u811a\u672c\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u7b49\u6b65\u9aa4\u3002\u5b89\u88c5Python\u3001\u8bbe\u7f6e\u865a\u62df\u73af\u5883\u3001\u9009\u62e9\u5408\u9002\u7684\u5f00\u53d1\u5de5\u5177\u662f\u5173\u952e\u6b65\u9aa4\uff0c\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5b89\u88c5Python\u7684\u65b9\u6cd5\u3002<\/strong><\/p>\n<\/p>\n<p><p>macOS\u901a\u5e38\u81ea\u5e26Python 2.x\u7248\u672c\uff0c\u4f46\u5927\u591a\u6570\u73b0\u4ee3\u5f00\u53d1\u9879\u76ee\u9700\u8981Python 3.x\u7248\u672c\u3002\u4e3a\u4e86\u5728macOS\u4e0a\u4f7f\u7528Python\uff0c\u7528\u6237\u9700\u8981\u5b89\u88c5Python 3.x\u5e76\u8fdb\u884c\u9002\u5f53\u7684\u914d\u7f6e\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Python<\/strong><\/p>\n<\/p>\n<p><p>\u5728macOS\u4e0a\u5b89\u88c5Python 3.x\u7684\u6700\u7b80\u5355\u65b9\u6cd5\u662f\u901a\u8fc7Homebrew\u3002Homebrew\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5b89\u88c5\u548c\u7ba1\u7406\u8f6f\u4ef6\u5305\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5b89\u88c5Homebrew<\/strong>\uff1a\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Homebrew\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<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python 3<\/strong>\uff1a\u5b89\u88c5Homebrew\u540e\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Python 3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew install python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c<code>python3 --version<\/code>\u547d\u4ee4\u6765\u9a8c\u8bc1\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u7ec8\u7aef\u8fd0\u884cPython\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884cPython\u811a\u672c\u3002\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u540d\u4e3a<code>script.py<\/code>\u7684Python\u811a\u672c\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u53ef\u4ee5\u76f4\u63a5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165Python\u4ee3\u7801\uff0c\u8fdb\u5165Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\uff0c\u4f7f\u7528<code>python3<\/code>\u547d\u4ee4\u5373\u53ef\u542f\u52a8\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u914d\u7f6e\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u4f9d\u8d56\u51b2\u7a81\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728macOS\u7ec8\u7aef\u4e2d\uff0c\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u7684\u547d\u4ee4\u662f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u6fc0\u6d3b\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684Python\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9009\u62e9\u5408\u9002\u7684IDE<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u5408\u9002\u7684IDE\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6d41\u884c\u7684\u9009\u62e9\uff1a<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>PyCharm<\/strong>\uff1a\u529f\u80fd\u5f3a\u5927\u7684Python\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff0c\u652f\u6301\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u548c\u7248\u672c\u63a7\u5236\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Visual Studio Code<\/strong>\uff1a\u8f7b\u91cf\u7ea7\u7684\u7f16\u8f91\u5668\uff0c\u5177\u6709\u4e30\u5bcc\u7684\u6269\u5c55\u652f\u6301\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Sublime Text<\/strong>\uff1a\u7b80\u5355\u5feb\u901f\u7684\u7f16\u8f91\u5668\uff0c\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u9009\u62e9\u4e00\u4e2a\u9002\u5408\u81ea\u5df1\u9700\u6c42\u7684IDE\uff0c\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8Python\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<hr>\n<p><h3>\u4e00\u3001\u5b89\u88c5\u4e0e\u914d\u7f6e<\/h3>\n<\/p>\n<p><p>\u5728macOS\u4e0a\u4f7f\u7528Python\u7684\u7b2c\u4e00\u6b65\u662f\u5b89\u88c5\u548c\u914d\u7f6ePython\u73af\u5883\u3002macOS\u7cfb\u7edf\u81ea\u5e26Python 2.x\u7248\u672c\uff0c\u4f46\u5927\u591a\u6570\u5e94\u7528\u548c\u5f00\u53d1\u9879\u76ee\u9700\u8981\u4f7f\u7528Python 3.x\u7248\u672c\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u5b89\u88c5\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h4>1. Homebrew\u5b89\u88c5Python 3<\/h4>\n<\/p>\n<p><p>Homebrew\u662fmacOS\u4e0a\u7684\u6d41\u884c\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b89\u88c5\u8f6f\u4ef6\u5305\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5b89\u88c5Homebrew<\/strong>\uff1a\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Homebrew\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<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python 3<\/strong>\uff1a\u5b89\u88c5Homebrew\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Python 3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew install python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f7f\u7528\u547d\u4ee4<code>python3 --version<\/code>\u6765\u9a8c\u8bc1\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>2. \u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7dPython<\/h4>\n<\/p>\n<p><p>\u9664\u4e86Homebrew\uff0c\u7528\u6237\u8fd8\u53ef\u4ee5\u4ecePython\u5b98\u7f51\u76f4\u63a5\u4e0b\u8f7dPython\u5b89\u88c5\u5305\u3002\u8bbf\u95ee<a href=\"https:\/\/www.python.org\/downloads\/\">Python\u5b98\u7f51<\/a>\uff0c\u4e0b\u8f7d\u5e76\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f\uff0c\u6309\u7167\u63d0\u793a\u5b8c\u6210\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f7f\u7528<code>python3 --version<\/code>\u547d\u4ee4\u9a8c\u8bc1\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>3. \u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u53ef\u80fd\u9700\u8981\u624b\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u4ee5\u786e\u4fdd\u6b63\u786e\u8fd0\u884cPython\u3002\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u6253\u5f00<code>.bash_profile<\/code>\u6216<code>.zshrc<\/code>\u6587\u4ef6\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PATH=&quot;\/usr\/local\/bin:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u5e76\u8fd0\u884c<code>source ~\/.bash_profile<\/code>\u6216<code>source ~\/.zshrc<\/code>\uff0c\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u7ec8\u7aef\u8fd0\u884cPython<\/h3>\n<\/p>\n<p><p>\u5728macOS\u4e0a\uff0c\u7ec8\u7aef\u662f\u8fd0\u884cPython\u811a\u672c\u7684\u4e3b\u8981\u5de5\u5177\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528\u7ec8\u7aef\u8fd0\u884cPython\u811a\u672c\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efaPython\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u4efb\u4f55\u6587\u672c\u7f16\u8f91\u5668\u521b\u5efa\u4e00\u4e2aPython\u811a\u672c\u6587\u4ef6\uff0c\u4f8b\u5982<code>script.py<\/code>\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, macOS!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u8fd0\u884cPython\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728\u7ec8\u7aef\u4e2d\uff0c\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u76ee\u5f55\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6267\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7ec8\u7aef\u5c06\u8f93\u51fa<code>Hello, macOS!<\/code>\uff0c\u8868\u793a\u811a\u672c\u8fd0\u884c\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h4>3. \u4f7f\u7528Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668<\/h4>\n<\/p>\n<p><p>\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python3<\/code>\u8fdb\u5165Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\uff0c\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u5e76\u7acb\u5373\u67e5\u770b\u7ed3\u679c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">&gt;&gt;&gt; print(&quot;Hello, interactive Python!&quot;)<\/p>\n<p>Hello, interactive Python!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u865a\u62df\u73af\u5883\u662fPython\u9879\u76ee\u5f00\u53d1\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u4f9d\u8d56\u51b2\u7a81\u3002<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efa\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>myenv<\/code>\u662f\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\uff0c\u53ef\u4ee5\u81ea\u884c\u547d\u540d\u3002<\/p>\n<\/p>\n<p><h4>2. \u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u5728macOS\u7ec8\u7aef\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u540e\uff0c\u7ec8\u7aef\u63d0\u793a\u7b26\u5c06\u663e\u793a\u865a\u62df\u73af\u5883\u540d\u79f0\uff0c\u8868\u793a\u5f53\u524d\u5904\u4e8e\u865a\u62df\u73af\u5883\u4e2d\u3002<\/p>\n<\/p>\n<p><h4>3. \u5b89\u88c5\u9879\u76ee\u4f9d\u8d56<\/h4>\n<\/p>\n<p><p>\u5728\u6fc0\u6d3b\u7684\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4f7f\u7528<code>pip<\/code>\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u4f9d\u8d56\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4. \u9000\u51fa\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u5b8c\u6210\u5f00\u53d1\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\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><h3>\u56db\u3001\u9009\u62e9\u5408\u9002\u7684IDE<\/h3>\n<\/p>\n<p><p>\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u53ef\u4ee5\u63d0\u9ad8Python\u5f00\u53d1\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6d41\u884c\u7684IDE\u9009\u62e9\uff1a<\/p>\n<\/p>\n<p><h4>1. PyCharm<\/h4>\n<\/p>\n<p><p>PyCharm\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684Python\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff0c\u652f\u6301\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u3001\u7248\u672c\u63a7\u5236\u7b49\u529f\u80fd\u3002\u5b83\u5206\u4e3a\u793e\u533a\u7248\uff08\u514d\u8d39\uff09\u548c\u4e13\u4e1a\u7248\uff08\u4ed8\u8d39\uff09\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u4e0b\u8f7d\u548c\u5b89\u88c5<\/strong>\uff1a\u8bbf\u95ee<a href=\"https:\/\/www.jetbrains.com\/pycharm\/\">PyCharm\u5b98\u7f51<\/a>\u4e0b\u8f7d\u5e76\u5b89\u88c5PyCharm\u3002<\/li>\n<li><strong>\u914d\u7f6e\u9879\u76ee<\/strong>\uff1a\u6253\u5f00PyCharm\uff0c\u521b\u5efa\u6216\u5bfc\u5165\u4e00\u4e2aPython\u9879\u76ee\uff0c\u914d\u7f6ePython\u89e3\u91ca\u5668\u548c\u865a\u62df\u73af\u5883\u3002<\/li>\n<\/ul>\n<p><h4>2. Visual Studio Code<\/h4>\n<\/p>\n<p><p>Visual Studio Code\uff08VS Code\uff09\u662f\u4e00\u6b3e\u8f7b\u91cf\u7ea7\u7684\u7f16\u8f91\u5668\uff0c\u5177\u6709\u4e30\u5bcc\u7684\u6269\u5c55\u652f\u6301\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u4e0b\u8f7d\u548c\u5b89\u88c5<\/strong>\uff1a\u8bbf\u95ee<a href=\"https:\/\/code.visualstudio.com\/\">Visual Studio Code\u5b98\u7f51<\/a>\u4e0b\u8f7d\u5e76\u5b89\u88c5VS Code\u3002<\/li>\n<li><strong>\u5b89\u88c5Python\u6269\u5c55<\/strong>\uff1a\u5728VS Code\u4e2d\u6253\u5f00\u6269\u5c55\u5e02\u573a\uff0c\u641c\u7d22\u5e76\u5b89\u88c5Python\u6269\u5c55\u3002<\/li>\n<\/ul>\n<p><h4>3. Sublime Text<\/h4>\n<\/p>\n<p><p>Sublime Text\u662f\u4e00\u6b3e\u7b80\u5355\u5feb\u901f\u7684\u7f16\u8f91\u5668\uff0c\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u4e0b\u8f7d\u548c\u5b89\u88c5<\/strong>\uff1a\u8bbf\u95ee<a href=\"https:\/\/www.sublimetext.com\/\">Sublime Text\u5b98\u7f51<\/a>\u4e0b\u8f7d\u5e76\u5b89\u88c5Sublime Text\u3002<\/li>\n<li><strong>\u5b89\u88c5Package Control<\/strong>\uff1a\u4f7f\u7528Package Control\u5b89\u88c5Python\u76f8\u5173\u63d2\u4ef6\uff0c\u5982Anaconda\u63d2\u4ef6\u3002<\/li>\n<\/ul>\n<p><h3>\u4e94\u3001\u4f7f\u7528Jupyter Notebook<\/h3>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u5f00\u53d1\u5de5\u5177\uff0c\u5e7f\u6cdb\u7528\u4e8e\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u9886\u57df\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5Jupyter Notebook<\/h4>\n<\/p>\n<p><p>\u5728\u6fc0\u6d3b\u7684\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Jupyter Notebook\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install jupyter<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u542f\u52a8Jupyter Notebook<\/h4>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\uff0c\u8fd0\u884c\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>\u6d4f\u89c8\u5668\u5c06\u81ea\u52a8\u6253\u5f00\uff0c\u663e\u793aJupyter Notebook\u7684\u7528\u6237\u754c\u9762\u3002<\/p>\n<\/p>\n<p><h4>3. \u521b\u5efa\u548c\u8fd0\u884cNotebook<\/h4>\n<\/p>\n<p><p>\u5728Jupyter Notebook\u754c\u9762\u4e2d\uff0c\u70b9\u51fb\u201cNew\u201d\u6309\u94ae\uff0c\u9009\u62e9\u201cPython 3\u201d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Notebook\u3002\u5728Notebook\u4e2d\uff0c\u53ef\u4ee5\u8f93\u5165\u548c\u6267\u884cPython\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528Python\u8fdb\u884c\u5f00\u53d1<\/h3>\n<\/p>\n<p><p>\u5728macOS\u4e0a\u642d\u5efa\u597dPython\u5f00\u53d1\u73af\u5883\u540e\uff0c\u53ef\u4ee5\u5f00\u59cb\u8fdb\u884cPython\u5f00\u53d1\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5f00\u53d1\u4efb\u52a1\uff1a<\/p>\n<\/p>\n<p><h4>1. \u6570\u636e\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Python\u5904\u7406\u6570\u636e\u662f\u5e38\u89c1\u7684\u4efb\u52a1\u4e4b\u4e00\u3002\u53ef\u4ee5\u4f7f\u7528NumPy\u548cPandas\u5e93\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5b89\u88c5NumPy\u548cPandas<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u793a\u4f8b\u4ee3\u7801<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>import pandas as pd<\/p>\n<h2><strong>\u521b\u5efaNumPy\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.array([1, 2, 3, 4, 5])<\/p>\n<p>print(array)<\/p>\n<h2><strong>\u521b\u5efaPandas\u6570\u636e\u6846<\/strong><\/h2>\n<p>data = {&#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;], &#39;Age&#39;: [25, 30, 35]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><h4>2. \u6570\u636e\u53ef\u89c6\u5316<\/h4>\n<\/p>\n<p><p>\u6570\u636e\u53ef\u89c6\u5316\u53ef\u4ee5\u5e2e\u52a9\u7406\u89e3\u548c\u5206\u6790\u6570\u636e\u3002\u53ef\u4ee5\u4f7f\u7528Matplotlib\u548cSeaborn\u5e93\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5b89\u88c5Matplotlib\u548cSeaborn<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib seaborn<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u793a\u4f8b\u4ee3\u7801<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import seaborn as sns<\/p>\n<h2><strong>\u521b\u5efa\u7b80\u5355\u7684\u6298\u7ebf\u56fe<\/strong><\/h2>\n<p>plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.title(&#39;Simple Line Plot&#39;)<\/p>\n<p>plt.show()<\/p>\n<h2><strong>\u4f7f\u7528Seaborn\u521b\u5efa\u7bb1\u7ebf\u56fe<\/strong><\/h2>\n<p>sns.boxplot(x=&#39;Age&#39;, data=df)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><h4>3. Web\u5f00\u53d1<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Python\u8fdb\u884cWeb\u5f00\u53d1\u662f\u53e6\u4e00\u79cd\u5e38\u89c1\u7684\u5e94\u7528\u3002\u53ef\u4ee5\u4f7f\u7528Flask\u6216Django\u6846\u67b6\u8fdb\u884cWeb\u5e94\u7528\u5f00\u53d1\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5b89\u88c5Flask<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install flask<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7b80\u5355\u7684Flask\u5e94\u7528<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>@app.route(&#39;\/&#39;)<\/p>\n<p>def hello():<\/p>\n<p>    return &quot;Hello, Flask!&quot;<\/p>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Django<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install django<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efaDjango\u9879\u76ee<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">django-admin startproject myproject<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><h3>\u4e03\u3001\u5e38\u89c1\u95ee\u9898\u89e3\u51b3<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Python\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1. Python\u7248\u672c\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u786e\u4fdd\u4f7f\u7528Python 3.x\u7248\u672c\u3002\u53ef\u4ee5\u901a\u8fc7<code>python3 --version<\/code>\u547d\u4ee4\u68c0\u67e5Python\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h4>2. \u73af\u5883\u53d8\u91cf\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u5728\u7ec8\u7aef\u4e2d\u65e0\u6cd5\u627e\u5230Python\u547d\u4ee4\uff0c\u53ef\u80fd\u662f\u73af\u5883\u53d8\u91cf\u672a\u6b63\u786e\u914d\u7f6e\u3002\u53ef\u4ee5\u5728<code>.bash_profile<\/code>\u6216<code>.zshrc<\/code>\u4e2d\u6dfb\u52a0Python\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><h4>3. \u4f9d\u8d56\u51b2\u7a81\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u6709\u6548\u89e3\u51b3\u4f9d\u8d56\u51b2\u7a81\u95ee\u9898\u3002\u786e\u4fdd\u5728\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u548c\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\u3002<\/p>\n<\/p>\n<p><h4>4. \u6743\u9650\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u5728\u5b89\u88c5\u8f6f\u4ef6\u5305\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u6743\u9650\u95ee\u9898\u3002\u53ef\u4ee5\u4f7f\u7528<code>sudo<\/code>\u547d\u4ee4\u63d0\u5347\u6743\u9650\uff0c\u4f46\u66f4\u63a8\u8350\u5728\u865a\u62df\u73af\u5883\u4e2d\u8fdb\u884c\u64cd\u4f5c\u4ee5\u907f\u514d\u6743\u9650\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\u548c\u6307\u5357\uff0c\u7528\u6237\u53ef\u4ee5\u5728macOS\u4e0a\u6709\u6548\u5730\u4f7f\u7528Python\u8fdb\u884c\u5f00\u53d1\u3002\u65e0\u8bba\u662f\u6570\u636e\u5206\u6790\u3001Web\u5f00\u53d1\u8fd8\u662f\u673a\u5668\u5b66\u4e60\uff0cPython\u90fd\u80fd\u63d0\u4f9b\u5f3a\u5927\u7684\u652f\u6301\u548c\u4e30\u5bcc\u7684\u5e93\u751f\u6001\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728macOS\u4e0a\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5728macOS\u4e0a\u5b89\u88c5Python\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ef\u4ee5\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff08python.org\uff09\uff0c\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u6700\u65b0\u7248\u672c\u5b89\u88c5\u5305\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\uff08Terminal\uff09\u8f93\u5165<code>python3 --version<\/code>\u6765\u786e\u8ba4\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002\u6b64\u5916\uff0cmacOS\u901a\u5e38\u9884\u88c5\u6709Python 2.x\uff0c\u5efa\u8bae\u4f7f\u7528<code>python3<\/code>\u547d\u4ee4\u6765\u786e\u4fdd\u4f7f\u7528\u7684\u662fPython 3.x\u7248\u672c\u3002<\/p>\n<p><strong>\u6211\u53ef\u4ee5\u5728macOS\u4e0a\u4f7f\u7528\u54ea\u4e9bPython\u5f00\u53d1\u73af\u5883\uff1f<\/strong><br \/>macOS\u652f\u6301\u591a\u79cdPython\u5f00\u53d1\u73af\u5883\u3002\u5e38\u89c1\u7684\u9009\u62e9\u5305\u62ecPyCharm\u3001Visual Studio Code\u548cJupyter Notebook\u7b49\u3002PyCharm\u662f\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u7684IDE\uff0c\u9002\u5408\u5927\u578b\u9879\u76ee\u5f00\u53d1\uff1b\u800cVisual Studio Code\u5219\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u7f16\u8f91\u5668\uff0c\u652f\u6301\u591a\u79cd\u63d2\u4ef6\uff0c\u975e\u5e38\u7075\u6d3b\u3002\u5bf9\u4e8e\u6570\u636e\u79d1\u5b66\u548c\u673a\u5668\u5b66\u4e60\uff0cJupyter Notebook\u63d0\u4f9b\u4e86\u4ea4\u4e92\u5f0f\u7684\u7f16\u7a0b\u4f53\u9a8c\uff0c\u9002\u5408\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\u548c\u63a2\u7d22\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728macOS\u4e0a\u4f7f\u7528pip\u5b89\u88c5Python\u5e93\uff1f<\/strong><br \/>\u5728macOS\u4e0a\uff0c\u4f7f\u7528pip\u5b89\u88c5Python\u5e93\u4e5f\u662f\u4e00\u9879\u7b80\u5355\u7684\u4efb\u52a1\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>pip3 install package_name<\/code>\uff0c\u5c06<code>package_name<\/code>\u66ff\u6362\u4e3a\u60a8\u60f3\u8981\u5b89\u88c5\u7684\u5e93\u540d\u5373\u53ef\u3002\u786e\u4fdd\u60a8\u7684pip\u662f\u6700\u65b0\u7248\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7<code>pip3 install --upgrade pip<\/code>\u547d\u4ee4\u6765\u66f4\u65b0\u3002\u6b64\u5916\uff0c\u5efa\u8bae\u4f7f\u7528\u865a\u62df\u73af\u5883\uff08\u5982venv\uff09\u6765\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\uff0c\u4ee5\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5e93\u51b2\u7a81\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728macOS\u4e0a\u4f7f\u7528Python\u4e3b\u8981\u5305\u62ec\u5b89\u88c5Python\u3001\u4f7f\u7528\u7ec8\u7aef\u8fd0\u884cPython\u811a\u672c\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883\u3001\u4f7f\u7528\u96c6\u6210\u5f00 [&hellip;]","protected":false},"author":3,"featured_media":943348,"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\/943345"}],"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=943345"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/943345\/revisions"}],"predecessor-version":[{"id":943350,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/943345\/revisions\/943350"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/943348"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=943345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=943345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=943345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}