{"id":1057787,"date":"2024-12-31T15:10:59","date_gmt":"2024-12-31T07:10:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1057787.html"},"modified":"2024-12-31T15:11:02","modified_gmt":"2024-12-31T07:11:02","slug":"%e4%bb%8ecmd%e5%a6%82%e4%bd%95%e6%9f%a5%e6%89%bepython%e7%9a%84%e5%ae%89%e8%a3%85%e8%b7%af%e5%be%84","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1057787.html","title":{"rendered":"\u4ececmd\u5982\u4f55\u67e5\u627epython\u7684\u5b89\u88c5\u8def\u5f84"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/ed2be925-b57d-4597-b719-a6be512483ea.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u4ececmd\u5982\u4f55\u67e5\u627epython\u7684\u5b89\u88c5\u8def\u5f84\" \/><\/p>\n<p><p> \u5728cmd\u5982\u4f55\u67e5\u627epython\u7684\u5b89\u88c5\u8def\u5f84<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u547d\u4ee4\u884c\u67e5\u627ePython\u7684\u5b89\u88c5\u8def\u5f84\u975e\u5e38\u7b80\u5355\uff0c\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528where\u547d\u4ee4\u3001\u4f7f\u7528python\u547d\u4ee4\u3001\u4f7f\u7528\u6ce8\u518c\u8868\u67e5\u8be2\u3002<\/strong> \u5176\u4e2d\uff0c<strong>\u4f7f\u7528where\u547d\u4ee4<\/strong>\u662f\u6700\u76f4\u63a5\u548c\u4fbf\u6377\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5feb\u901f\u627e\u5230Python\u7684\u53ef\u6267\u884c\u6587\u4ef6\u8def\u5f84\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u6bcf\u4e00\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528WHERE\u547d\u4ee4<\/p>\n<\/p>\n<p><p>WHERE\u547d\u4ee4\u662fWindows\u547d\u4ee4\u884c\u5de5\u5177\u63d0\u4f9b\u7684\u4e00\u79cd\u7528\u4e8e\u67e5\u627e\u53ef\u6267\u884c\u6587\u4ef6\u8def\u5f84\u7684\u547d\u4ee4\u3002\u5b83\u7684\u4f7f\u7528\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code>where python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6761\u547d\u4ee4\u4f1a\u8fd4\u56de\u7cfb\u7edf\u4e2d\u6240\u6709\u540d\u4e3apython\u7684\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\u3002\u5982\u679c\u7cfb\u7edf\u4e2d\u5b89\u88c5\u4e86\u591a\u4e2a\u7248\u672c\u7684Python\uff0c\u5b83\u4eec\u7684\u8def\u5f84\u4e5f\u4f1a\u5168\u90e8\u5217\u51fa\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528PYTHON\u547d\u4ee4<\/p>\n<\/p>\n<p><p>\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u76f4\u63a5\u4f7f\u7528python\u547d\u4ee4\u6765\u67e5\u8be2\u5b89\u88c5\u8def\u5f84\u3002\u4f60\u53ef\u4ee5\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code>python -c &quot;import sys; print(sys.executable)&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6761\u547d\u4ee4\u4f1a\u6267\u884c\u4e00\u6bb5Python\u4ee3\u7801\uff0c\u8f93\u51fa\u5f53\u524d\u8fd0\u884c\u7684Python\u89e3\u91ca\u5668\u7684\u8def\u5f84\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u662f\u5b83\u80fd\u7cbe\u786e\u5730\u544a\u8bc9\u4f60\u5f53\u524d\u9ed8\u8ba4Python\u89e3\u91ca\u5668\u7684\u4f4d\u7f6e\uff0c\u5e76\u4e14\u53ef\u4ee5\u7528\u4e8e\u8de8\u5e73\u53f0\u67e5\u8be2\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u6ce8\u518c\u8868\u67e5\u8be2<\/p>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0cPython\u7684\u5b89\u88c5\u4fe1\u606f\u901a\u5e38\u4f1a\u5199\u5165\u6ce8\u518c\u8868\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528reg\u547d\u4ee4\u6765\u67e5\u8be2\u6ce8\u518c\u8868\u4e2d\u7684\u76f8\u5173\u4fe1\u606f\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ol>\n<p><pre><code>reg query &quot;HKCU\\SOFTWARE\\Python\\PythonCore&quot; \/s<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u8be5\u547d\u4ee4\u4f1a\u5217\u51fa\u6240\u6709\u6ce8\u518c\u5728\u5f53\u524d\u7528\u6237\u4e2d\u7684Python\u7248\u672c\u53ca\u5176\u5b89\u88c5\u8def\u5f84\u3002<\/li>\n<\/ol>\n<p><p>\u5982\u679c\u4f60\u60f3\u67e5\u627e\u6240\u6709\u7528\u6237\u7684Python\u5b89\u88c5\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code>reg query &quot;HKLM\\SOFTWARE\\Python\\PythonCore&quot; \/s<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u67e5\u8be2\u6ce8\u518c\u8868\uff0c\u4f60\u53ef\u4ee5\u83b7\u5f97\u66f4\u591a\u5173\u4e8ePython\u5b89\u88c5\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u5b89\u88c5\u8def\u5f84\u3001\u7248\u672c\u53f7\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528Python\u811a\u672c\u67e5\u8be2<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u4f60\u8fd8\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\u6765\u67e5\u8be2Python\u7684\u5b89\u88c5\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>def find_python_path():<\/p>\n<p>    print(f&quot;Python executable path: {sys.executable}&quot;)<\/p>\n<p>if __name__ == &quot;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&quot;:<\/p>\n<p>    find_python_path()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5c06\u4e0a\u8ff0\u4ee3\u7801\u4fdd\u5b58\u4e3a\u4e00\u4e2aPython\u6587\u4ef6\uff08\u4f8b\u5982find_python_path.py\uff09\uff0c\u7136\u540e\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code>python find_python_path.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u811a\u672c\u4f1a\u8f93\u51fa\u5f53\u524dPython\u89e3\u91ca\u5668\u7684\u8def\u5f84\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u662f\u53ef\u4ee5\u7075\u6d3b\u6269\u5c55\uff0c\u67e5\u8be2\u66f4\u591a\u5173\u4e8ePython\u73af\u5883\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u67e5\u8be2<\/p>\n<\/p>\n<p><p>Python\u7684\u5b89\u88c5\u8def\u5f84\u901a\u5e38\u4f1a\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u67e5\u8be2\u73af\u5883\u53d8\u91cf\u6765\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ol>\n<p><pre><code>echo %PATH%<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u8be5\u547d\u4ee4\u4f1a\u8f93\u51fa\u7cfb\u7edf\u7684PATH\u73af\u5883\u53d8\u91cf\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u6240\u6709\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84\u3002\u4f60\u53ef\u4ee5\u5728\u8f93\u51fa\u4fe1\u606f\u4e2d\u67e5\u627ePython\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/li>\n<\/ol>\n<p><p>\u6b64\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u76f4\u63a5\u67e5\u8be2PYTHONPATH\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code>echo %PYTHONPATH%<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679cPYTHONPATH\u73af\u5883\u53d8\u91cf\u5df2\u8bbe\u7f6e\uff0c\u5b83\u4f1a\u5305\u542bPython\u5e93\u7684\u641c\u7d22\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5de5\u5177\u67e5\u8be2<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u4e0d\u719f\u6089\u547d\u4ee4\u884c\u64cd\u4f5c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u7b2c\u4e09\u65b9\u5de5\u5177\u6765\u67e5\u8be2Python\u7684\u5b89\u88c5\u8def\u5f84\u3002\u4f8b\u5982\uff0cAnaconda Navigator\u3001PyCharm\u7b49\u5de5\u5177\u90fd\u80fd\u5e2e\u52a9\u4f60\u8f7b\u677e\u7ba1\u7406\u548c\u67e5\u8be2Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u5de5\u5177\uff0c\u4f60\u4e0d\u4ec5\u53ef\u4ee5\u67e5\u770bPython\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u8fd8\u80fd\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u3001\u5b89\u88c5\u5305\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0c\u67e5\u627ePython\u5b89\u88c5\u8def\u5f84\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5305\u62ec\u4f7f\u7528WHERE\u547d\u4ee4\u3001PYTHON\u547d\u4ee4\u3001\u6ce8\u518c\u8868\u67e5\u8be2\u3001Python\u811a\u672c\u67e5\u8be2\u3001\u73af\u5883\u53d8\u91cf\u67e5\u8be2\u4ee5\u53ca\u7b2c\u4e09\u65b9\u5de5\u5177\u67e5\u8be2\u3002<strong>\u4f7f\u7528where\u547d\u4ee4<\/strong> \u662f\u6700\u76f4\u63a5\u548c\u4fbf\u6377\u7684\u65b9\u5f0f\uff0c\u4f46\u5176\u4ed6\u65b9\u6cd5\u4e5f\u5404\u6709\u4f18\u70b9\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\uff0c\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\u5728cmd\u4e2d\u68c0\u67e5Python\u662f\u5426\u5df2\u5b89\u88c5\uff1f<\/strong><br \/>\u8981\u68c0\u67e5Python\u662f\u5426\u5df2\u5b89\u88c5\uff0c\u53ef\u4ee5\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08cmd\uff09\uff0c\u7136\u540e\u8f93\u5165<code>python --version<\/code>\u6216<code>python -V<\/code>\u3002\u5982\u679cPython\u5df2\u5b89\u88c5\uff0c\u7cfb\u7edf\u5c06\u663e\u793a\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\u53f7\u3002\u5982\u679c\u672a\u5b89\u88c5\uff0c\u60a8\u5c06\u770b\u5230\u9519\u8bef\u6d88\u606f\uff0c\u63d0\u793a\u627e\u4e0d\u5230\u8be5\u547d\u4ee4\u3002<\/p>\n<p><strong>\u5982\u679ccmd\u65e0\u6cd5\u627e\u5230Python\uff0c\u5e94\u8be5\u5982\u4f55\u5904\u7406\uff1f<\/strong><br \/>\u5728cmd\u4e2d\u627e\u4e0d\u5230Python\u901a\u5e38\u610f\u5473\u7740Python\u672a\u5b89\u88c5\uff0c\u6216\u8005\u5176\u5b89\u88c5\u8def\u5f84\u672a\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u60a8\u53ef\u4ee5\u8bbf\u95eePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u3002\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\u4f46\u4ecd\u65e0\u6cd5\u8bbf\u95ee\uff0c\u8bf7\u624b\u52a8\u5c06Python\u7684\u5b89\u88c5\u76ee\u5f55\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u201c\u73af\u5883\u53d8\u91cf\u201d\u4e2d\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728cmd\u4e2d\u67e5\u627ePython\u7684\u5177\u4f53\u5b89\u88c5\u8def\u5f84\uff1f<\/strong><br \/>\u5728cmd\u4e2d\uff0c\u8f93\u5165<code>where python<\/code>\u547d\u4ee4\u53ef\u4ee5\u5e2e\u52a9\u60a8\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\u3002\u8fd9\u6761\u547d\u4ee4\u4f1a\u8fd4\u56dePython\u53ef\u6267\u884c\u6587\u4ef6\u7684\u786e\u5207\u4f4d\u7f6e\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u8fd9\u4e2a\u8def\u5f84\u67e5\u627ePython\u7684\u5176\u4ed6\u76f8\u5173\u6587\u4ef6\u548c\u5e93\u3002<\/p>\n<p><strong>\u5982\u679c\u6709\u591a\u4e2a\u7248\u672c\u7684Python\uff0c\u5982\u4f55\u786e\u5b9a\u4f7f\u7528\u7684\u662f\u54ea\u4e2a\u7248\u672c\uff1f<\/strong><br \/>\u5982\u679c\u7cfb\u7edf\u4e2d\u5b89\u88c5\u4e86\u591a\u4e2a\u7248\u672c\u7684Python\uff0c\u53ef\u4ee5\u5728cmd\u4e2d\u8f93\u5165<code>py -0<\/code>\u547d\u4ee4\u6765\u67e5\u770b\u6240\u6709\u5df2\u5b89\u88c5\u7684Python\u7248\u672c\u3002\u4f7f\u7528<code>py<\/code>\u547d\u4ee4\u53ef\u4ee5\u65b9\u4fbf\u5730\u9009\u62e9\u7279\u5b9a\u7248\u672c\u6765\u8fd0\u884cPython\u811a\u672c\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>py -2<\/code>\u6216<code>py -3<\/code>\u53ef\u4ee5\u6307\u5b9a\u4f7f\u7528Python 2.x\u62163.x\u7248\u672c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728cmd\u5982\u4f55\u67e5\u627epython\u7684\u5b89\u88c5\u8def\u5f84 \u4f7f\u7528\u547d\u4ee4\u884c\u67e5\u627ePython\u7684\u5b89\u88c5\u8def\u5f84\u975e\u5e38\u7b80\u5355\uff0c\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528whe [&hellip;]","protected":false},"author":3,"featured_media":1057795,"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\/1057787"}],"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=1057787"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1057787\/revisions"}],"predecessor-version":[{"id":1057799,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1057787\/revisions\/1057799"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1057795"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1057787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1057787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1057787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}