{"id":995070,"date":"2024-12-27T09:01:32","date_gmt":"2024-12-27T01:01:32","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/995070.html"},"modified":"2024-12-27T09:01:37","modified_gmt":"2024-12-27T01:01:37","slug":"python%e8%8b%b9%e6%9e%9c%e7%b3%bb%e7%bb%9f%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/995070.html","title":{"rendered":"python\u82f9\u679c\u7cfb\u7edf\u5982\u4f55\u5b89\u88c5"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25071816\/b171babc-3987-4dfb-80bb-3bc93296ba21.webp\" alt=\"python\u82f9\u679c\u7cfb\u7edf\u5982\u4f55\u5b89\u88c5\" \/><\/p>\n<p><p> \u4e00\u3001\u5728\u82f9\u679c\u7cfb\u7edf\u4e0a\u5b89\u88c5Python\u7684\u6b65\u9aa4<\/p>\n<\/p>\n<p><p>\u5728\u82f9\u679c\u7cfb\u7edf\u4e0a\u5b89\u88c5Python\u975e\u5e38\u7b80\u5355\uff0c<strong>\u4f60\u53ef\u4ee5\u4f7f\u7528MacOS\u81ea\u5e26\u7684Python\u3001\u901a\u8fc7Homebrew\u5b89\u88c5Python\u3001\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5<\/strong>\u3002\u5176\u4e2d\uff0c<strong>\u901a\u8fc7Homebrew\u5b89\u88c5Python<\/strong>\u662f\u63a8\u8350\u7684\u65b9\u5f0f\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u5e2e\u52a9\u4f60\u8f7b\u677e\u7ba1\u7406\u4e0d\u540c\u7248\u672c\u7684Python\u4ee5\u53ca\u76f8\u5173\u7684\u8f6f\u4ef6\u5305\u3002\u5728\u5b89\u88c5\u524d\uff0c\u786e\u4fdd\u4f60\u7684\u7cfb\u7edf\u7248\u672c\u548c\u5b89\u88c5\u5de5\u5177\u662f\u6700\u65b0\u7684\uff0c\u4ee5\u907f\u514d\u6f5c\u5728\u7684\u517c\u5bb9\u6027\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u6b65\u9aa4\u5c55\u5f00\uff1a<\/strong><br \/>\u901a\u8fc7Homebrew\u5b89\u88c5Python\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Homebrew<\/strong>\uff1aHomebrew\u662f\u4e00\u4e2a\u6d41\u884c\u7684MacOS\u8f6f\u4ef6\u5305\u7ba1\u7406\u5668\u3002\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<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8fd0\u884c<code>brew doctor<\/code>\u6765\u68c0\u67e5Homebrew\u662f\u5426\u6b63\u5e38\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python<\/strong>\uff1a\u4f7f\u7528Homebrew\u5b89\u88c5Python\u53ea\u9700\u4e00\u884c\u547d\u4ee4\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew install python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5b89\u88c5Python\u7684\u6700\u65b0\u7248\u672c\uff0c\u5e76\u540c\u65f6\u5b89\u88c5<code>pip<\/code>\uff0cPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong>\uff1a\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u9a8c\u8bc1Python\u548cpip\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p>pip3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u663e\u793aPython\u548cpip\u7684\u7248\u672c\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u5728\u82f9\u679c\u7cfb\u7edf\u4e0a\u4f7f\u7528\u81ea\u5e26Python<\/p>\n<\/p>\n<p><p>\u82f9\u679c\u7cfb\u7edf\u901a\u5e38\u81ea\u5e26Python\uff0c\u4f46\u8fd9\u4e2a\u7248\u672c\u53ef\u80fd\u4e0d\u662f\u6700\u65b0\u7684\uff0c\u56e0\u6b64\u5728\u4f7f\u7528\u524d\u9700\u8981\u786e\u8ba4\u5b83\u662f\u5426\u6ee1\u8db3\u4f60\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5\u7cfb\u7edf\u81ea\u5e26Python<\/strong>\uff1a\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770bPython\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u81ea\u5e26Python<\/strong>\uff1a\u5982\u679c\u7cfb\u7edf\u81ea\u5e26\u7684Python\u7248\u672c\u8db3\u591f\u4f7f\u7528\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5b83\u6765\u8fd0\u884cPython\u811a\u672c\uff0c\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\u8fdb\u5165Python\u4ea4\u4e92\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u9700\u8981\u7279\u5b9a\u7248\u672c\u7684Python\u6216\u4e0d\u60f3\u4f7f\u7528Homebrew\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5Python\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7dPython\u5b89\u88c5\u5305<\/strong>\uff1a\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9<a href=\"https:\/\/www.python.org\/downloads\/\">Python.org<\/a>\u5e76\u4e0b\u8f7d\u9002\u7528\u4e8eMacOS\u7684Python\u5b89\u88c5\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python<\/strong>\uff1a\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u6253\u5f00\u5b89\u88c5\u5305\u5e76\u6309\u7167\u6307\u793a\u8fdb\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0cPython\u548cpip\u5c06\u88ab\u6dfb\u52a0\u5230\u4f60\u7684\u7cfb\u7edf\u4e2d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong>\uff1a\u540c\u6837\uff0c\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u9a8c\u8bc1Python\u548cpip\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p>pip3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5728\u82f9\u679c\u7cfb\u7edf\u4e0a\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u6709\u65f6\u5019\u9700\u8981\u540c\u65f6\u4f7f\u7528\u591a\u4e2a\u7248\u672c\u7684Python\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>pyenv<\/code>\u6765\u7ba1\u7406\u591a\u4e2a\u7248\u672c\u7684Python\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5pyenv<\/strong>\uff1a\u4f7f\u7528Homebrew\u5b89\u88c5<code>pyenv<\/code>\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><strong>\u5b89\u88c5\u4e0d\u540c\u7248\u672c\u7684Python<\/strong>\uff1a\u4f7f\u7528<code>pyenv<\/code>\u5b89\u88c5\u6240\u9700\u7248\u672c\u7684Python\u3002\u4f8b\u5982\uff0c\u5b89\u88c5Python 3.8.0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv install 3.8.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bbe\u7f6ePython\u7248\u672c<\/strong>\uff1a\u8bbe\u7f6e\u5168\u5c40\u6216\u672c\u5730\u7684Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv global 3.8.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\u5728\u67d0\u4e2a\u9879\u76ee\u76ee\u5f55\u4e0b\u8bbe\u7f6e\u672c\u5730\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv local 3.8.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1Python\u7248\u672c<\/strong>\uff1a\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u5f53\u524d\u4f7f\u7528\u7684Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5728\u82f9\u679c\u7cfb\u7edf\u4e0a\u914d\u7f6ePython\u5f00\u53d1\u73af\u5883<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\uff0c\u53ef\u4ee5\u914d\u7f6e\u4e00\u4e2a\u5b8c\u6574\u7684Python\u5f00\u53d1\u73af\u5883\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9009\u62e9\u5408\u9002\u7684IDE<\/strong>\uff1a\u9009\u62e9\u4e00\u4e2a\u9002\u5408\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u662f\u5173\u952e\u3002\u5e38\u7528\u7684Python IDE\u6709PyCharm\u3001Visual Studio Code\u3001Atom\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python\u5305\u7ba1\u7406\u5de5\u5177<\/strong>\uff1a\u4f7f\u7528<code>pip<\/code>\u5b89\u88c5\u6240\u9700\u7684Python\u5305\u3002\u4f8b\u5982\uff0c\u5b89\u88c5<code>numpy<\/code>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip3 install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u865a\u62df\u73af\u5883<\/strong>\uff1a\u4f7f\u7528<code>venv<\/code>\u6a21\u5757\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u786e\u4fdd\u9879\u76ee\u7684\u4f9d\u8d56\u72ec\u7acb\u7ba1\u7406\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 -m venv myprojectenv<\/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 myprojectenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u540e\uff0c\u6240\u6709\u7684<code>pip<\/code>\u64cd\u4f5c\u90fd\u4f1a\u9488\u5bf9\u8fd9\u4e2a\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u7248\u672c\u63a7\u5236\u5de5\u5177<\/strong>\uff1a\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u4f7f\u7528Git\u7b49\u7248\u672c\u63a7\u5236\u5de5\u5177\u6765\u7ba1\u7406\u4ee3\u7801\u53d8\u66f4\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u5728\u82f9\u679c\u7cfb\u7edf\u4e0a\u5b89\u88c5\u5e76\u914d\u7f6ePython\u5f00\u53d1\u73af\u5883\uff0c\u4ece\u800c\u66f4\u9ad8\u6548\u5730\u8fdb\u884cPython\u7f16\u7a0b\u3002\u786e\u4fdd\u5b9a\u671f\u66f4\u65b0\u4f60\u7684\u5de5\u5177\u548c\u5e93\uff0c\u4ee5\u83b7\u5f97\u6700\u65b0\u7684\u7279\u6027\u548c\u5b89\u5168\u8865\u4e01\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u82f9\u679c\u7cfb\u7edf\u4e0a\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5728\u82f9\u679c\u7cfb\u7edf\u4e0a\u5b89\u88c5Python\u7684\u8fc7\u7a0b\u76f8\u5bf9\u7b80\u5355\u3002\u9996\u5148\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684\u5b89\u88c5\u5305\uff0c\u9009\u62e9\u9002\u5408macOS\u7684\u7248\u672c\u8fdb\u884c\u4e0b\u8f7d\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u6253\u5f00\u5b89\u88c5\u5305\u5e76\u6309\u7167\u63d0\u793a\u8fdb\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u8f93\u5165<code>python3 --version<\/code>\u6765\u786e\u8ba4Python\u662f\u5426\u5df2\u6210\u529f\u5b89\u88c5\u3002<\/p>\n<p><strong>\u5728macOS\u4e0a\u5b89\u88c5Python\u540e\u5982\u4f55\u7ba1\u7406\u4e0d\u540c\u7248\u672c\uff1f<\/strong><br \/>\u7ba1\u7406\u4e0d\u540c\u7248\u672c\u7684Python\u53ef\u4ee5\u4f7f\u7528\u7248\u672c\u7ba1\u7406\u5de5\u5177\uff0c\u5982pyenv\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7Homebrew\u5b89\u88c5pyenv\uff0c\u547d\u4ee4\u4e3a<code>brew install pyenv<\/code>\u3002\u5b89\u88c5\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>pyenv install &lt;version&gt;<\/code>\u547d\u4ee4\u6765\u5b89\u88c5\u6240\u9700\u7684Python\u7248\u672c\uff0c\u5e76\u4f7f\u7528<code>pyenv global &lt;version&gt;<\/code>\u8bbe\u7f6e\u9ed8\u8ba4\u7248\u672c\uff0c\u786e\u4fdd\u5728\u9879\u76ee\u4e2d\u4f7f\u7528\u7684Python\u7248\u672c\u4e00\u81f4\u3002<\/p>\n<p><strong>\u5b89\u88c5Python\u540e\uff0c\u5982\u4f55\u5b89\u88c5\u5e38\u7528\u7684\u7b2c\u4e09\u65b9\u5e93\uff1f<\/strong><br \/>\u5b89\u88c5Python\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528pip\u6765\u5b89\u88c5\u7b2c\u4e09\u65b9\u5e93\u3002pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u901a\u5e38\u4f1a\u968fPython\u4e00\u8d77\u5b89\u88c5\u3002\u901a\u8fc7\u6253\u5f00\u7ec8\u7aef\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>pip install &lt;package_name&gt;<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002\u4f8b\u5982\uff0c\u8981\u5b89\u88c5NumPy\u5e93\uff0c\u53ef\u4ee5\u8f93\u5165<code>pip install numpy<\/code>\u3002\u786e\u4fdd\u4f7f\u7528<code>pip3<\/code>\u547d\u4ee4\u6765\u5b89\u88c5\u4e0ePython 3\u517c\u5bb9\u7684\u5e93\uff0c\u907f\u514d\u4e0ePython 2\u7684\u5e93\u4ea7\u751f\u51b2\u7a81\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4e00\u3001\u5728\u82f9\u679c\u7cfb\u7edf\u4e0a\u5b89\u88c5Python\u7684\u6b65\u9aa4 \u5728\u82f9\u679c\u7cfb\u7edf\u4e0a\u5b89\u88c5Python\u975e\u5e38\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528MacOS\u81ea\u5e26\u7684Pyt [&hellip;]","protected":false},"author":3,"featured_media":995075,"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\/995070"}],"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=995070"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/995070\/revisions"}],"predecessor-version":[{"id":995077,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/995070\/revisions\/995077"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/995075"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=995070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=995070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=995070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}