{"id":149970,"date":"2024-05-06T10:51:27","date_gmt":"2024-05-06T02:51:27","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/149970.html"},"modified":"2024-05-06T10:51:30","modified_gmt":"2024-05-06T02:51:30","slug":"cmd%e6%80%8e%e4%b9%88%e6%89%be%e5%88%b0python%e5%9c%a8%e7%9a%84%e8%b7%af%e5%be%84","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/149970.html","title":{"rendered":"cmd\u600e\u4e48\u627e\u5230python\u5728\u7684\u8def\u5f84"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27143504\/2a48712e-16ad-4654-bda3-d90b7d473058.webp\" alt=\"cmd\u600e\u4e48\u627e\u5230python\u5728\u7684\u8def\u5f84\" \/><\/p>\n<p><p>\u8981\u627e\u5230Python\u5728\u60a8\u7684\u8ba1\u7b97\u673a\u4e0a\u7684\u8def\u5f84\uff0c\u6709\u51e0\u4e2a\u5feb\u901f\u548c\u7b80\u5355\u7684\u65b9\u6cd5\uff0c<strong>\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u63d0\u793a\u7b26\uff08CMD\uff09\u3001\u73af\u5883\u53d8\u91cf\u3001\u4ee5\u53caPython\u81ea\u8eab\u7684\u7279\u6027\u6765\u5b9e\u73b0<\/strong>\u3002(<strong>\u6838\u5fc3\u89c2\u70b9<\/strong>) \u5176\u4e2d\uff0c<strong>\u901a\u8fc7\u547d\u4ee4\u63d0\u793a\u7b26\uff08CMD\uff09\u6765\u67e5\u627e<\/strong>\u662f\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u60a8\u53ea\u9700\u8981\u6253\u5f00CMD\uff0c\u7136\u540e\u8f93\u5165\u7279\u5b9a\u7684\u547d\u4ee4\uff0cPython\u7684\u5b89\u88c5\u8def\u5f84\u5c31\u4f1a\u663e\u793a\u5728\u60a8\u7684\u5c4f\u5e55\u4e0a\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u52bf\u662f\u76f4\u63a5\u4e14\u6548\u7387\u9ad8\uff0c\u65e0\u9700\u901a\u8fc7\u56fe\u5f62\u754c\u9762\uff0c\u5728\u7ec8\u7aef\u5373\u53ef\u5b8c\u6210\u8def\u5f84\u7684\u67e5\u627e\u3002<\/p>\n<\/p>\n<p><h2>\u901a\u8fc7\u547d\u4ee4\u63d0\u793a\u7b26\uff08CMD\uff09<\/h2>\n<\/p>\n<p><p>\u8981\u4f7f\u7528CMD\u627e\u5230Python\u7684\u8def\u5f84\uff0c\u60a8\u53ef\u4ee5\u8ddf\u968f\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h3>\u6253\u5f00CMD<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u5728Windows\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u641c\u7d22\u201cCMD\u201d\u6216\u201c\u547d\u4ee4\u63d0\u793a\u7b26\u201d\u6765\u627e\u5230\u5e76\u6253\u5f00\u5b83\u3002<\/p>\n<\/p>\n<p><h3>\u8f93\u5165\u547d\u4ee4<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\uff0c\u8f93\u5165\u4ee5\u4e0b\u4efb\u4e00\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><code>python -c &quot;import sys; print(sys.executable)&quot;<\/code> &#8211; \u8fd9\u6761\u547d\u4ee4\u5229\u7528Python\u81ea\u8eab\u7684\u5e93\u6765\u6253\u5370Python\u89e3\u91ca\u5668\u7684\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><code>where python<\/code> \u6216 <code>where.exe python<\/code> &#8211; \u8fd9\u6761\u547d\u4ee4\u5728Windows\u73af\u5883\u4e0b\u5de5\u4f5c\uff0c\u7528\u4e8e\u641c\u7d22\u73af\u5883\u53d8\u91cfPATH\u5217\u51fa\u7684\u76ee\u5f55\uff0c\u5e76\u663e\u793a\u5339\u914d\u201cpython\u201d\u7684\u6240\u6709\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u89e3\u8bfb\u8f93\u51fa<\/h3>\n<\/p>\n<p><p>\u6267\u884c\u4e0a\u8ff0\u547d\u4ee4\u540e\uff0c\u547d\u4ee4\u884c\u4f1a\u8f93\u51faPython\u89e3\u91ca\u5668\u7684\u5b8c\u6574\u8def\u5f84\u3002\u8fd9\u4e2a\u8def\u5f84\u5c31\u662fPython\u5b89\u88c5\u7684\u4f4d\u7f6e\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u8fd9\u4e2a\u8def\u5f84\u6765\u6267\u884cPython\u811a\u672c\u6216\u8fdb\u884c\u5176\u4ed6\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h2>\u73af\u5883\u53d8\u91cf\u4e2d\u67e5\u627e<\/h2>\n<\/p>\n<p><p>\u73af\u5883\u53d8\u91cf\u662f\u53e6\u4e00\u79cd\u627e\u5230Python\u8def\u5f84\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u67e5\u770bPATH\u73af\u5883\u53d8\u91cf\uff0c\u60a8\u53ef\u4ee5\u627e\u5230\u7cfb\u7edf\u7528\u6765\u67e5\u627e\u53ef\u6267\u884c\u6587\u4ef6\u7684\u76ee\u5f55\u5217\u8868\uff0cPython\u7684\u5b89\u88c5\u76ee\u5f55\u901a\u5e38\u4f1a\u88ab\u5305\u542b\u5176\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u8bbf\u95ee\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u5728Windows\u4e0a\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u201c\u63a7\u5236\u9762\u677f\u201d-&gt;\u201c\u7cfb\u7edf\u548c\u5b89\u5168\u201d-&gt;\u201c\u7cfb\u7edf\u201d-&gt;\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d-&gt;\u201c\u73af\u5883\u53d8\u91cf\u201d\u6765\u67e5\u770b\u548c\u7f16\u8f91\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><h3>\u67e5\u627ePython\u8def\u5f84<\/h3>\n<\/p>\n<p><p>\u5728\u201c\u73af\u5883\u53d8\u91cf\u201d\u5bf9\u8bdd\u6846\u4e2d\uff0c\u627e\u5230\u201cPath\u201d\u53d8\u91cf\uff0c\u7136\u540e\u5728\u5176\u503c\u4e2d\u5bfb\u627e\u542b\u6709\u201cPython\u201d\u7684\u6761\u76ee\u3002\u8fd9\u4e9b\u6761\u76ee\u901a\u5e38\u6307\u5411Python\u7684\u5b89\u88c5\u76ee\u5f55\u6216Script\u76ee\u5f55\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5b83\u4eec\u627e\u5230Python\u7684\u786e\u5207\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><h2>\u4f7f\u7528Python\u7684\u7279\u6027<\/h2>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u5efa\u7684\u51fd\u6570\u548c\u6a21\u5757\uff0c\u901a\u8fc7\u7f16\u5199\u7b80\u5355\u7684Python\u811a\u672c\u4e5f\u53ef\u4ee5\u627e\u5230\u5176\u5b89\u88c5\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><h3>\u7f16\u5199Python\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u811a\u672c\uff0c\u6bd4\u5982\u53eb\u505a<code>find_python_path.py<\/code>\uff0c\u5e76\u5728\u8be5\u811a\u672c\u4e2d\u5199\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>print(&quot;Python\u8def\u5f84\u662f:&quot;, sys.executable)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u6267\u884c\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u5728CMD\u4e2d\u5bfc\u822a\u5230\u8be5\u811a\u672c\u6240\u5728\u76ee\u5f55\uff0c\u5e76\u4f7f\u7528\u547d\u4ee4<code>python find_python_path.py<\/code>\u6765\u6267\u884c\u811a\u672c\uff0c\u811a\u672c\u4f1a\u6253\u5370\u51faPython\u89e3\u91ca\u5668\u7684\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><p>\u6240\u6709\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u63d0\u4f9b\u4e86\u4e00\u79cd\u5feb\u901f\u4fbf\u6377\u7684\u65b9\u5f0f\u6765\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u65e0\u8bba\u662f\u901a\u8fc7\u547d\u4ee4\u63d0\u793a\u7b26\u3001\u68c0\u67e5\u73af\u5883\u53d8\u91cf\u8fd8\u662f\u5229\u7528Python\u81ea\u8eab\u7684\u7279\u6027\u3002\u8fd9\u5bf9\u4e8e\u914d\u7f6e\u5f00\u53d1\u73af\u5883\u3001\u8fd0\u884cPython\u811a\u672c\u3001\u6216\u662f\u8fdb\u884c\u7cfb\u7edf\u7ba1\u7406\u6765\u8bf4\uff0c\u662f\u4e00\u4e2a\u6781\u4e3a\u5b9e\u7528\u7684\u6280\u5de7\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u5982\u4f55\u5728cmd\u4e2d\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\uff1f<\/strong><\/p>\n<p>\u5728cmd\u4e2d\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u6253\u5f00cmd\uff1a\u6309\u4e0bWin + R\u952e\uff0c\u5728\u5f39\u51fa\u7684\u8fd0\u884c\u6846\u4e2d\u8f93\u5165\u201ccmd\u201d\u5e76\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u3002<\/li>\n<li>\u8f93\u5165\u547d\u4ee4\uff1a\u8f93\u5165\u201cpython\u201d\u6216\u201cpython3\u201d\u547d\u4ee4\uff0c\u7136\u540e\u6309\u4e0b\u7a7a\u683c\u952e\u3002<\/li>\n<li>\u4f7f\u7528\u201cwhere\u201d\u547d\u4ee4\uff1a\u5728\u8f93\u5165\u7684\u547d\u4ee4\u540e\u9762\u6dfb\u52a0\u201cwhere\u201d\u547d\u4ee4\uff0c\u518d\u6b21\u6309\u4e0b\u7a7a\u683c\u952e\u3002<\/li>\n<li>\u6267\u884c\u547d\u4ee4\uff1a\u6309\u4e0b\u56de\u8f66\u952e\u4ee5\u6267\u884c\u547d\u4ee4\u3002<\/li>\n<li>\u83b7\u53d6\u8def\u5f84\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\u5c06\u663e\u793aPython\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/li>\n<\/ol>\n<p><strong>2. \u600e\u6837\u5229\u7528cmd\u67e5\u627ePython\u7684\u5b89\u88c5\u76ee\u5f55\uff1f<\/strong><\/p>\n<p>\u5728cmd\u4e2d\u67e5\u627ePython\u7684\u5b89\u88c5\u76ee\u5f55\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u6253\u5f00cmd\uff1a\u901a\u8fc7\u6309\u4e0bWin + R\u952e\u5e76\u5728\u8fd0\u884c\u6846\u4e2d\u952e\u5165\u201ccmd\u201d\u6765\u6253\u5f00cmd\u3002<\/li>\n<li>\u8f93\u5165\u547d\u4ee4\uff1a\u952e\u5165\u201cwhere python\u201d\u6216\u201cwhere python3\u201d\u547d\u4ee4\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u7b49\u5f85\u547d\u4ee4\u6267\u884c\uff1acmd\u5c06\u5f00\u59cb\u641c\u7d22Python\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u5e76\u5c06\u5176\u663e\u793a\u5728\u547d\u4ee4\u884c\u7a97\u53e3\u4e2d\u3002<\/li>\n<li>\u67e5\u627e\u8def\u5f84\uff1a\u67e5\u627e\u663e\u793a\u7684\u8def\u5f84\uff0c\u8fd9\u5c31\u662fPython\u7684\u5b89\u88c5\u76ee\u5f55\u3002<\/li>\n<\/ol>\n<p><strong>3. \u5982\u4f55\u5728cmd\u4e2d\u67e5\u627ePython\u7684\u8def\u5f84\uff1f<\/strong><\/p>\n<p>\u60f3\u8981\u5728cmd\u4e2d\u67e5\u627ePython\u7684\u8def\u5f84\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a<\/p>\n<ol>\n<li>\u6253\u5f00cmd\uff1a\u6309\u4e0bWin + R\u952e\uff0c\u5728\u8fd0\u884c\u6846\u4e2d\u8f93\u5165\u201ccmd\u201d\u5e76\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u6765\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3002<\/li>\n<li>\u8f93\u5165\u547d\u4ee4\uff1a\u952e\u5165\u201cwhere python\u201d\u6216\u201cwhere python3\u201d\u547d\u4ee4\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u7b49\u5f85\u7ed3\u679c\uff1acmd\u5c06\u4f1a\u5f00\u59cb\u641c\u7d22Python\u7684\u8def\u5f84\uff0c\u7a0d\u7b49\u7247\u523b\uff0c\u76f4\u5230\u547d\u4ee4\u6267\u884c\u5b8c\u6210\u3002<\/li>\n<li>\u67e5\u627e\u8def\u5f84\uff1a\u5728\u547d\u4ee4\u884c\u7a97\u53e3\u4e2d\u663e\u793a\u7684\u8def\u5f84\u5c31\u662fPython\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"\u8981\u627e\u5230Python\u5728\u60a8\u7684\u8ba1\u7b97\u673a\u4e0a\u7684\u8def\u5f84\uff0c\u6709\u51e0\u4e2a\u5feb\u901f\u548c\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u63d0\u793a\u7b26\uff08CMD\uff09\u3001\u73af\u5883\u53d8\u91cf\u3001\u4ee5\u53caP [&hellip;]","protected":false},"author":3,"featured_media":149975,"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\/149970"}],"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=149970"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/149970\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/149975"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=149970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=149970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=149970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}