{"id":1157258,"date":"2025-01-13T18:26:20","date_gmt":"2025-01-13T10:26:20","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1157258.html"},"modified":"2025-01-13T18:26:22","modified_gmt":"2025-01-13T10:26:22","slug":"%e5%a6%82%e4%bd%95%e7%a7%bb%e5%8a%a8python%e5%ae%89%e8%a3%85%e7%9b%ae%e5%bd%95","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1157258.html","title":{"rendered":"\u5982\u4f55\u79fb\u52a8python\u5b89\u88c5\u76ee\u5f55"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25195517\/1dd68824-410c-4f5f-b3ee-8a4bdfa80a2c.webp\" alt=\"\u5982\u4f55\u79fb\u52a8python\u5b89\u88c5\u76ee\u5f55\" \/><\/p>\n<p><p> \u8981\u79fb\u52a8Python\u7684\u5b89\u88c5\u76ee\u5f55\uff0c\u4f60\u9700\u8981\u8fdb\u884c\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<strong>\u627e\u5230Python\u7684\u5f53\u524d\u5b89\u88c5\u76ee\u5f55\u3001\u590d\u5236\u6216\u79fb\u52a8Python\u5b89\u88c5\u6587\u4ef6\u5230\u65b0\u4f4d\u7f6e\u3001\u66f4\u65b0\u73af\u5883\u53d8\u91cf\u3001\u4fee\u6539Python\u5feb\u6377\u65b9\u5f0f\u3001\u91cd\u65b0\u914d\u7f6eIDE\u6216\u7f16\u8f91\u5668<\/strong>\u3002\u6211\u4eec\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5176\u4e2d\u7684\u201c\u66f4\u65b0\u73af\u5883\u53d8\u91cf\u201d\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p><strong>\u66f4\u65b0\u73af\u5883\u53d8\u91cf<\/strong>\uff1a\u8fd9\u4e00\u6b65\u9aa4\u975e\u5e38\u5173\u952e\uff0c\u56e0\u4e3a\u5b83\u786e\u4fdd\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\u80fd\u591f\u627e\u5230Python\u89e3\u91ca\u5668\u3002\u5982\u679c\u4f60\u4e0d\u66f4\u65b0\u73af\u5883\u53d8\u91cf\uff0c\u7cfb\u7edf\u53ef\u80fd\u65e0\u6cd5\u8bc6\u522bPython\u547d\u4ee4\uff0c\u8fd9\u5c06\u5bfc\u81f4\u5404\u79cd\u95ee\u9898\u3002\u4f60\u9700\u8981\u8fdb\u5165\u7cfb\u7edf\u8bbe\u7f6e\uff0c\u627e\u5230\u73af\u5883\u53d8\u91cf\u7684\u914d\u7f6e\u7a97\u53e3\uff0c\u66f4\u65b0\u5176\u4e2d\u7684Python\u8def\u5f84\u4fe1\u606f\u3002\u786e\u4fdd\u65b0\u8def\u5f84\u6b63\u786e\u65e0\u8bef\uff0c\u5426\u5219\u5c06\u5bfc\u81f4Python\u65e0\u6cd5\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8be6\u7ec6\u8bf4\u660e\u5982\u4f55\u5b8c\u6210\u4e0a\u8ff0\u6bcf\u4e00\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u627e\u5230Python\u7684\u5f53\u524d\u5b89\u88c5\u76ee\u5f55<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u79fb\u52a8\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u77e5\u9053Python\u76ee\u524d\u7684\u5b89\u88c5\u4f4d\u7f6e\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u627e\u5230\u5b83\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5728Windows\u4e0a<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08Cmd\uff09\u3002<\/li>\n<li>\u8f93\u5165 <code>where python<\/code>\uff0c\u5e76\u56de\u8f66\u3002<\/li>\n<li>\u8fd9\u5c06\u663e\u793aPython\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5728macOS\u548cLinux\u4e0a<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u7ec8\u7aef\u3002<\/li>\n<li>\u8f93\u5165 <code>which python3<\/code> \u6216 <code>which python<\/code>\uff0c\u5e76\u56de\u8f66\u3002<\/li>\n<li>\u8fd9\u5c06\u663e\u793aPython\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u786e\u4fdd\u8bb0\u5f55\u4e0b\u8fd9\u4e2a\u8def\u5f84\uff0c\u56e0\u4e3a\u4f60\u7a0d\u540e\u4f1a\u9700\u8981\u5b83\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u590d\u5236\u6216\u79fb\u52a8Python\u5b89\u88c5\u6587\u4ef6\u5230\u65b0\u4f4d\u7f6e<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u590d\u5236\u6216\u79fb\u52a8\u6587\u4ef6<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728Windows\u4e0a\uff1a\u4f7f\u7528\u6587\u4ef6<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/58557.html\" target=\"_blank\">\u8d44\u6e90\u7ba1\u7406<\/a>\u5668\u5bfc\u822a\u5230\u5f53\u524dPython\u5b89\u88c5\u76ee\u5f55\uff0c\u9009\u62e9\u6240\u6709\u6587\u4ef6\u548c\u6587\u4ef6\u5939\uff0c\u7136\u540e\u590d\u5236\uff08Ctrl+C\uff09\u5e76\u7c98\u8d34\uff08Ctrl+V\uff09\u5230\u65b0\u4f4d\u7f6e\u3002<\/li>\n<li>\u5728macOS\u548cLinux\u4e0a\uff1a\u4f7f\u7528\u7ec8\u7aef\u547d\u4ee4 <code>cp -r \/\u65e7\u8def\u5f84 \/\u65b0\u8def\u5f84<\/code> \u8fdb\u884c\u590d\u5236\uff0c\u6216\u8005 <code>mv \/\u65e7\u8def\u5f84 \/\u65b0\u8def\u5f84<\/code> \u8fdb\u884c\u79fb\u52a8\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u6587\u4ef6\u5b8c\u6574\u6027<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u786e\u4fdd\u6240\u6709\u6587\u4ef6\u90fd\u5b8c\u6574\u5730\u590d\u5236\u6216\u79fb\u52a8\u5230\u4e86\u65b0\u76ee\u5f55\u3002<\/li>\n<li>\u68c0\u67e5\u65b0\u76ee\u5f55\u4e2d\u7684Python\u53ef\u6267\u884c\u6587\u4ef6\u662f\u5426\u80fd\u591f\u8fd0\u884c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u66f4\u65b0\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><p><strong>Windows<\/strong>\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u201c\u63a7\u5236\u9762\u677f\u201d\uff0c\u9009\u62e9\u201c\u7cfb\u7edf\u548c\u5b89\u5168\u201d\uff0c\u7136\u540e\u9009\u62e9\u201c\u7cfb\u7edf\u201d\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u94fe\u63a5\u3002<\/li>\n<li>\u5728\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u6309\u94ae\u3002<\/li>\n<li>\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u90e8\u5206\uff0c\u627e\u5230\u540d\u4e3a <code>Path<\/code> \u7684\u53d8\u91cf\uff0c\u5e76\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u3002<\/li>\n<li>\u5728\u201c\u7f16\u8f91\u73af\u5883\u53d8\u91cf\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u65b0\u5efa\u201d\uff0c\u7136\u540e\u8f93\u5165Python\u65b0\u76ee\u5f55\u7684\u8def\u5f84\u3002\u4f8b\u5982\uff1a<code>C:\\NewPath\\Python39<\/code>\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u66f4\u6539\u3002<\/li>\n<\/ol>\n<p><p><strong>macOS\u548cLinux<\/strong>\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u7ec8\u7aef\u3002<\/li>\n<li>\u7f16\u8f91\u4f60\u7684Shell\u914d\u7f6e\u6587\u4ef6\uff08\u4f8b\u5982 <code>.bashrc<\/code>\u3001<code>.bash_profile<\/code>\u3001<code>.zshrc<\/code> \u7b49\uff09\uff0c\u6dfb\u52a0\u6216\u66f4\u65b0\u4ee5\u4e0b\u884c\uff1a\n<pre><code class=\"language-sh\">export PATH=&quot;\/\u65b0\u8def\u5f84:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u4fdd\u5b58\u6587\u4ef6\u5e76\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6\uff1a\n<pre><code class=\"language-sh\">source ~\/.bashrc  # \u6216\u8005 source ~\/.zshrc\uff0c\u53d6\u51b3\u4e8e\u4f60\u4f7f\u7528\u7684Shell<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u4fee\u6539Python\u5feb\u6377\u65b9\u5f0f<\/h3>\n<\/p>\n<p><p>\u5728Windows\u4e0a\uff0c\u5982\u679c\u4f60\u6709\u4efb\u4f55\u6307\u5411\u65e7Python\u5b89\u88c5\u76ee\u5f55\u7684\u5feb\u6377\u65b9\u5f0f\uff0c\u9700\u8981\u66f4\u65b0\u8fd9\u4e9b\u5feb\u6377\u65b9\u5f0f\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u53f3\u952e\u70b9\u51fb\u5feb\u6377\u65b9\u5f0f\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002<\/li>\n<li>\u5728\u201c\u5feb\u6377\u65b9\u5f0f\u201d\u9009\u9879\u5361\u4e2d\uff0c\u66f4\u65b0\u201c\u76ee\u6807\u201d\u5b57\u6bb5\u4e2d\u7684\u8def\u5f84\uff0c\u6307\u5411\u65b0\u7684Python\u76ee\u5f55\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u66f4\u6539\u3002<\/li>\n<\/ol>\n<p><p>\u5728macOS\u548cLinux\u4e0a\uff0c\u5feb\u6377\u65b9\u5f0f\u901a\u5e38\u662f\u7b26\u53f7\u94fe\u63a5\uff08symlink\uff09\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>ln -sf \/\u65b0\u8def\u5f84\/python \/usr\/local\/bin\/python<\/code> \u547d\u4ee4\u66f4\u65b0\u7b26\u53f7\u94fe\u63a5\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u91cd\u65b0\u914d\u7f6eIDE\u6216\u7f16\u8f91\u5668<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u6216\u8005\u6587\u672c\u7f16\u8f91\u5668\uff0c\u4f60\u9700\u8981\u66f4\u65b0\u8fd9\u4e9b\u5de5\u5177\u7684Python\u89e3\u91ca\u5668\u8def\u5f84\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>PyCharm<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00PyCharm\uff0c\u9009\u62e9\u201cFile\u201d &gt; \u201cSettings\u201d\u3002<\/li>\n<li>\u5728\u201cProject Interpreter\u201d\u90e8\u5206\uff0c\u70b9\u51fb\u8bbe\u7f6e\u56fe\u6807\uff0c\u7136\u540e\u9009\u62e9\u201cAdd Local\u201d\u3002<\/li>\n<li>\u9009\u62e9\u65b0\u7684Python\u89e3\u91ca\u5668\u8def\u5f84\uff0c\u7136\u540e\u70b9\u51fb\u201cOK\u201d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>VS Code<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00VS Code\uff0c\u6309\u4e0b <code>Ctrl+Shift+P<\/code> \u6253\u5f00\u547d\u4ee4\u9762\u677f\u3002<\/li>\n<li>\u8f93\u5165\u5e76\u9009\u62e9 <code>Python: Select Interpreter<\/code>\u3002<\/li>\n<li>\u9009\u62e9\u65b0\u7684Python\u89e3\u91ca\u5668\u8def\u5f84\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5176\u4ed6\u7f16\u8f91\u5668<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6bcf\u4e2a\u7f16\u8f91\u5668\u7684\u914d\u7f6e\u65b9\u5f0f\u53ef\u80fd\u7565\u6709\u4e0d\u540c\uff0c\u8bf7\u53c2\u8003\u76f8\u5173\u6587\u6863\u8fdb\u884c\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u516d\u3001\u9a8c\u8bc1\u8fc1\u79fb\u7ed3\u679c<\/h3>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u786e\u4fdd\u4e00\u5207\u5de5\u4f5c\u6b63\u5e38\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u547d\u4ee4\u884c\u6216\u8005\u7ec8\u7aef\uff0c\u8f93\u5165 <code>python --version<\/code>\uff0c\u786e\u8ba4\u8f93\u51fa\u7684\u7248\u672c\u4fe1\u606f\u6b63\u786e\u3002<\/li>\n<li>\u5c1d\u8bd5\u8fd0\u884c\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\uff0c\u786e\u4fdd\u80fd\u591f\u6b63\u5e38\u6267\u884c\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u5e94\u8be5\u80fd\u591f\u987a\u5229\u5730\u5c06Python\u5b89\u88c5\u76ee\u5f55\u79fb\u52a8\u5230\u65b0\u7684\u4f4d\u7f6e\uff0c\u5e76\u786e\u4fdd\u4e00\u5207\u6b63\u5e38\u8fd0\u884c\u3002\u786e\u4fdd\u9010\u6b65\u4ed4\u7ec6\u64cd\u4f5c\uff0c\u907f\u514d\u9057\u6f0f\u5173\u952e\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u786e\u5b9a\u5f53\u524dPython\u7684\u5b89\u88c5\u76ee\u5f55\uff1f<\/strong><br \/>\u8981\u786e\u5b9a\u5f53\u524dPython\u7684\u5b89\u88c5\u76ee\u5f55\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\uff0c\u7136\u540e\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a  <\/p>\n<pre><code class=\"language-python\">import sys\nprint(sys.executable)\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u663e\u793aPython\u89e3\u91ca\u5668\u7684\u7edd\u5bf9\u8def\u5f84\uff0c\u901a\u5e38\u4e5f\u5c31\u662f\u5b89\u88c5\u76ee\u5f55\u7684\u4f4d\u7f6e\u3002<\/p>\n<p><strong>\u79fb\u52a8Python\u5b89\u88c5\u76ee\u5f55\u540e\u9700\u8981\u505a\u54ea\u4e9b\u8c03\u6574\uff1f<\/strong><br \/>\u79fb\u52a8Python\u5b89\u88c5\u76ee\u5f55\u540e\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u66f4\u65b0\u73af\u5883\u53d8\u91cf\uff0c\u7279\u522b\u662f<code>PATH<\/code>\u53d8\u91cf\uff0c\u4ee5\u786e\u4fdd\u7cfb\u7edf\u80fd\u591f\u627e\u5230\u65b0\u7684Python\u8def\u5f84\u3002\u5982\u679c\u4f7f\u7528\u4e86\u865a\u62df\u73af\u5883\uff0c\u60a8\u8fd8\u9700\u8981\u91cd\u65b0\u521b\u5efa\u8fd9\u4e9b\u865a\u62df\u73af\u5883\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0e\u539f\u59cb\u5b89\u88c5\u8def\u5f84\u76f8\u5173\u8054\u3002<\/p>\n<p><strong>\u5728\u79fb\u52a8Python\u5b89\u88c5\u76ee\u5f55\u65f6\u662f\u5426\u9700\u8981\u5907\u4efd\u6570\u636e\uff1f<\/strong><br \/>\u5728\u79fb\u52a8Python\u5b89\u88c5\u76ee\u5f55\u4e4b\u524d\uff0c\u5907\u4efd\u91cd\u8981\u7684\u6570\u636e\u548c\u9879\u76ee\u662f\u4e00\u4e2a\u597d\u4e3b\u610f\u3002\u8fd9\u53ef\u4ee5\u9632\u6b62\u610f\u5916\u4e22\u5931\u6587\u4ef6\u6216\u914d\u7f6e\uff0c\u7279\u522b\u662f\u5982\u679c\u60a8\u5728\u8be5\u76ee\u5f55\u4e2d\u5b89\u88c5\u4e86\u989d\u5916\u7684\u5e93\u6216\u6a21\u5757\uff0c\u786e\u4fdd\u5728\u79fb\u52a8\u540e\u5b83\u4eec\u4ecd\u7136\u53ef\u4ee5\u6b63\u5e38\u4f7f\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u79fb\u52a8Python\u7684\u5b89\u88c5\u76ee\u5f55\uff0c\u4f60\u9700\u8981\u8fdb\u884c\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a\u627e\u5230Python\u7684\u5f53\u524d\u5b89\u88c5\u76ee\u5f55\u3001\u590d\u5236\u6216\u79fb\u52a8Python\u5b89 [&hellip;]","protected":false},"author":3,"featured_media":1157264,"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\/1157258"}],"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=1157258"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1157258\/revisions"}],"predecessor-version":[{"id":1157266,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1157258\/revisions\/1157266"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1157264"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1157258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1157258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1157258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}