{"id":1019856,"date":"2024-12-27T13:05:25","date_gmt":"2024-12-27T05:05:25","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1019856.html"},"modified":"2024-12-27T13:05:44","modified_gmt":"2024-12-27T05:05:44","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8mac%e8%bf%90%e8%a1%8cpython","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1019856.html","title":{"rendered":"\u5982\u4f55\u5728mac\u8fd0\u884cpython"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25162301\/73fe6043-aa50-4669-884d-326afcd4ffba.webp\" alt=\"\u5982\u4f55\u5728mac\u8fd0\u884cpython\" \/><\/p>\n<p><p> \u5728Mac\u4e0a\u8fd0\u884cPython\uff0c\u9996\u5148\u9700\u8981<strong>\u786e\u4fdd\u5df2\u5b89\u88c5Python\u3001\u901a\u8fc7\u7ec8\u7aef\u8fd0\u884cPython\u3001\u4f7f\u7528IDLE\u6216\u5176\u4ed6IDE\u3001\u8bbe\u7f6ePython\u73af\u5883\u53d8\u91cf<\/strong>\u3002\u5176\u4e2d\uff0c\u786e\u4fdd\u5df2\u5b89\u88c5Python\u662f\u5173\u952e\u7684\u4e00\u6b65\u3002\u5927\u591a\u6570\u73b0\u4ee3Mac\u90fd\u9884\u88c5\u4e86Python\uff0c\u4f46\u901a\u5e38\u662f\u65e7\u7248\u672c\u3002\u4e3a\u4e86\u4f7f\u7528\u6700\u65b0\u529f\u80fd\u548c\u5b89\u5168\u66f4\u65b0\uff0c\u5efa\u8bae\u5b89\u88c5\u6700\u65b0\u7684Python\u7248\u672c\u3002\u53ef\u4ee5\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528Homebrew\u7b49\u5305\u7ba1\u7406\u5de5\u5177\u5b89\u88c5\u3002\u5728\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u901a\u8fc7\u7ec8\u7aef\u9a8c\u8bc1Python\u7248\u672c\u4ee5\u786e\u4fdd\u5b89\u88c5\u6210\u529f\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u8ba8\u8bba\u8fd9\u4e9b\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u786e\u4fdd\u5df2\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>\u5728Mac\u4e0a\u4f7f\u7528Python\uff0c\u9996\u5148\u9700\u8981\u786e\u4fddPython\u5df2\u7ecf\u5b89\u88c5\u3002\u5927\u591a\u6570MacOS\u7cfb\u7edf\u90fd\u9884\u88c5\u4e86Python\uff0c\u4f46\u901a\u5e38\u7248\u672c\u8f83\u65e7\u3002\u5efa\u8bae\u68c0\u67e5\u5f53\u524d\u7248\u672c\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u68c0\u67e5\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c<\/strong><\/li>\n<\/ol>\n<p><p>\u8981\u68c0\u67e5Mac\u4e0a\u662f\u5426\u5df2\u5b89\u88c5Python\u53ca\u5176\u7248\u672c\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\">python --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\uff0c\u4f1a\u770b\u5230\u7c7b\u4f3c\u201cPython 2.7.16\u201d\u6216\u201cPython 3.9.1\u201d\u7684\u8f93\u51fa\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\u6216\u7248\u672c\u592a\u65e7\uff0c\u9700\u8981\u5b89\u88c5\u65b0\u7248\u672c\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Python<\/strong><\/li>\n<\/ol>\n<p><p>\u4e3a\u4e86\u786e\u4fdd\u4f7f\u7528\u6700\u65b0\u7684Python\u7248\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b89\u88c5Python\u3002\u4ee5\u4e0b\u662f\u4e24\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d<\/strong><\/p>\n<\/p>\n<p><p>\u8bbf\u95eePython\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.python.org\/%EF%BC%89%EF%BC%8C%E4%B8%8B%E8%BD%BD%E9%80%82%E7%94%A8%E4%BA%8EMac%E7%9A%84%E6%9C%80%E6%96%B0%E7%89%88%E6%9C%AC%E5%AE%89%E8%A3%85%E5%8C%85%E3%80%82%E4%B8%8B%E8%BD%BD%E5%AE%8C%E6%88%90%E5%90%8E%EF%BC%8C%E8%BF%90%E8%A1%8C%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F%EF%BC%8C%E6%8C%89%E7%85%A7%E6%8F%90%E7%A4%BA%E5%AE%8C%E6%88%90%E5%AE%89%E8%A3%85%E3%80%82\">https:\/\/www.python.org\/\uff09\uff0c\u4e0b\u8f7d\u9002\u7528\u4e8eMac\u7684\u6700\u65b0\u7248\u672c\u5b89\u88c5\u5305\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f\uff0c\u6309\u7167\u63d0\u793a\u5b8c\u6210\u5b89\u88c5\u3002<\/a><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Homebrew\u5b89\u88c5<\/strong><\/p>\n<\/p>\n<p><p>Homebrew\u662fMac\u4e0a\u7684\u4e00\u4e2a\u6d41\u884c\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b89\u88c5\u8f6f\u4ef6\u5305\u3002\u5728\u7ec8\u7aef\u4e2d\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<p><p>\u7136\u540e\u4f7f\u7528Homebrew\u5b89\u88c5Python\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\u91cd\u65b0\u6253\u5f00\u7ec8\u7aef\uff0c\u68c0\u67e5Python\u7248\u672c\u4ee5\u786e\u4fdd\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u901a\u8fc7\u7ec8\u7aef\u8fd0\u884cPython<\/p>\n<\/p>\n<p><p>\u5728Mac\u4e0a\uff0c\u7ec8\u7aef\u662f\u8fd0\u884cPython\u7684\u4e00\u4e2a\u91cd\u8981\u5de5\u5177\u3002\u901a\u8fc7\u7ec8\u7aef\u53ef\u4ee5\u76f4\u63a5\u6267\u884cPython\u811a\u672c\u5e76\u8fdb\u884c\u4ea4\u4e92\u5f0f\u7f16\u7a0b\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u542f\u52a8Python\u89e3\u91ca\u5668<\/strong><\/li>\n<\/ol>\n<p><p>\u8981\u542f\u52a8Python\u89e3\u91ca\u5668\uff0c\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u5b89\u88c5\u4e86Python 3\uff0c\u5efa\u8bae\u4f7f\u7528<code>python3<\/code>\u547d\u4ee4\u3002\u542f\u52a8\u540e\u4f1a\u8fdb\u5165Python\u4ea4\u4e92\u6a21\u5f0f\uff0c\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u8fdb\u884c\u6d4b\u8bd5\u3002\u4f8b\u5982\uff0c\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\u6253\u5370\u201cHello, World!\u201d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6267\u884cPython\u811a\u672c<\/strong><\/li>\n<\/ol>\n<p><p>\u9664\u4e86\u4ea4\u4e92\u5f0f\u7f16\u7a0b\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u6267\u884c\u5b8c\u6574\u7684Python\u811a\u672c\u3002\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a<code>example.py<\/code>\u7684Python\u811a\u672c\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># example.py<\/p>\n<p>print(&quot;Hello from example script!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8981\u6267\u884c\u8be5\u811a\u672c\uff0c\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python example.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 example.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7ec8\u7aef\u5c06\u6267\u884c\u811a\u672c\u5e76\u8f93\u51fa\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528IDLE\u6216\u5176\u4ed6IDE<\/p>\n<\/p>\n<p><p>\u5728Mac\u4e0a\u8fd0\u884cPython\uff0c\u9664\u4e86\u7ec8\u7aef\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528IDLE\u6216\u5176\u4ed6\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\uff0c\u5982PyCharm\u3001VS Code\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528IDLE<\/strong><\/li>\n<\/ol>\n<p><p>IDLE\u662fPython\u81ea\u5e26\u7684\u8f7b\u91cf\u7ea7IDE\uff0c\u9002\u5408\u521d\u5b66\u8005\u4f7f\u7528\u3002\u5b89\u88c5Python\u65f6\uff0c\u901a\u5e38\u4f1a\u81ea\u52a8\u5b89\u88c5IDLE\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u542f\u52a8IDLE\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u627e\u5230IDLE\u56fe\u6807\u5e76\u53cc\u51fb\u542f\u52a8\u3002<\/li>\n<li>\u6253\u5f00\u540e\uff0c\u53ef\u4ee5\u5728IDLE\u7684\u4ea4\u4e92\u7a97\u53e3\u4e2d\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u3002<\/li>\n<li>\u8981\u521b\u5efa\u548c\u8fd0\u884cPython\u811a\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7\u83dc\u5355\u9009\u62e9\u201cFile\u201d -&gt; \u201cNew File\u201d\u521b\u5efa\u65b0\u6587\u4ef6\uff0c\u5e76\u5728\u65b0\u7a97\u53e3\u4e2d\u7f16\u5199\u4ee3\u7801\u3002\u7f16\u5199\u5b8c\u6210\u540e\uff0c\u9009\u62e9\u201cRun\u201d -&gt; \u201cRun Module\u201d\u8fd0\u884c\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528\u5176\u4ed6IDE<\/strong><\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u9879\u76ee\uff0c\u5efa\u8bae\u4f7f\u7528\u529f\u80fd\u66f4\u5f3a\u5927\u7684IDE\uff0c\u5982PyCharm\u3001Visual Studio Code\u7b49\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>PyCharm<\/strong><\/p>\n<\/p>\n<p><p>PyCharm\u662fJetBr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ns\u516c\u53f8\u5f00\u53d1\u7684\u4e13\u4e1aPython IDE\uff0c\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u4ee3\u7801\u7f16\u8f91\u3001\u8c03\u8bd5\u548c\u6d4b\u8bd5\u529f\u80fd\u3002\u53ef\u4ee5\u4ecePyCharm\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u521b\u5efa\u65b0\u9879\u76ee\uff0c\u5bfc\u5165\u73b0\u6709\u9879\u76ee\uff0c\u5e76\u4f7f\u7528\u5185\u7f6e\u5de5\u5177\u8fdb\u884c\u5f00\u53d1\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Visual Studio Code<\/strong><\/p>\n<\/p>\n<p><p>Visual Studio Code\uff08VS Code\uff09\u662f\u5fae\u8f6f\u5f00\u53d1\u7684\u5f00\u6e90\u7f16\u8f91\u5668\uff0c\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u3002\u901a\u8fc7\u5b89\u88c5Python\u6269\u5c55\uff0cVS Code\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u5f3a\u5927\u7684Python\u5f00\u53d1\u73af\u5883\u3002\u53ef\u4ee5\u4eceVS Code\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5\uff0c\u7136\u540e\u5728\u6269\u5c55\u5e02\u573a\u4e2d\u641c\u7d22\u5e76\u5b89\u88c5Python\u6269\u5c55\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u56db\u3001\u8bbe\u7f6ePython\u73af\u5883\u53d8\u91cf<\/p>\n<\/p>\n<p><p>\u5728Mac\u4e0a\u8fd0\u884cPython\uff0c\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u6709\u52a9\u4e8e\u7ba1\u7406Python\u7248\u672c\u548c\u5e93\u8def\u5f84\uff0c\u786e\u4fdd\u7a0b\u5e8f\u6b63\u786e\u6267\u884c\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u914d\u7f6ePATH\u73af\u5883\u53d8\u91cf<\/strong><\/li>\n<\/ol>\n<p><p>\u4e3a\u4e86\u5728\u7ec8\u7aef\u4e2d\u65b9\u4fbf\u5730\u8c03\u7528Python\u547d\u4ee4\uff0c\u53ef\u4ee5\u5c06Python\u7684\u5b89\u88c5\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684PATH\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u53ef\u4ee5\u901a\u8fc7\u7f16\u8f91<code>~\/.bash_profile<\/code>\u6216<code>~\/.zshrc<\/code>\u6587\u4ef6\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><p>\u5047\u8bbePython\u7684\u5b89\u88c5\u8def\u5f84\u4e3a<code>\/usr\/local\/bin\/python3<\/code>\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8f91\u73af\u5883\u53d8\u91cf\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">nano ~\/.zshrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6587\u4ef6\u672b\u5c3e\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\u9000\u51fa\u7f16\u8f91\u5668\u540e\uff0c\u91cd\u65b0\u52a0\u8f7d\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source ~\/.zshrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528pyenv\u7ba1\u7406Python\u7248\u672c<\/strong><\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u540c\u65f6\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u7684\u5f00\u53d1\u8005\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pyenv<\/code>\u5de5\u5177\u3002<code>pyenv<\/code>\u5141\u8bb8\u5728\u4e0d\u540c\u7248\u672c\u4e4b\u95f4\u5207\u6362\uff0c\u65b9\u4fbf\u6d4b\u8bd5\u548c\u5f00\u53d1\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p>\u5b89\u88c5pyenv<\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7Homebrew\u5b89\u88c5pyenv\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew install pyenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u5b89\u88c5\u4e0d\u540c\u7248\u672c\u7684Python<\/p>\n<\/p>\n<p><p>\u4f7f\u7528pyenv\u5b89\u88c5\u7279\u5b9a\u7248\u672c\u7684Python\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv install 3.8.10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u5207\u6362Python\u7248\u672c<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5207\u6362Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv global 3.8.10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u4e94\u3001\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305<\/p>\n<\/p>\n<p><p>Python\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u5176\u4e30\u5bcc\u7684\u7b2c\u4e09\u65b9\u5e93\u548c\u6a21\u5757\u3002\u5728Mac\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u6765\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528pip\u5b89\u88c5\u5305<\/strong><\/li>\n<\/ol>\n<p><p>pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u901a\u5e38\u4f1a\u968fPython\u4e00\u8d77\u5b89\u88c5\u3002\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u4f7f\u7528pip\u5b89\u88c5\u6240\u9700\u7684\u7b2c\u4e09\u65b9\u5e93\u3002\u4f8b\u5982\uff0c\u5b89\u88c5requests\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip3 install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u5e76\u4f7f\u7528\u8be5\u5e93\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u7ba1\u7406\u865a\u62df\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u5f00\u53d1\u4e0d\u540c\u9879\u76ee\u65f6\uff0c\u53ef\u80fd\u9700\u8981\u7ba1\u7406\u4e0d\u540c\u7684\u5e93\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u865a\u62df\u73af\u5883\uff08virtual environment\uff09\u6765\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p>\u521b\u5efa\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\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>\u8fd9\u5c06\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>myenv<\/code>\u7684\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p>\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\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\u4f1a\u663e\u793a\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\uff0c\u8fd9\u65f6\u5b89\u88c5\u7684\u4efb\u4f55Python\u5305\u90fd\u53ea\u4f1a\u5f71\u54cd\u8be5\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u9000\u51fa\u865a\u62df\u73af\u5883<\/p>\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<\/li>\n<\/ul>\n<p><p>\u516d\u3001\u8c03\u8bd5Python\u4ee3\u7801<\/p>\n<\/p>\n<p><p>\u5728\u7f16\u5199Python\u7a0b\u5e8f\u65f6\uff0c\u8c03\u8bd5\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u73af\u8282\u3002\u65e0\u8bba\u662f\u5728\u7ec8\u7aef\u8fd8\u662f\u5728IDE\u4e2d\uff0c\u90fd\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u5de5\u5177\u548c\u6280\u672f\u8fdb\u884c\u8c03\u8bd5\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528print\u8bed\u53e5\u8c03\u8bd5<\/strong><\/li>\n<\/ol>\n<p><p>\u6700\u7b80\u5355\u7684\u8c03\u8bd5\u65b9\u6cd5\u662f\u4f7f\u7528print\u8bed\u53e5\u8f93\u51fa\u53d8\u91cf\u7684\u503c\u548c\u7a0b\u5e8f\u7684\u6267\u884c\u8def\u5f84\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u7b80\u5355\u7684\u8c03\u8bd5\u4efb\u52a1\u548c\u521d\u5b66\u8005\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def example_function(x):<\/p>\n<p>    print(f&quot;Input value: {x}&quot;)<\/p>\n<p>    result = x * 2<\/p>\n<p>    print(f&quot;Result: {result}&quot;)<\/p>\n<p>    return result<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u5728\u5173\u952e\u4f4d\u7f6e\u6dfb\u52a0print\u8bed\u53e5\uff0c\u53ef\u4ee5\u89c2\u5bdf\u7a0b\u5e8f\u7684\u8fd0\u884c\u60c5\u51b5\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528pdb\u6a21\u5757\u8fdb\u884c\u8c03\u8bd5<\/strong><\/li>\n<\/ol>\n<p><p>pdb\u662fPython\u5185\u7f6e\u7684\u8c03\u8bd5\u5668\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8fdb\u884c\u66f4\u8be6\u7ec6\u7684\u8c03\u8bd5\u3002\u901a\u8fc7\u5728\u4ee3\u7801\u4e2d\u63d2\u5165\u4ee5\u4e0b\u884c\uff0c\u53ef\u4ee5\u542f\u52a8pdb\u8c03\u8bd5\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pdb; pdb.set_trace()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7a0b\u5e8f\u6267\u884c\u5230\u8fd9\u884c\u65f6\u4f1a\u6682\u505c\uff0c\u5e76\u8fdb\u5165\u4ea4\u4e92\u5f0f\u8c03\u8bd5\u6a21\u5f0f\uff0c\u53ef\u4ee5\u67e5\u770b\u53d8\u91cf\u503c\u3001\u6267\u884c\u4e0b\u4e00\u6b65\u7b49\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u4f7f\u7528IDE\u7684\u8c03\u8bd5\u5de5\u5177<\/strong><\/li>\n<\/ol>\n<p><p>\u5927\u591a\u6570IDE\u90fd\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u65ad\u70b9\u3001\u5355\u6b65\u6267\u884c\u3001\u67e5\u770b\u53d8\u91cf\u503c\u7b49\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>PyCharm<\/strong><\/p>\n<\/p>\n<p><p>\u5728PyCharm\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u4ee3\u7801\u884c\u5de6\u4fa7\u7684\u7070\u8272\u8fb9\u6846\u8bbe\u7f6e\u65ad\u70b9\u3002\u7136\u540e\u70b9\u51fb\u201cDebug\u201d\u6309\u94ae\u542f\u52a8\u8c03\u8bd5\u6a21\u5f0f\u3002\u7a0b\u5e8f\u8fd0\u884c\u5230\u65ad\u70b9\u65f6\u4f1a\u6682\u505c\uff0c\u53ef\u4ee5\u67e5\u770b\u53d8\u91cf\u503c\u548c\u6267\u884c\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Visual Studio Code<\/strong><\/p>\n<\/p>\n<p><p>\u5728VS Code\u4e2d\uff0c\u5b89\u88c5Python\u6269\u5c55\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\u3002\u70b9\u51fb\u4ee3\u7801\u884c\u5de6\u4fa7\u7684\u7a7a\u767d\u533a\u57df\u8bbe\u7f6e\u65ad\u70b9\uff0c\u7136\u540e\u9009\u62e9\u201cRun and Debug\u201d\u542f\u52a8\u8c03\u8bd5\u6a21\u5f0f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u4e03\u3001\u7ba1\u7406Python\u9879\u76ee<\/p>\n<\/p>\n<p><p>\u5728Mac\u4e0a\u5f00\u53d1Python\u9879\u76ee\u65f6\uff0c\u826f\u597d\u7684<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/23316.html\" target=\"_blank\">\u9879\u76ee\u7ba1\u7406<\/a>\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u4ee3\u7801\u8d28\u91cf\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u7ec4\u7ec7\u9879\u76ee\u7ed3\u6784<\/strong><\/li>\n<\/ol>\n<p><p>\u4e3a\u4fbf\u4e8e\u7ef4\u62a4\u548c\u6269\u5c55\uff0c\u5efa\u8bae\u9075\u5faaPython\u7684\u9879\u76ee\u7ed3\u6784\u6807\u51c6\u3002\u4e00\u4e2a\u5178\u578b\u7684\u9879\u76ee\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code>my_project\/<\/p>\n<p>\u2502<\/p>\n<p>\u251c\u2500\u2500 my_project\/<\/p>\n<p>\u2502   \u251c\u2500\u2500 __init__.py<\/p>\n<p>\u2502   \u251c\u2500\u2500 module1.py<\/p>\n<p>\u2502   \u251c\u2500\u2500 module2.py<\/p>\n<p>\u2502<\/p>\n<p>\u251c\u2500\u2500 tests\/<\/p>\n<p>\u2502   \u251c\u2500\u2500 test_module1.py<\/p>\n<p>\u2502   \u251c\u2500\u2500 test_module2.py<\/p>\n<p>\u2502<\/p>\n<p>\u251c\u2500\u2500 README.md<\/p>\n<p>\u251c\u2500\u2500 setup.py<\/p>\n<p>\u251c\u2500\u2500 requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>my_project\/<\/code>\u76ee\u5f55\u5b58\u653e\u9879\u76ee\u7684\u6838\u5fc3\u4ee3\u7801\u3002<\/li>\n<li><code>tests\/<\/code>\u76ee\u5f55\u5b58\u653e\u6d4b\u8bd5\u4ee3\u7801\u3002<\/li>\n<li><code>README.md<\/code>\u63d0\u4f9b\u9879\u76ee\u7684\u57fa\u672c\u4fe1\u606f\u548c\u4f7f\u7528\u8bf4\u660e\u3002<\/li>\n<li><code>setup.py<\/code>\u7528\u4e8e\u6253\u5305\u548c\u53d1\u5e03\u9879\u76ee\u3002<\/li>\n<li><code>requirements.txt<\/code>\u5217\u51fa\u9879\u76ee\u7684\u4f9d\u8d56\u5e93\u53ca\u5176\u7248\u672c\u3002<\/li>\n<\/ul>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf<\/strong><\/li>\n<\/ol>\n<p><p>\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08\u5982Git\uff09\u53ef\u4ee5\u8ddf\u8e2a\u4ee3\u7801\u53d8\u66f4\u3001\u534f\u4f5c\u5f00\u53d1\u5e76\u56de\u6eda\u5230\u5386\u53f2\u7248\u672c\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u521d\u59cb\u5316Git\u4ed3\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">git init<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u6839\u636e\u9700\u8981\u6dfb\u52a0\u3001\u63d0\u4ea4\u548c\u63a8\u9001\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">git add .<\/p>\n<p>git commit -m &quot;Initial commit&quot;<\/p>\n<p>git push origin main<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u7f16\u5199\u6d4b\u8bd5<\/strong><\/li>\n<\/ol>\n<p><p>\u7f16\u5199\u6d4b\u8bd5\u53ef\u4ee5\u786e\u4fdd\u4ee3\u7801\u7684\u6b63\u786e\u6027\u548c\u7a33\u5b9a\u6027\u3002\u53ef\u4ee5\u4f7f\u7528Python\u7684unittest\u6a21\u5757\u6216\u7b2c\u4e09\u65b9\u6d4b\u8bd5\u6846\u67b6\u5982pytest\u7f16\u5199\u548c\u8fd0\u884c\u6d4b\u8bd5\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>unittest<\/strong><\/p>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u6d4b\u8bd5\u6a21\u5757\uff0c\u4f8b\u5982<code>test_module1.py<\/code>\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unittest<\/p>\n<p>from my_project.module1 import my_function<\/p>\n<p>class TestMyFunction(unittest.TestCase):<\/p>\n<p>    def test_case1(self):<\/p>\n<p>        self.assertEqual(my_function(2), 4)<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    unittest.main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>pytest<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7pip\u5b89\u88c5pytest\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pytest<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u521b\u5efa\u6d4b\u8bd5\u6587\u4ef6\u540e\uff0c\u53ef\u4ee5\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u8fd0\u884cpytest\u547d\u4ee4\u4ee5\u6267\u884c\u6d4b\u8bd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pytest<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u516b\u3001\u53d1\u5e03\u548c\u5206\u53d1Python\u5305<\/p>\n<\/p>\n<p><p>\u5f00\u53d1\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5c06Python\u9879\u76ee\u6253\u5305\u5e76\u53d1\u5e03\u5230Python Package Index\uff08PyPI\uff09\uff0c\u4ee5\u4fbf\u5176\u4ed6\u5f00\u53d1\u8005\u4f7f\u7528\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u51c6\u5907setup.py<\/strong><\/li>\n<\/ol>\n<p><p><code>setup.py<\/code>\u6587\u4ef6\u7528\u4e8e\u5b9a\u4e49\u5305\u7684\u5143\u6570\u636e\u548c\u4f9d\u8d56\u9879\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from setuptools import setup, find_packages<\/p>\n<p>setup(<\/p>\n<p>    name=&#39;my_project&#39;,<\/p>\n<p>    version=&#39;0.1&#39;,<\/p>\n<p>    packages=find_packages(),<\/p>\n<p>    install_requires=[<\/p>\n<p>        &#39;requests&#39;,<\/p>\n<p>    ],<\/p>\n<p>    author=&#39;Your Name&#39;,<\/p>\n<p>    author_email=&#39;your.email@example.com&#39;,<\/p>\n<p>    description=&#39;A simple example project&#39;,<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6253\u5305\u548c\u53d1\u5e03<\/strong><\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4f7f\u7528setuptools\u548ctwine\u5de5\u5177\u6253\u5305\u5e76\u53d1\u5e03\u9879\u76ee\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p>\u5b89\u88c5\u5fc5\u8981\u5de5\u5177\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install setuptools twine<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u6253\u5305\u9879\u76ee\uff1a<\/p>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u751f\u6210\u5206\u53d1\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py sdist bdist_wheel<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u53d1\u5e03\u5230PyPI\uff1a<\/p>\n<\/p>\n<p><p>\u4f7f\u7528twine\u5c06\u5305\u4e0a\u4f20\u5230PyPI\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">twine upload dist\/*<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u5728\u53d1\u5e03\u4e4b\u524d\uff0c\u9700\u8981\u5728PyPI\u7f51\u7ad9\u4e0a\u6ce8\u518c\u4e00\u4e2a\u8d26\u53f7\u5e76\u751f\u6210API token\u3002<\/p>\n<\/p>\n<p><p>\u4e5d\u3001\u4f18\u5316\u548c\u7ef4\u62a4Python\u73af\u5883<\/p>\n<\/p>\n<p><p>\u5728Mac\u4e0a\u4f7f\u7528Python\u8fdb\u884c\u5f00\u53d1\u65f6\uff0c\u7ef4\u62a4\u826f\u597d\u7684\u5f00\u53d1\u73af\u5883\u6709\u52a9\u4e8e\u63d0\u9ad8\u751f\u4ea7\u529b\u548c\u4ee3\u7801\u8d28\u91cf\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b9a\u671f\u66f4\u65b0Python\u548c\u5e93<\/strong><\/li>\n<\/ol>\n<p><p>\u5b9a\u671f\u66f4\u65b0Python\u7248\u672c\u548c\u7b2c\u4e09\u65b9\u5e93\u53ef\u4ee5\u83b7\u5f97\u6700\u65b0\u7684\u529f\u80fd\u548c\u5b89\u5168\u8865\u4e01\u3002\u53ef\u4ee5\u4f7f\u7528Homebrew\u66f4\u65b0Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew upgrade python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528pip\u66f4\u65b0\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install --upgrade package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u66f4\u65b0\u6240\u6709\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip list --outdated | cut -d &#39; &#39; -f 1 | xargs -n1 pip install -U<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u7ba1\u7406\u591a\u4e2aPython\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u540c\u65f6\u5904\u7406\u591a\u4e2a\u9879\u76ee\u7684\u5f00\u53d1\u8005\uff0c\u4f7f\u7528\u5de5\u5177\u5982<code>virtualenv<\/code>\u6216<code>pyenv<\/code>\u7ba1\u7406\u591a\u4e2aPython\u73af\u5883\u662f\u975e\u5e38\u6709\u76ca\u7684\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>virtualenv<\/strong><\/p>\n<\/p>\n<p><p><code>virtualenv<\/code>\u5141\u8bb8\u521b\u5efa\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u6bcf\u4e2a\u73af\u5883\u90fd\u53ef\u4ee5\u6709\u81ea\u5df1\u7684\u5e93\u7248\u672c\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">virtualenv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\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<\/li>\n<li>\n<p><strong>pyenv-virtualenv<\/strong><\/p>\n<\/p>\n<p><p><code>pyenv-virtualenv<\/code>\u7ed3\u5408\u4e86pyenv\u548cvirtualenv\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u540c\u65f6\u7ba1\u7406Python\u7248\u672c\u548c\u865a\u62df\u73af\u5883\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u521b\u5efa\u548c\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv virtualenv 3.8.10 myenv<\/p>\n<p>pyenv activate myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u5341\u3001\u5b66\u4e60\u548c\u63d0\u5347Python\u6280\u80fd<\/p>\n<\/p>\n<p><p>\u4e0d\u65ad\u5b66\u4e60\u548c\u63d0\u5347Python\u6280\u80fd\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u9ad8\u6548\u5730\u89e3\u51b3\u95ee\u9898\u548c\u5f00\u53d1\u521b\u65b0\u7684\u9879\u76ee\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u9605\u8bfb\u5b98\u65b9\u6587\u6863<\/strong><\/li>\n<\/ol>\n<p><p>Python\u7684\u5b98\u65b9\u6587\u6863\u662f\u5b66\u4e60Python\u7684\u6743\u5a01\u8d44\u6599\uff0c\u6db5\u76d6\u4e86\u8bed\u8a00\u7684\u6240\u6709\u7279\u6027\u3001\u6807\u51c6\u5e93\u548c\u5e38\u7528\u6a21\u5757\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95eePython\u5b98\u7f51\u83b7\u53d6\u6587\u6863\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee<\/strong><\/li>\n<\/ol>\n<p><p>\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\u662f\u63d0\u5347\u7f16\u7a0b\u6280\u80fd\u548c\u79ef\u7d2f\u7ecf\u9a8c\u7684\u597d\u65b9\u6cd5\u3002\u53ef\u4ee5\u5728GitHub\u4e0a\u5bfb\u627e\u611f\u5174\u8da3\u7684Python\u9879\u76ee\uff0c\u8d21\u732e\u4ee3\u7801\u6216\u62a5\u544a\u95ee\u9898\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u53c2\u52a0\u793e\u533a\u6d3b\u52a8<\/strong><\/li>\n<\/ol>\n<p><p>\u53c2\u52a0Python\u793e\u533a\u6d3b\u52a8\uff0c\u5982PyCon\u4f1a\u8bae\u3001\u6280\u672f\u5206\u4eab\u4f1a\u7b49\uff0c\u53ef\u4ee5\u4e0e\u5176\u4ed6\u5f00\u53d1\u8005\u4ea4\u6d41\u7ecf\u9a8c\uff0c\u4e86\u89e3\u884c\u4e1a\u8d8b\u52bf\u548c\u65b0\u6280\u672f\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0d\u65ad\u5b66\u4e60\u548c\u5b9e\u8df5\uff0c\u53ef\u4ee5\u5728Mac\u4e0a\u66f4\u9ad8\u6548\u5730\u8fd0\u884c\u548c\u5f00\u53d1Python\u5e94\u7528\u7a0b\u5e8f\u3002\u5e0c\u671b\u672c\u6587\u7684\u8be6\u7ec6\u4ecb\u7ecd\u80fd\u591f\u5e2e\u52a9\u60a8\u5728Mac\u73af\u5883\u4e0b\u66f4\u597d\u5730\u4f7f\u7528Python\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\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff08python.org\uff09\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684Python\u5b89\u88c5\u5305\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u53cc\u51fb\u5b89\u88c5\u5305\u5e76\u6309\u7167\u63d0\u793a\u8fdb\u884c\u5b89\u88c5\u3002\u6b64\u5916\uff0cMac\u7cfb\u7edf\u9ed8\u8ba4\u5b89\u88c5\u4e86Python 2.x\u7248\u672c\uff0c\u5982\u679c\u9700\u8981\u4f7f\u7528Python 3.x\u7248\u672c\uff0c\u5efa\u8bae\u60a8\u8fdb\u884c\u624b\u52a8\u5b89\u88c5\u5e76\u786e\u4fdd\u5728\u7ec8\u7aef\u4e2d\u4f7f\u7528<code>python3<\/code>\u547d\u4ee4\u6765\u8fd0\u884c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Mac\u4e0a\u4f7f\u7528\u7ec8\u7aef\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u5728Mac\u4e0a\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u8f7b\u677e\u8fd0\u884cPython\u811a\u672c\u3002\u9996\u5148\uff0c\u6253\u5f00\u7ec8\u7aef\u5e94\u7528\u7a0b\u5e8f\uff0c\u7136\u540e\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u82e5\u60a8\u7684\u811a\u672c\u5b58\u50a8\u5728\u201c\u6587\u6863\u201d\u6587\u4ef6\u5939\u4e2d\uff0c\u53ef\u4ee5\u8f93\u5165<code>cd ~\/Documents<\/code>\u3002\u63a5\u4e0b\u6765\uff0c\u8f93\u5165<code>python3 your_script.py<\/code>\u6765\u8fd0\u884c\u60a8\u7684Python\u811a\u672c\uff0c\u786e\u4fdd\u5c06<code>your_script.py<\/code>\u66ff\u6362\u4e3a\u60a8\u7684\u6587\u4ef6\u540d\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Mac\u4e0a\u5b89\u88c5Python\u5e93\uff1f<\/strong><br \/>\u5728Mac\u4e0a\u5b89\u88c5Python\u5e93\u901a\u5e38\u4f7f\u7528<code>pip<\/code>\u5de5\u5177\u3002\u82e5\u60a8\u5df2\u7ecf\u5b89\u88c5\u4e86Python 3\uff0c<code>pip<\/code>\u901a\u5e38\u4f1a\u968f\u4e4b\u5b89\u88c5\u3002\u6253\u5f00\u7ec8\u7aef\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>pip install package_name<\/code>\u547d\u4ee4\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93\uff0c\u4f8b\u5982\uff0c<code>pip install numpy<\/code>\u3002\u786e\u4fdd\u5728\u5b89\u88c5\u5e93\u65f6\uff0c\u60a8\u6709\u7a33\u5b9a\u7684\u4e92\u8054\u7f51\u8fde\u63a5\uff0c\u5e76\u4e14\u5728\u5fc5\u8981\u65f6\u4f7f\u7528<code>sudo<\/code>\u547d\u4ee4\u83b7\u53d6\u7ba1\u7406\u5458\u6743\u9650\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Mac\u4e0a\u8fd0\u884cPython\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5df2\u5b89\u88c5Python\u3001\u901a\u8fc7\u7ec8\u7aef\u8fd0\u884cPython\u3001\u4f7f\u7528IDLE\u6216\u5176\u4ed6IDE [&hellip;]","protected":false},"author":3,"featured_media":1019894,"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\/1019856"}],"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=1019856"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1019856\/revisions"}],"predecessor-version":[{"id":1019895,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1019856\/revisions\/1019895"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1019894"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1019856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1019856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1019856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}