{"id":985468,"date":"2024-12-27T07:36:56","date_gmt":"2024-12-26T23:36:56","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/985468.html"},"modified":"2024-12-27T07:36:58","modified_gmt":"2024-12-26T23:36:58","slug":"%e5%a6%82%e4%bd%95%e6%a3%80%e6%9f%a5python%e5%ae%89%e8%a3%85%e8%b7%af%e5%be%84","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/985468.html","title":{"rendered":"\u5982\u4f55\u68c0\u67e5python\u5b89\u88c5\u8def\u5f84"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24212621\/d3a20876-e69a-472b-9d23-1afdb2badf8e.webp\" alt=\"\u5982\u4f55\u68c0\u67e5python\u5b89\u88c5\u8def\u5f84\" \/><\/p>\n<p><p> <strong>\u68c0\u67e5Python\u5b89\u88c5\u8def\u5f84\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u547d\u4ee4\u3001\u901a\u8fc7Python\u811a\u672c\u67e5\u8be2\u3001\u5728\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u4e2d\u67e5\u770b\u3001\u901a\u8fc7\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u68c0\u67e5\u3002<\/strong> \u5176\u4e2d\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u547d\u4ee4\u662f\u4e00\u79cd\u7b80\u5355\u4e14\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>which python<\/code>\uff08\u5728Linux\u548cmacOS\u4e0a\uff09\u6216<code>where python<\/code>\uff08\u5728Windows\u4e0a\uff09\u6765\u67e5\u627ePython\u7684\u5b89\u88c5\u8def\u5f84\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u6bcf\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u547d\u4ee4<\/p>\n<\/p>\n<p><p>\u5728Windows\u3001macOS\u548cLinux\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u547d\u4ee4\u662f\u68c0\u67e5Python\u5b89\u88c5\u8def\u5f84\u7684\u5feb\u901f\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Windows\u64cd\u4f5c\u7cfb\u7edf<\/strong><\/p>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08\u53ef\u4ee5\u901a\u8fc7\u5728\u201c\u8fd0\u884c\u201d\u5bf9\u8bdd\u6846\u4e2d\u8f93\u5165<code>cmd<\/code>\u6253\u5f00\uff09\uff0c\u7136\u540e\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-cmd\">where python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8fd4\u56dePython\u53ef\u6267\u884c\u6587\u4ef6\u6240\u5728\u7684\u8def\u5f84\u3002\u5982\u679c\u5b89\u88c5\u4e86\u591a\u4e2aPython\u7248\u672c\uff0c\u53ef\u80fd\u4f1a\u8fd4\u56de\u591a\u4e2a\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>macOS\u548cLinux\u64cd\u4f5c\u7cfb\u7edf<\/strong><\/p>\n<\/p>\n<p><p>\u5728macOS\u6216Linux\u7cfb\u7edf\u4e2d\uff0c\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">which python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\uff0c\u5982\u679c\u4f7f\u7528Python3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">which python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e9b\u547d\u4ee4\u5c06\u8fd4\u56dePython\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u901a\u8fc7Python\u811a\u672c\u67e5\u8be2<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u5df2\u7ecf\u5728\u4f7f\u7528Python\uff0c\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\u6765\u83b7\u53d6Python\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528<code>sys<\/code>\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>Python\u7684<code>sys<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e2a<code>executable<\/code>\u5c5e\u6027\uff0c\u53ef\u4ee5\u7528\u4e8e\u83b7\u53d6Python\u89e3\u91ca\u5668\u7684\u8def\u5f84\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>print(sys.executable)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u8fd9\u4e2a\u811a\u672c\u5c06\u6253\u5370\u51faPython\u89e3\u91ca\u5668\u7684\u5b8c\u6574\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528<code>os<\/code>\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>\u53e6\u4e00\u4e2a\u9009\u9879\u662f\u4f7f\u7528<code>os<\/code>\u6a21\u5757\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u4ea4\u4e92\u7684\u529f\u80fd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>print(os.__file__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8fd4\u56de<code>os<\/code>\u6a21\u5757\u7684\u6587\u4ef6\u8def\u5f84\uff0c\u901a\u5e38\u4f4d\u4e8ePython\u7684\u5b89\u88c5\u76ee\u5f55\u4e2d\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u5728\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u4e2d\u67e5\u770b<\/p>\n<\/p>\n<p><p>\u8bb8\u591aIDE\u5982PyCharm\u3001VSCode\u7b49\u90fd\u5141\u8bb8\u7528\u6237\u67e5\u770b\u548c\u8bbe\u7f6ePython\u89e3\u91ca\u5668\u7684\u8def\u5f84\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>PyCharm<\/strong><\/p>\n<\/p>\n<p><p>\u5728PyCharm\u4e2d\uff0c\u6253\u5f00\u201cFile\u201d\u83dc\u5355\uff0c\u9009\u62e9\u201cSettings\u201d\uff08Windows\uff09\u6216\u201cPreferences\u201d\uff08macOS\uff09\uff0c\u7136\u540e\u5bfc\u822a\u5230\u201cProject: [project name]\u201d &gt; \u201cPython Interpreter\u201d\u3002\u5728\u8fd9\u4e2a\u7a97\u53e3\u4e2d\uff0c\u4f60\u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u9879\u76ee\u4f7f\u7528\u7684Python\u89e3\u91ca\u5668\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Visual Studio Code<\/strong><\/p>\n<\/p>\n<p><p>\u5728VSCode\u4e2d\uff0c\u6253\u5f00\u547d\u4ee4\u9762\u677f\uff08\u53ef\u4ee5\u901a\u8fc7\u6309<code>Ctrl + Shift + P<\/code>\u6216<code>Cmd + Shift + P<\/code>\uff09\uff0c\u8f93\u5165\u201cPython: Select Interpreter\u201d\uff0c\u7136\u540e\u9009\u62e9\u201cPython: Select Interpreter\u201d\u9009\u9879\u3002\u6b64\u65f6\uff0c\u4f60\u5c06\u770b\u5230\u5f53\u524d\u9009\u62e9\u7684Python\u89e3\u91ca\u5668\u53ca\u5176\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u901a\u8fc7\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u68c0\u67e5<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0cPython\u7684\u8def\u5f84\u53ef\u80fd\u5df2\u7ecf\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u67e5\u770b\u73af\u5883\u53d8\u91cf\u6765\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Windows\u64cd\u4f5c\u7cfb\u7edf<\/strong><\/p>\n<\/p>\n<p><p>\u5728Windows\u4e0a\uff0c\u53f3\u952e\u5355\u51fb\u201c\u8ba1\u7b97\u673a\u201d\u6216\u201c\u6211\u7684\u7535\u8111\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002\u5728\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u6309\u94ae\u3002\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u90e8\u5206\u4e2d\uff0c\u627e\u5230\u5e76\u9009\u62e9\u201cPath\u201d\u53d8\u91cf\uff0c\u7136\u540e\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u3002\u5728\u8fd9\u91cc\uff0c\u4f60\u53ef\u4ee5\u770b\u5230\u6240\u6709\u5305\u542bPython\u8def\u5f84\u7684\u6761\u76ee\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>macOS\u548cLinux\u64cd\u4f5c\u7cfb\u7edf<\/strong><\/p>\n<\/p>\n<p><p>\u5728macOS\u6216Linux\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u67e5\u770b<code>.bashrc<\/code>\u3001<code>.bash_profile<\/code>\u6216<code>.zshrc<\/code>\u6587\u4ef6\u6765\u68c0\u67e5\u662f\u5426\u6709\u4efb\u4f55Python\u8def\u5f84\u88ab\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u6253\u5f00\u7ec8\u7aef\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u6587\u4ef6\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cat ~\/.bashrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cat ~\/.bash_profile<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cat ~\/.zshrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e9b\u6587\u4ef6\u4e2d\uff0c\u67e5\u627e<code>export PATH<\/code>\u8bed\u53e5\uff0c\u770b\u770b\u662f\u5426\u5305\u542bPython\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\u3002\u65e0\u8bba\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\u5bf9\u4e8e\u89e3\u51b3\u914d\u7f6e\u95ee\u9898\u3001\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u4ee5\u53ca\u5b89\u88c5Python\u5305\u7b49\u4efb\u52a1\u90fd\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u5e0c\u671b\u8fd9\u4e9b\u65b9\u6cd5\u80fd\u591f\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7ba1\u7406\u548c\u4f7f\u7528Python\u73af\u5883\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Windows\u4e0a\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\uff1f<\/strong><br \/>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u51e0\u79cd\u65b9\u6cd5\u68c0\u67e5Python\u7684\u5b89\u88c5\u8def\u5f84\u3002\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08CMD\uff09\uff0c\u8f93\u5165\u547d\u4ee4<code>where python<\/code>\uff0c\u8fd9\u5c06\u663e\u793aPython\u7684\u53ef\u6267\u884c\u6587\u4ef6\u8def\u5f84\u3002\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fAnaconda\u6216\u5176\u4ed6Python\u5206\u53d1\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>where python<\/code>\u547d\u4ee4\u6765\u627e\u5230\u5bf9\u5e94\u7684\u8def\u5f84\u3002\u6b64\u5916\uff0c\u4e5f\u53ef\u4ee5\u5728Python\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>import sys; print(sys.executable)<\/code>\u6765\u83b7\u53d6Python\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/p>\n<p><strong>\u5728macOS\u4e2d\uff0c\u5982\u4f55\u786e\u8ba4Python\u7684\u5b89\u88c5\u4f4d\u7f6e\uff1f<\/strong><br \/>\u5728macOS\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u6765\u68c0\u67e5Python\u7684\u5b89\u88c5\u8def\u5f84\u3002\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165\u547d\u4ee4<code>which python3<\/code>\uff0c\u8fd9\u5c06\u8fd4\u56dePython 3\u7684\u5b89\u88c5\u8def\u5f84\u3002\u5982\u679c\u4f60\u7684\u7cfb\u7edf\u4e2d\u540c\u65f6\u5b89\u88c5\u4e86Python 2\u548cPython 3\uff0c\u53ef\u4ee5\u5206\u522b\u4f7f\u7528<code>which python<\/code>\u548c<code>which python3<\/code>\u6765\u786e\u8ba4\u5404\u81ea\u7684\u8def\u5f84\u3002\u6b64\u5916\uff0c\u4f7f\u7528Python\u547d\u4ee4\u884c\u4e2d\u7684<code>import sys; print(sys.executable)<\/code>\u540c\u6837\u6709\u6548\u3002<\/p>\n<p><strong>\u5982\u679c\u6211\u6709\u591a\u4e2aPython\u7248\u672c\uff0c\u5982\u4f55\u627e\u5230\u7279\u5b9a\u7248\u672c\u7684\u5b89\u88c5\u8def\u5f84\uff1f<\/strong><br \/>\u5f53\u4f60\u5728\u7cfb\u7edf\u4e2d\u5b89\u88c5\u4e86\u591a\u4e2a\u7248\u672c\u7684Python\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5177\u4f53\u7248\u672c\u7684\u547d\u4ee4\u6765\u67e5\u627e\u8def\u5f84\u3002\u4f8b\u5982\uff0c\u8f93\u5165<code>where python3.8<\/code>\uff08\u5728Windows\u4e0a\uff09\u6216<code>which python3.8<\/code>\uff08\u5728macOS\u548cLinux\u4e0a\uff09\u53ef\u4ee5\u5e2e\u52a9\u4f60\u627e\u5230\u7279\u5b9a\u7248\u672c\u7684\u5b89\u88c5\u4f4d\u7f6e\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>py -0<\/code>\u547d\u4ee4\uff08\u5728Windows\u4e0a\uff09\u53ef\u4ee5\u5217\u51fa\u6240\u6709\u5df2\u5b89\u88c5\u7684Python\u7248\u672c\u53ca\u5176\u8def\u5f84\uff0c\u4fbf\u4e8e\u4f60\u9009\u62e9\u548c\u4f7f\u7528\u7279\u5b9a\u7684\u7248\u672c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u68c0\u67e5Python\u5b89\u88c5\u8def\u5f84\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u547d\u4ee4\u3001\u901a\u8fc7Python\u811a\u672c\u67e5\u8be2\u3001\u5728\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u4e2d [&hellip;]","protected":false},"author":3,"featured_media":985476,"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\/985468"}],"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=985468"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985468\/revisions"}],"predecessor-version":[{"id":985481,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985468\/revisions\/985481"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/985476"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=985468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=985468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=985468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}