{"id":988979,"date":"2024-12-27T08:07:16","date_gmt":"2024-12-27T00:07:16","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/988979.html"},"modified":"2024-12-27T08:07:20","modified_gmt":"2024-12-27T00:07:20","slug":"%e5%a6%82%e4%bd%95%e6%89%be%e5%88%b0python-%e7%9a%84%e8%b7%af%e5%be%84","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/988979.html","title":{"rendered":"\u5982\u4f55\u627e\u5230python \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\/25064401\/99a0247d-7ef4-4a0e-b312-c5e21751fa99.webp\" alt=\"\u5982\u4f55\u627e\u5230python \u7684\u8def\u5f84\" \/><\/p>\n<p><p> <strong>\u627e\u5230Python\u8def\u5f84\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u3001Python\u5185\u7f6e\u6a21\u5757\u4ee5\u53ca\u73af\u5883\u53d8\u91cf\u7ba1\u7406\u5de5\u5177\u3002\u5177\u4f53\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u4e2d\u7684<code>which<\/code>\u6216<code>where<\/code>\u547d\u4ee4\u3001\u5728Python\u4e2d\u4f7f\u7528<code>sys<\/code>\u6a21\u5757\u3001\u4ee5\u53ca\u67e5\u770b\u73af\u5883\u53d8\u91cf\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u547d\u4ee4\u884c\u5de5\u5177\u67e5\u627ePython\u8def\u5f84\u662f\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u5bf9\u4e8eLinux\u548cMac\u7528\u6237\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>which python<\/code>\u6216<code>which python3<\/code>\u6765\u67e5\u770bPython\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u8fd9\u4f1a\u8fd4\u56dePython\u53ef\u6267\u884c\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55\u8def\u5f84\u3002\u5bf9\u4e8eWindows\u7528\u6237\uff0c\u4f7f\u7528<code>where python<\/code>\u547d\u4ee4\u53ef\u4ee5\u5f97\u5230\u7c7b\u4f3c\u7684\u7ed3\u679c\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u4e9b\u547d\u4ee4\u663e\u793a\u7684\u662fPython\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u800c\u4e0d\u4e00\u5b9a\u662fPython\u5b89\u88c5\u7684\u6839\u76ee\u5f55\u3002<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>sys<\/code>\u6a21\u5757\u6765\u67e5\u627ePython\u7684\u8def\u5f84\u3002\u9996\u5148\uff0c\u6253\u5f00Python\u89e3\u91ca\u5668\uff0c\u7136\u540e\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\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\u6253\u5370\u51faPython\u89e3\u91ca\u5668\u7684\u53ef\u6267\u884c\u6587\u4ef6\u8def\u5f84\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528<code>sys.path<\/code>\u67e5\u770bPython\u89e3\u91ca\u5668\u7684\u641c\u7d22\u8def\u5f84\u5217\u8868\uff0c\u8fd9\u5bf9\u4e8e\u8c03\u8bd5Python\u6a21\u5757\u5bfc\u5165\u95ee\u9898\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u901a\u8fc7\u547d\u4ee4\u884c\u5de5\u5177\u67e5\u627e\u8def\u5f84<\/h3>\n<\/p>\n<p><p>\u547d\u4ee4\u884c\u5de5\u5177\u662f\u67e5\u627ePython\u8def\u5f84\u7684\u4e00\u4e2a\u57fa\u672c\u65b9\u6cd5\uff0c\u65e0\u8bba\u662fLinux\u3001Mac\u8fd8\u662fWindows\u7cfb\u7edf\uff0c\u90fd\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u7684\u547d\u4ee4\u5feb\u901f\u83b7\u53d6\u3002<\/p>\n<\/p>\n<p><h4>1\u3001Linux\u548cMac\u7cfb\u7edf<\/h4>\n<\/p>\n<p><p>\u5728Linux\u548cMac\u7cfb\u7edf\u4e2d\uff0cPython\u901a\u5e38\u5df2\u7ecf\u9884\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528<code>which<\/code>\u547d\u4ee4\u6765\u67e5\u627ePython\u8def\u5f84\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u4f7f\u7528<code>which<\/code>\u547d\u4ee4\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u6253\u5f00\u7ec8\u7aef\uff0c\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<\/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\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84\u3002\u4f8b\u5982\uff0c\u53ef\u80fd\u4f1a\u8fd4\u56de<code>\/usr\/bin\/python<\/code>\u6216<code>\/usr\/local\/bin\/python<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u89e3\u91ca\uff1a<\/strong> <code>which<\/code>\u547d\u4ee4\u901a\u8fc7\u5728\u73af\u5883\u53d8\u91cf<code>PATH<\/code>\u4e2d\u67e5\u627e\uff0c\u663e\u793a\u6307\u5b9a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84\u3002\u8fd9\u5bf9\u4e8e\u786e\u8ba4\u7cfb\u7edf\u4e2d\u4f7f\u7528\u7684Python\u7248\u672c\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h4>2\u3001Windows\u7cfb\u7edf<\/h4>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>where<\/code>\u547d\u4ee4\u67e5\u627ePython\u7684\u8def\u5f84\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u4f7f\u7528<code>where<\/code>\u547d\u4ee4\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08cmd\uff09\uff0c\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\u7684\u8def\u5f84\u3002\u4f8b\u5982\uff0c\u53ef\u80fd\u4f1a\u8fd4\u56de<code>C:\\Python39\\python.exe<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u89e3\u91ca\uff1a<\/strong> <code>where<\/code>\u547d\u4ee4\u662fWindows\u4e2d\u7528\u4e8e\u67e5\u627e\u53ef\u6267\u884c\u6587\u4ef6\u8def\u5f84\u7684\u5de5\u5177\u3002\u5b83\u4f1a\u5728\u73af\u5883\u53d8\u91cf<code>PATH<\/code>\u4e2d\u67e5\u627e\u6307\u5b9a\u7a0b\u5e8f\uff0c\u5e76\u8fd4\u56de\u627e\u5230\u7684\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Python\u5185\u7f6e\u6a21\u5757\u67e5\u627e\u8def\u5f84<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u7f6e\u6a21\u5757\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728Python\u73af\u5883\u4e2d\u67e5\u627ePython\u7684\u8def\u5f84\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528<code>sys<\/code>\u6a21\u5757<\/h4>\n<\/p>\n<p><p><code>sys<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e9b\u6709\u7528\u7684\u5c5e\u6027\uff0c\u53ef\u4ee5\u5e2e\u52a9\u67e5\u627ePython\u8def\u5f84\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u83b7\u53d6\u53ef\u6267\u884c\u6587\u4ef6\u8def\u5f84\uff1a<\/strong><\/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\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\u3002\u4f8b\u5982\uff0c\u53ef\u80fd\u4f1a\u8f93\u51fa<code>\/usr\/bin\/python3.8<\/code>\u6216<code>C:\\Python39\\python.exe<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u83b7\u53d6\u6a21\u5757\u641c\u7d22\u8def\u5f84\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>print(sys.path)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u4e00\u4e2a\u5217\u8868\uff0c\u5305\u542bPython\u89e3\u91ca\u5668\u5728\u5bfc\u5165\u6a21\u5757\u65f6\u641c\u7d22\u7684\u76ee\u5f55\u8def\u5f84\u3002\u8fd9\u5bf9\u4e8e\u8c03\u8bd5\u6a21\u5757\u5bfc\u5165\u95ee\u9898\u7279\u522b\u6709\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h4>2\u3001\u4f7f\u7528<code>os<\/code>\u6a21\u5757<\/h4>\n<\/p>\n<p><p><code>os<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u4ea4\u4e92\u7684\u529f\u80fd\uff0c\u4e5f\u53ef\u4ee5\u7528\u6765\u67e5\u627ePython\u8def\u5f84\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u83b7\u53d6\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>print(os.getcwd())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u867d\u7136\u8fd9\u5e76\u4e0d\u662fPython\u5b89\u88c5\u8def\u5f84\uff0c\u4f46\u5728\u7ba1\u7406Python\u73af\u5883\u65f6\uff0c\u4e86\u89e3\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u7684\u4f4d\u7f6e\u662f\u6709\u7528\u7684\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u83b7\u53d6\u73af\u5883\u53d8\u91cf\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>print(os.environ[&#39;PATH&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u6253\u5370\u51fa\u7cfb\u7edf\u7684<code>PATH<\/code>\u73af\u5883\u53d8\u91cf\uff0c\u5176\u4e2d\u5305\u542b\u4e86Python\u7684\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u7ba1\u7406\u5de5\u5177\u67e5\u627e\u8def\u5f84<\/h3>\n<\/p>\n<p><p>\u73af\u5883\u53d8\u91cf\u7ba1\u7406\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u7ba1\u7406Python\u8def\u5f84\uff0c\u7279\u522b\u662f\u5728\u591a\u4e2aPython\u7248\u672c\u5171\u5b58\u7684\u60c5\u51b5\u4e0b\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528<code>pyenv<\/code>\u7ba1\u7406Python\u7248\u672c<\/h4>\n<\/p>\n<p><p><code>pyenv<\/code>\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python\u7248\u672c\u7ba1\u7406\u5de5\u5177\uff0c\u5141\u8bb8\u5728\u540c\u4e00\u7cfb\u7edf\u4e0a\u5b89\u88c5\u548c\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5b89\u88c5<code>pyenv<\/code>\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u5728Linux\u548cMac\u7cfb\u7edf\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5<code>pyenv<\/code>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">curl https:\/\/pyenv.run | bash<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5217\u51fa\u53ef\u7528Python\u7248\u672c\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv versions<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5217\u51fa\u901a\u8fc7<code>pyenv<\/code>\u5b89\u88c5\u7684\u6240\u6709Python\u7248\u672c\u53ca\u5176\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h4>2\u3001\u4f7f\u7528<code>conda<\/code>\u7ba1\u7406Python\u73af\u5883<\/h4>\n<\/p>\n<p><p><code>conda<\/code>\u662f\u53e6\u4e00\u4e2a\u6d41\u884c\u7684Python\u73af\u5883\u7ba1\u7406\u5de5\u5177\uff0c\u7279\u522b\u662f\u5728\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u9886\u57df\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5217\u51fa\u6240\u6709\u73af\u5883\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda env list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5217\u51fa\u6240\u6709\u901a\u8fc7<code>conda<\/code>\u521b\u5efa\u7684\u73af\u5883\u53ca\u5176\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u83b7\u53d6\u6fc0\u6d3b\u73af\u5883\u7684Python\u8def\u5f84\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u6fc0\u6d3b\u67d0\u4e2a\u73af\u5883\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770bPython\u8def\u5f84\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\u5728Windows\u4e0a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-cmd\">where python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><h3>\u56db\u3001\u67e5\u627ePython\u5e93\u7684\u5b89\u88c5\u8def\u5f84<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u67e5\u627e\u67d0\u4e2a\u7279\u5b9aPython\u5e93\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7<code>pip<\/code>\u548c<code>pkg_resources<\/code>\u6a21\u5757\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528<code>pip<\/code>\u67e5\u627e\u5e93\u8def\u5f84<\/h4>\n<\/p>\n<p><p><code>pip<\/code>\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u67e5\u627e\u5df2\u5b89\u88c5\u5e93\u7684\u8def\u5f84\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u67e5\u770b\u5e93\u5b89\u88c5\u8def\u5f84\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip show package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u663e\u793a\u6709\u5173\u8be5\u5e93\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u5176\u5b89\u88c5\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h4>2\u3001\u4f7f\u7528<code>pkg_resources<\/code>\u6a21\u5757<\/h4>\n<\/p>\n<p><p><code>pkg_resources<\/code>\u662f<code>setuptools<\/code>\u7684\u4e00\u90e8\u5206\uff0c\u63d0\u4f9b\u4e86\u6709\u5173\u5df2\u5b89\u88c5Python\u5305\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u83b7\u53d6\u5e93\u8def\u5f84\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pkg_resources<\/p>\n<p>package = pkg_resources.get_distribution(&#39;package_name&#39;)<\/p>\n<p>print(package.location)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u6307\u5b9a\u5e93\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h3>\u4e94\u3001\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u5728\u67e5\u627ePython\u8def\u5f84\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\uff0c\u8fd9\u91cc\u63d0\u4f9b\u4e00\u4e9b\u89e3\u51b3\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u591a\u4e2aPython\u7248\u672c\u5171\u5b58<\/h4>\n<\/p>\n<p><p>\u5728\u540c\u4e00\u7cfb\u7edf\u4e0a\u5b89\u88c5\u591a\u4e2aPython\u7248\u672c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8def\u5f84\u51b2\u7a81\u3002\u4f7f\u7528\u7248\u672c\u7ba1\u7406\u5de5\u5177\u5982<code>pyenv<\/code>\u6216<code>conda<\/code>\u53ef\u4ee5\u6709\u6548\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u8def\u5f84\u672a\u5728<code>PATH<\/code>\u4e2d<\/h4>\n<\/p>\n<p><p>\u5982\u679cPython\u8def\u5f84\u672a\u6dfb\u52a0\u5230<code>PATH<\/code>\u4e2d\uff0c\u5219\u547d\u4ee4\u884c\u5de5\u5177\u53ef\u80fd\u65e0\u6cd5\u627e\u5230Python\u3002\u53ef\u4ee5\u624b\u52a8\u5c06Python\u8def\u5f84\u6dfb\u52a0\u5230<code>PATH<\/code>\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u4ee5\u4fbf\u7cfb\u7edf\u53ef\u4ee5\u8bc6\u522b\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u865a\u62df\u73af\u5883\u8def\u5f84\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u865a\u62df\u73af\u5883\u65f6\uff0cPython\u8def\u5f84\u4f1a\u6307\u5411\u865a\u62df\u73af\u5883\u4e2d\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u786e\u4fdd\u5728\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\u8fdb\u884c\u8def\u5f84\u67e5\u627e\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u65e0\u8bba\u662f\u5728\u67e5\u627ePython\u53ef\u6267\u884c\u6587\u4ef6\u3001\u5e93\u8def\u5f84\u8fd8\u662f\u8c03\u8bd5\u73af\u5883\u95ee\u9898\u65f6\uff0c\u8fd9\u4e9b\u6280\u5de7\u90fd\u80fd\u63d0\u4f9b\u5e2e\u52a9\u3002\u4e86\u89e3\u8fd9\u4e9b\u65b9\u6cd5\u5c06\u6709\u52a9\u4e8e\u6709\u6548\u7ba1\u7406Python\u5f00\u53d1\u73af\u5883\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u786e\u8ba4\u6211\u5b89\u88c5\u7684Python\u7248\u672c\u53ca\u5176\u8def\u5f84\uff1f<\/strong><br \/>\u8981\u786e\u8ba4\u4f60\u5b89\u88c5\u7684Python\u7248\u672c\u53ca\u5176\u8def\u5f84\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u6765\u67e5\u770b\u7248\u672c\u4fe1\u606f\u3002\u540c\u65f6\uff0c\u4f7f\u7528<code>which python<\/code>\uff08\u5728Linux\u6216macOS\u4e0a\uff09\u6216<code>where python<\/code>\uff08\u5728Windows\u4e0a\uff09\u53ef\u4ee5\u663e\u793aPython\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/p>\n<p><strong>\u5728Windows\u548cmacOS\u4e0a\u5982\u4f55\u67e5\u627ePython\u7684\u5b89\u88c5\u4f4d\u7f6e\uff1f<\/strong><br \/>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8f93\u5165<code>where python<\/code>\u6765\u627e\u5230Python\u7684\u5b89\u88c5\u4f4d\u7f6e\u3002\u5728macOS\u4e0a\uff0c\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165<code>which python3<\/code>\uff0c\u5373\u53ef\u83b7\u53d6Python\u7684\u8def\u5f84\u3002\u8fd9\u4e9b\u547d\u4ee4\u4f1a\u544a\u8bc9\u4f60\u5f53\u524d\u4f7f\u7528\u7684Python\u89e3\u91ca\u5668\u7684\u5177\u4f53\u4f4d\u7f6e\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\u6211\u627e\u4e0d\u5230Python\u7684\u8def\u5f84\uff1f<\/strong><br \/>\u5982\u679c\u5728\u547d\u4ee4\u884c\u4e2d\u627e\u4e0d\u5230Python\u7684\u8def\u5f84\uff0c\u53ef\u80fd\u662f\u56e0\u4e3aPython\u6ca1\u6709\u6b63\u786e\u5b89\u88c5\uff0c\u6216\u8005\u5176\u5b89\u88c5\u8def\u5f84\u6ca1\u6709\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u91cd\u65b0\u5b89\u88c5Python\uff0c\u5e76\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u786e\u4fdd\u9009\u62e9\u4e86\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u8c03\u7528Python\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4ee3\u7801\u4e2d\u83b7\u53d6\u5f53\u524d\u7684Python\u8def\u5f84\uff1f<\/strong><br \/>\u5728Python\u4ee3\u7801\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>import sys<\/code>\u548c<code>print(sys.executable)<\/code>\u6765\u83b7\u53d6\u5f53\u524d\u8fd0\u884c\u7684Python\u89e3\u91ca\u5668\u7684\u8def\u5f84\u3002\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u6709\u6548\uff0c\u5c24\u5176\u662f\u5728\u9700\u8981\u786e\u8ba4\u4ee3\u7801\u8fd0\u884c\u73af\u5883\u65f6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u627e\u5230Python\u8def\u5f84\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u3001Python\u5185\u7f6e\u6a21\u5757\u4ee5\u53ca\u73af\u5883\u53d8\u91cf\u7ba1\u7406\u5de5\u5177\u3002\u5177\u4f53\u65b9\u6cd5\u5305\u62ec\uff1a [&hellip;]","protected":false},"author":3,"featured_media":988998,"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\/988979"}],"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=988979"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/988979\/revisions"}],"predecessor-version":[{"id":989001,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/988979\/revisions\/989001"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/988998"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=988979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=988979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=988979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}