{"id":999012,"date":"2024-12-27T09:37:50","date_gmt":"2024-12-27T01:37:50","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/999012.html"},"modified":"2024-12-27T09:37:53","modified_gmt":"2024-12-27T01:37:53","slug":"%e5%a6%82%e4%bd%95%e6%89%8b%e5%8a%a8%e6%b7%bb%e5%8a%a0python%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/999012.html","title":{"rendered":"\u5982\u4f55\u624b\u52a8\u6dfb\u52a0python\u73af\u5883"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25074218\/5c6bdcd0-39ea-436f-89bc-435c203703bd.webp\" alt=\"\u5982\u4f55\u624b\u52a8\u6dfb\u52a0python\u73af\u5883\" \/><\/p>\n<p><p> <strong>\u8981\u624b\u52a8\u6dfb\u52a0Python\u73af\u5883\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u4e0b\u8f7d\u5b89\u88c5Python\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u5b89\u88c5\u6240\u9700\u7684\u5305\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/strong>\u5176\u4e2d\uff0c\u521b\u5efa\u865a\u62df\u73af\u5883\u5c24\u4e3a\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u80fd\u591f\u8ba9\u4f60\u5728\u4e0d\u540c\u9879\u76ee\u4e2d\u4f7f\u7528\u4e0d\u540c\u7684Python\u7248\u672c\u548c\u5e93\u7248\u672c\uff0c\u4ece\u800c\u907f\u514d\u6f5c\u5728\u7684\u517c\u5bb9\u6027\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4e0b\u8f7d\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>\u8981\u624b\u52a8\u6dfb\u52a0Python\u73af\u5883\uff0c\u9996\u5148\u9700\u8981\u5728\u4f60\u7684\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5Python\u3002\u8bbf\u95eePython\u7684\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%E5%90%88%E4%BD%A0%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%9A%84Python%E7%89%88%E6%9C%AC%E3%80%82%E9%80%9A%E5%B8%B8%E5%BB%BA%E8%AE%AE%E4%B8%8B%E8%BD%BD%E6%9C%80%E6%96%B0%E7%9A%84%E7%A8%B3%E5%AE%9A%E7%89%88%E6%9C%AC%EF%BC%8C%E4%BB%A5%E8%8E%B7%E5%BE%97%E6%9C%80%E6%96%B0%E7%9A%84%E5%8A%9F%E8%83%BD%E5%92%8C%E5%AE%89%E5%85%A8%E6%9B%B4%E6%96%B0%E3%80%82%E5%9C%A8%E5%AE%89%E8%A3%85%E8%BF%87%E7%A8%8B%E4%B8%AD%EF%BC%8C%E5%8A%A1%E5%BF%85%E5%8B%BE%E9%80%89%E2%80%9CAdd\">https:\/\/www.python.org\/\uff09\uff0c\u4e0b\u8f7d\u9002\u5408\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684Python\u7248\u672c\u3002\u901a\u5e38\u5efa\u8bae\u4e0b\u8f7d\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u672c\uff0c\u4ee5\u83b7\u5f97\u6700\u65b0\u7684\u529f\u80fd\u548c\u5b89\u5168\u66f4\u65b0\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u52a1\u5fc5\u52fe\u9009\u201cAdd<\/a> Python to PATH\u201d\u9009\u9879\uff0c\u8fd9\u5c06\u81ea\u52a8\u4e3a\u4f60\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u6253\u5f00\u547d\u4ee4\u884c\uff08Windows\u7cfb\u7edf\u7684CMD\u6216PowerShell\uff0cmacOS\u7684\u7ec8\u7aef\uff09\u5e76\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u6765\u786e\u8ba4\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002\u5982\u679c\u8f93\u51faPython\u7684\u7248\u672c\u53f7\uff0c\u5219\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n<\/p>\n<p><p>\u73af\u5883\u53d8\u91cf\u662f\u64cd\u4f5c\u7cfb\u7edf\u7528\u4e8e\u4f20\u9012\u914d\u7f6e\u4fe1\u606f\u7684\u5168\u5c40\u53d8\u91cf\u3002\u4e3a\u4e86\u786e\u4fdd\u5728\u547d\u4ee4\u884c\u4e2d\u53ef\u4ee5\u65b9\u4fbf\u5730\u8bbf\u95eePython\uff0c\u4f60\u9700\u8981\u624b\u52a8\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u8ba1\u7b97\u673a\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002\u5728\u5f39\u51fa\u7684\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u6309\u94ae\u3002\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u4e2d\u627e\u5230\u201cPath\u201d\u53d8\u91cf\uff0c\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u6309\u94ae\u3002\u5c06Python\u7684\u5b89\u88c5\u8def\u5f84\uff08\u4f8b\u5982\uff0c<code>C:\\Python39<\/code>\uff09\u6dfb\u52a0\u5230\u5217\u8868\u4e2d\u5e76\u4fdd\u5b58\u3002<\/p>\n<\/p>\n<p><p>\u5728macOS\u6216Linux\u7cfb\u7edf\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u7f16\u8f91<code>.bashrc<\/code>\u6216<code>.bash_profile<\/code>\u6587\u4ef6\uff0c\u6dfb\u52a0\u4e00\u884c\u5982<code>export PATH=&quot;\/usr\/local\/bin\/python:$PATH&quot;<\/code>\uff0c\u7136\u540e\u6267\u884c<code>source .bashrc<\/code>\u6216<code>source .bash_profile<\/code>\u4ee5\u5e94\u7528\u66f4\u6539\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u5b89\u88c5\u6240\u9700\u7684\u5305<\/p>\n<\/p>\n<p><p>Python\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u5176\u4e30\u5bcc\u7684\u5e93\u548c\u5305\u3002\u5b89\u88c5Python\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177<code>pip<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684\u5305\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u9700\u8981\u5b89\u88c5NumPy\u5e93\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>pip install numpy<\/code>\u3002\u5efa\u8bae\u5728\u5b89\u88c5\u5305\u65f6\uff0c\u5c3d\u91cf\u4f7f\u7528\u865a\u62df\u73af\u5883\uff0c\u4ee5\u907f\u514d\u5f71\u54cd\u5168\u5c40\u7684Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u521b\u5efa\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p>\u5728Python\u9879\u76ee\u4e2d\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u6709\u6548\u5730\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\u3002Python\u63d0\u4f9b\u4e86<code>venv<\/code>\u6a21\u5757\uff0c\u7528\u4e8e\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5bfc\u822a\u5230\u4f60\u7684\u9879\u76ee\u76ee\u5f55\u3002\u7136\u540e\uff0c\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python -m venv myenv<\/code>\u6765\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>myenv<\/code>\u7684\u865a\u62df\u73af\u5883\u3002\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u4f60\u9700\u8981\u6fc0\u6d3b\u8be5\u865a\u62df\u73af\u5883\u3002\u5728Windows\u4e0a\uff0c\u8f93\u5165<code>myenv\\Scripts\\activate<\/code>\uff1b\u5728macOS\u6216Linux\u4e0a\uff0c\u8f93\u5165<code>source myenv\/bin\/activate<\/code>\u3002\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u547d\u4ee4\u884c\u63d0\u793a\u7b26\u524d\u4f1a\u663e\u793a\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\uff0c\u8868\u793a\u4f60\u5df2\u8fdb\u5165\u8be5\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u7684\u4efb\u4f55\u5305\u90fd\u662f\u72ec\u7acb\u4e8e\u7cfb\u7edf\u7684Python\u73af\u5883\u7684\u3002\u5f53\u4f60\u5b8c\u6210\u5f00\u53d1\u5de5\u4f5c\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165<code>deactivate<\/code>\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u7ba1\u7406\u548c\u5207\u6362Python\u7248\u672c<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5728\u4e0d\u540c\u7684\u9879\u76ee\u4e2d\u4f7f\u7528\u4e0d\u540c\u7684Python\u7248\u672c\u3002\u4f7f\u7528\u5de5\u5177\u5982<code>pyenv<\/code>\u53ef\u4ee5\u65b9\u4fbf\u5730\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u3002<\/p>\n<\/p>\n<p><p>\u5b89\u88c5<code>pyenv<\/code>\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7<code>pyenv install 3.x.x<\/code>\u547d\u4ee4\u5b89\u88c5\u6307\u5b9a\u7248\u672c\u7684Python\u3002\u4f7f\u7528<code>pyenv global 3.x.x<\/code>\u53ef\u4ee5\u8bbe\u7f6e\u5168\u5c40\u7684Python\u7248\u672c\uff0c\u800c\u4f7f\u7528<code>pyenv local 3.x.x<\/code>\u53ef\u4ee5\u4e3a\u5f53\u524d\u76ee\u5f55\u8bbe\u7f6e\u5c40\u90e8\u7684Python\u7248\u672c\u3002\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u8f7b\u677e\u5207\u6362\u4e0d\u540c\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u624b\u52a8\u6dfb\u52a0Python\u73af\u5883\u9700\u8981\u51e0\u6b65\u5173\u952e\u64cd\u4f5c\uff1a\u4e0b\u8f7d\u5b89\u88c5Python\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u5b89\u88c5\u6240\u9700\u7684\u5305\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u4ee5\u53ca\u7ba1\u7406\u548c\u5207\u6362Python\u7248\u672c\u3002\u8fd9\u4e9b\u6b65\u9aa4\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728\u5f00\u53d1\u4e2d\u66f4\u597d\u5730\u7ba1\u7406Python\u73af\u5883\uff0c\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002\u540c\u65f6\uff0c\u5229\u7528\u865a\u62df\u73af\u5883\u548c\u7248\u672c\u7ba1\u7406\u5de5\u5177\u80fd\u591f\u6709\u6548\u907f\u514d\u7248\u672c\u51b2\u7a81\u548c\u4f9d\u8d56\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u624b\u52a8\u6dfb\u52a0Python\u73af\u5883\uff1f<\/strong><br \/>\u5728Windows\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u8f7dPython\u5b89\u88c5\u5305\u5e76\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f\u6765\u6dfb\u52a0Python\u73af\u5883\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u8c03\u7528Python\u3002\u5728macOS\u548cLinux\u7cfb\u7edf\u4e2d\uff0c\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5de5\u5177\uff08\u5982Homebrew\u6216apt-get\uff09\u6765\u5b89\u88c5Python\uff0c\u5e76\u4e14\u8fd9\u4e9b\u5de5\u5177\u4f1a\u81ea\u52a8\u5c06Python\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/p>\n<p><strong>\u5982\u679c\u6211\u5df2\u7ecf\u5b89\u88c5\u4e86Python\uff0c\u5982\u4f55\u786e\u4fdd\u5b83\u7684\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u6b63\u786e\uff1f<\/strong><br \/>\u53ef\u4ee5\u901a\u8fc7\u5728\u547d\u4ee4\u884c\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u6765\u68c0\u67e5Python\u662f\u5426\u5df2\u6b63\u786e\u5b89\u88c5\u5e76\u914d\u7f6e\u3002\u5982\u679c\u547d\u4ee4\u8fd4\u56dePython\u7684\u7248\u672c\u53f7\uff0c\u8bf4\u660e\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u6b63\u786e\u3002\u5982\u679c\u51fa\u73b0\u201c\u672a\u627e\u5230\u547d\u4ee4\u201d\u6216\u7c7b\u4f3c\u4fe1\u606f\uff0c\u53ef\u80fd\u9700\u8981\u624b\u52a8\u5c06Python\u7684\u5b89\u88c5\u8def\u5f84\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/p>\n<p><strong>\u5728\u624b\u52a8\u6dfb\u52a0Python\u73af\u5883\u540e\uff0c\u5982\u4f55\u5b89\u88c5\u548c\u7ba1\u7406Python\u5e93\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u5de5\u5177\u6765\u5b89\u88c5\u548c\u7ba1\u7406Python\u5e93\u3002\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165<code>pip install package_name<\/code>\u6765\u5b89\u88c5\u7279\u5b9a\u7684\u5e93\uff0c\u786e\u4fdd\u5728\u5b89\u88c5\u4e4b\u524d\uff0cPython\u548cpip\u5df2\u7ecf\u6b63\u786e\u914d\u7f6e\u3002\u4f7f\u7528<code>pip list<\/code>\u53ef\u4ee5\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5e93\uff0c<code>pip uninstall package_name<\/code>\u53ef\u4ee5\u5378\u8f7d\u4e0d\u9700\u8981\u7684\u5e93\uff0c\u5e2e\u52a9\u60a8\u4fdd\u6301\u73af\u5883\u7684\u6574\u6d01\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u624b\u52a8\u6dfb\u52a0Python\u73af\u5883\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u4e0b\u8f7d\u5b89\u88c5Python\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u5b89\u88c5\u6240\u9700\u7684\u5305\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3002 [&hellip;]","protected":false},"author":3,"featured_media":999021,"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\/999012"}],"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=999012"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/999012\/revisions"}],"predecessor-version":[{"id":999024,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/999012\/revisions\/999024"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/999021"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=999012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=999012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=999012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}