{"id":1128384,"date":"2025-01-08T20:19:59","date_gmt":"2025-01-08T12:19:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1128384.html"},"modified":"2025-01-08T20:20:01","modified_gmt":"2025-01-08T12:20:01","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e5%91%bd%e4%bb%a4%e8%a1%8c%e8%8e%b7%e5%8f%96python%e7%9a%84%e4%bd%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1128384.html","title":{"rendered":"\u5982\u4f55\u4f7f\u7528\u547d\u4ee4\u884c\u83b7\u53d6python\u7684\u4f4d\u7f6e"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25095125\/b3e6ebf5-d477-4a46-b268-ffc6de22359a.webp\" alt=\"\u5982\u4f55\u4f7f\u7528\u547d\u4ee4\u884c\u83b7\u53d6python\u7684\u4f4d\u7f6e\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u4f7f\u7528\u547d\u4ee4\u884c\u83b7\u53d6Python\u7684\u4f4d\u7f6e<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u83b7\u53d6Python\u7684\u4f4d\u7f6e\u975e\u5e38\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u884c\u5de5\u5177\uff1a<code>which<\/code>\u3001<code>where<\/code>\u3001<code>command -v<\/code>\u3001<code>type<\/code>\u3002<strong>\u5176\u4e2d\uff0c<code>which<\/code>\u547d\u4ee4\u662f\u6700\u5e38\u7528\u7684\u3001\u9002\u7528\u4e8e\u5927\u591a\u6570Unix\u7cfb\u7edf<\/strong>\u3002\u5b83\u53ef\u4ee5\u5feb\u901f\u627e\u5230Python\u7684\u5b89\u88c5\u4f4d\u7f6e\uff0c\u5e2e\u52a9\u4f60\u786e\u8ba4\u5f53\u524d\u4f7f\u7528\u7684Python\u89e3\u91ca\u5668\u7684\u4f4d\u7f6e\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u547d\u4ee4\u83b7\u53d6Python\u7684\u4f4d\u7f6e\uff0c\u5e76\u89e3\u91ca\u5176\u4e2d\u7684\u7ec6\u8282\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u4e00\u3001\u4f7f\u7528<code>which<\/code>\u547d\u4ee4<\/h2>\n<\/p>\n<p><p><code>which<\/code>\u547d\u4ee4\u662fUnix\u7cfb\u7edf\u4e2d\u975e\u5e38\u5e38\u7528\u7684\u5de5\u5177\uff0c\u5b83\u7528\u4e8e\u67e5\u627e\u5e76\u663e\u793a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u4f4d\u7f6e\u3002\u5bf9\u4e8ePython\uff0c\u4f60\u53ef\u4ee5\u7b80\u5355\u5730\u5728\u547d\u4ee4\u884c\u4e2d\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><h3>1.1 \u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u5047\u8bbe\u4f60\u7684\u7cfb\u7edf\u4e0a\u5b89\u88c5\u4e86Python 3.x\u7248\u672c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">which python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8fd4\u56dePython 3\u7684\u89e3\u91ca\u5668\u8def\u5f84\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">\/usr\/bin\/python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>1.2 \u89e3\u91ca<\/h3>\n<\/p>\n<p><p><code>which<\/code>\u547d\u4ee4\u4f1a\u5728\u7cfb\u7edf\u7684<code>$PATH<\/code>\u73af\u5883\u53d8\u91cf\u4e2d\u641c\u7d22\u6307\u5b9a\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u8fd4\u56de\u5b83\u7684\u8def\u5f84\u3002\u5bf9\u4e8ePython\uff0c\u5b83\u4f1a\u627e\u5230Python\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff0c\u786e\u4fdd\u4f60\u8fd0\u884c\u7684\u662f\u6b63\u786e\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528<code>where<\/code>\u547d\u4ee4\uff08\u9002\u7528\u4e8eWindows\uff09<\/h2>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e0a\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>where<\/code>\u547d\u4ee4\u6765\u67e5\u627ePython\u7684\u5b89\u88c5\u8def\u5f84\u3002<code>where<\/code>\u547d\u4ee4\u4e0e<code>which<\/code>\u547d\u4ee4\u7c7b\u4f3c\uff0c\u4f46\u5b83\u9002\u7528\u4e8eWindows\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h3>2.1 \u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\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\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-cmd\">C:\\Python39\\python.exe<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2.2 \u89e3\u91ca<\/h3>\n<\/p>\n<p><p><code>where<\/code>\u547d\u4ee4\u4f1a\u5728\u7cfb\u7edf\u7684<code>PATH<\/code>\u73af\u5883\u53d8\u91cf\u4e2d\u641c\u7d22\u6307\u5b9a\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u8fd4\u56de\u5b83\u7684\u8def\u5f84\u3002\u5bf9\u4e8ePython\uff0c\u5b83\u4f1a\u627e\u5230Python\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff0c\u786e\u4fdd\u4f60\u8fd0\u884c\u7684\u662f\u6b63\u786e\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528<code>command -v<\/code>\u547d\u4ee4<\/h2>\n<\/p>\n<p><p><code>command -v<\/code>\u547d\u4ee4\u662f\u53e6\u4e00\u4e2a\u5728Unix\u7cfb\u7edf\u4e2d\u67e5\u627e\u53ef\u6267\u884c\u6587\u4ef6\u4f4d\u7f6e\u7684\u5de5\u5177\u3002\u5b83\u7684\u5de5\u4f5c\u65b9\u5f0f\u4e0e<code>which<\/code>\u547d\u4ee4\u7c7b\u4f3c\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5b83\u53ef\u80fd\u4f1a\u63d0\u4f9b\u66f4\u591a\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>3.1 \u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">command -v python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8fd4\u56dePython\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">\/usr\/bin\/python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3.2 \u89e3\u91ca<\/h3>\n<\/p>\n<p><p><code>command -v<\/code>\u547d\u4ee4\u4f1a\u5728\u7cfb\u7edf\u7684<code>$PATH<\/code>\u73af\u5883\u53d8\u91cf\u4e2d\u641c\u7d22\u6307\u5b9a\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u8fd4\u56de\u5b83\u7684\u8def\u5f84\u3002\u5bf9\u4e8ePython\uff0c\u5b83\u4f1a\u627e\u5230Python\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff0c\u786e\u4fdd\u4f60\u8fd0\u884c\u7684\u662f\u6b63\u786e\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u4f7f\u7528<code>type<\/code>\u547d\u4ee4<\/h2>\n<\/p>\n<p><p><code>type<\/code>\u547d\u4ee4\u53ef\u4ee5\u7528\u4e8e\u786e\u5b9a\u547d\u4ee4\u662f\u5185\u7f6e\u7684\u3001\u522b\u540d\u3001\u51fd\u6570\u3001\u6216\u8005\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u4e14\u5b83\u4e5f\u53ef\u4ee5\u7528\u6765\u67e5\u627e\u53ef\u6267\u884c\u6587\u4ef6\u7684\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<p><h3>4.1 \u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">type python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8fd4\u56dePython\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python is \/usr\/bin\/python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4.2 \u89e3\u91ca<\/h3>\n<\/p>\n<p><p><code>type<\/code>\u547d\u4ee4\u4f1a\u68c0\u67e5\u547d\u4ee4\u5728\u7cfb\u7edf\u4e2d\u7684\u7c7b\u578b\uff0c\u5e76\u8fd4\u56de\u5b83\u7684\u4f4d\u7f6e\u3002\u5bf9\u4e8ePython\uff0c\u5b83\u4f1a\u627e\u5230Python\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff0c\u786e\u4fdd\u4f60\u8fd0\u884c\u7684\u662f\u6b63\u786e\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u4f7f\u7528<code>sys<\/code>\u6a21\u5757<\/h2>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u4f60\u8fd8\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u4f7f\u7528<code>sys<\/code>\u6a21\u5757\u6765\u83b7\u53d6Python\u89e3\u91ca\u5668\u7684\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<p><h3>5.1 \u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u5728Python\u811a\u672c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\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>\u8fd9\u5c06\u8f93\u51faPython\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">\/usr\/bin\/python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>5.2 \u89e3\u91ca<\/h3>\n<\/p>\n<p><p><code>sys.executable<\/code>\u5c5e\u6027\u8fd4\u56de\u6b63\u5728\u8fd0\u884c\u7684Python\u89e3\u91ca\u5668\u7684\u8def\u5f84\u3002\u8fd9\u5bf9\u4e8e\u786e\u8ba4Python\u89e3\u91ca\u5668\u7684\u4f4d\u7f6e\u975e\u5e38\u6709\u7528\uff0c\u5c24\u5176\u662f\u5728\u591a\u7248\u672c\u5171\u5b58\u7684\u73af\u5883\u4e2d\u3002<\/p>\n<\/p>\n<p><h2>\u516d\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u83b7\u53d6Python\u7684\u4f4d\u7f6e\u662f\u4e00\u4e2a\u975e\u5e38\u5e38\u89c1\u7684\u4efb\u52a1\uff0c\u5c24\u5176\u662f\u5728\u591a\u7248\u672c\u5171\u5b58\u6216\u9700\u8981\u786e\u4fdd\u4f7f\u7528\u6b63\u786e\u7684Python\u7248\u672c\u65f6\u3002\u4ee5\u4e0a\u4ecb\u7ecd\u4e86\u51e0\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u5305\u62ec<code>which<\/code>\u3001<code>where<\/code>\u3001<code>command -v<\/code>\u3001<code>type<\/code>\u547d\u4ee4\u4ee5\u53ca\u4f7f\u7528<code>sys<\/code>\u6a21\u5757\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u5de5\u5177\uff0c\u4f60\u53ef\u4ee5\u5feb\u901f\u627e\u5230Python\u7684\u5b89\u88c5\u4f4d\u7f6e\uff0c\u786e\u4fdd\u4f60\u7684\u5f00\u53d1\u73af\u5883\u914d\u7f6e\u6b63\u786e\u3002<strong>\u63a8\u8350\u4f7f\u7528<code>which<\/code>\u547d\u4ee4\uff0c\u5b83\u662f\u6700\u5e38\u7528\u4e14\u9002\u7528\u4e8e\u5927\u591a\u6570Unix\u7cfb\u7edf\u7684\u5de5\u5177<\/strong>\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5feb\u901f\u627e\u5230Python\u7684\u5b89\u88c5\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e2d\u67e5\u627ePython\u7684\u5b89\u88c5\u8def\u5f84\uff1f<\/strong><br \/>\u53ef\u4ee5\u901a\u8fc7\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\u8fd9\u4e9b\u547d\u4ee4\u4f1a\u8fd4\u56dePython\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\uff0c\u5e2e\u52a9\u4f60\u786e\u8ba4Python\u7684\u5b89\u88c5\u4f4d\u7f6e\u3002<\/p>\n<p><strong>\u5982\u679c\u6211\u7684\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5\u4e86\u591a\u4e2aPython\u7248\u672c\uff0c\u6211\u8be5\u5982\u4f55\u786e\u5b9a\u4f7f\u7528\u7684\u662f\u54ea\u4e2a\u7248\u672c\uff1f<\/strong><br \/>\u4f7f\u7528\u547d\u4ee4<code>python --version<\/code>\u6216\u8005<code>python3 --version<\/code>\u53ef\u4ee5\u5feb\u901f\u67e5\u770b\u5f53\u524d\u4f7f\u7528\u7684Python\u7248\u672c\u3002\u5982\u679c\u4f60\u5728\u7cfb\u7edf\u4e0a\u5b89\u88c5\u4e86\u591a\u4e2a\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>py -0<\/code>\u547d\u4ee4\u6765\u5217\u51fa\u6240\u6709\u5df2\u5b89\u88c5\u7684Python\u7248\u672c\uff0c\u5e76\u786e\u8ba4\u4f60\u5e0c\u671b\u4f7f\u7528\u7684\u7248\u672c\u3002<\/p>\n<p><strong>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u5982\u4f55\u901a\u8fc7\u547d\u4ee4\u884c\u8bbf\u95eePython\u7684\u5b89\u88c5\u6587\u4ef6\u5939\uff1f<\/strong><br \/>\u53ef\u4ee5\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230Python\u7684\u5b89\u88c5\u76ee\u5f55\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u9ed8\u8ba4\u8def\u5f84\u662f<code>C:\\PythonXX<\/code>\uff08XX\u8868\u793a\u7248\u672c\u53f7\uff09\u3002\u8f93\u5165<code>cd C:\\PythonXX<\/code>\u5e76\u56de\u8f66\uff0c\u5c31\u53ef\u4ee5\u8fdb\u5165Python\u7684\u5b89\u88c5\u6587\u4ef6\u5939\uff0c\u65b9\u4fbf\u8fdb\u884c\u5176\u4ed6\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Linux\u7cfb\u7edf\u4e2d\u67e5\u627ePython\u7684\u6240\u6709\u53ef\u6267\u884c\u6587\u4ef6\uff1f<\/strong><br \/>\u5728Linux\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>whereis python<\/code>\u547d\u4ee4\u6765\u67e5\u627e\u7cfb\u7edf\u4e2d\u6240\u6709\u4e0ePython\u76f8\u5173\u7684\u53ef\u6267\u884c\u6587\u4ef6\u53ca\u5176\u8def\u5f84\u3002\u8fd9\u5c06\u4e3a\u4f60\u63d0\u4f9b\u4e00\u4e2a\u5217\u8868\uff0c\u663e\u793a\u51fa\u4e0d\u540c\u7248\u672c\u548c\u5b89\u88c5\u8def\u5f84\u7684Python\u6587\u4ef6\uff0c\u4fbf\u4e8e\u7ba1\u7406\u548c\u4f7f\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u4f7f\u7528\u547d\u4ee4\u884c\u83b7\u53d6Python\u7684\u4f4d\u7f6e \u5728\u547d\u4ee4\u884c\u4e2d\u83b7\u53d6Python\u7684\u4f4d\u7f6e\u975e\u5e38\u7b80\u5355\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u884c\u5de5\u5177\uff1awh [&hellip;]","protected":false},"author":3,"featured_media":1128391,"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\/1128384"}],"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=1128384"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1128384\/revisions"}],"predecessor-version":[{"id":1128392,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1128384\/revisions\/1128392"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1128391"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1128384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1128384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1128384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}