{"id":964786,"date":"2024-12-27T04:31:46","date_gmt":"2024-12-26T20:31:46","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/964786.html"},"modified":"2024-12-27T04:31:48","modified_gmt":"2024-12-26T20:31:48","slug":"%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8bpython%e7%8e%af%e5%a2%83%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/964786.html","title":{"rendered":"\u5982\u4f55\u67e5\u770bpython\u73af\u5883\u8bbe\u7f6e"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24181419\/128a9e1b-0dd5-4e88-94ac-ac49f30ae26d.webp\" alt=\"\u5982\u4f55\u67e5\u770bpython\u73af\u5883\u8bbe\u7f6e\" \/><\/p>\n<p><p> \u67e5\u770bPython\u73af\u5883\u8bbe\u7f6e\u662f\u5f00\u53d1\u8005\u5728\u7ba1\u7406\u548c\u914d\u7f6ePython\u9879\u76ee\u65f6\u7684\u5e38\u89c1\u9700\u6c42\u3002\u8981\u67e5\u770bPython\u73af\u5883\u8bbe\u7f6e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7<strong>\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u3001\u67e5\u770b\u865a\u62df\u73af\u5883\u914d\u7f6e\u3001\u4f7f\u7528IDE\u7279\u6027<\/strong>\u7b49\u65b9\u5f0f\u6765\u5b9e\u73b0\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u51e0\u79cd\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u5177\u4f53\u6b65\u9aa4\u548c\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u547d\u4ee4\u884c\u67e5\u770bPython\u7248\u672c\u548c\u8def\u5f84<\/strong><\/li>\n<\/ol>\n<p><p>\u8981\u67e5\u770b\u5f53\u524dPython\u7248\u672c\u548c\u5b89\u88c5\u8def\u5f84\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python --version<\/p>\n<p>which python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e24\u4e2a\u547d\u4ee4\u5206\u522b\u8f93\u51faPython\u7684\u7248\u672c\u53f7\u548cPython\u53ef\u6267\u884c\u6587\u4ef6\u6240\u5728\u7684\u8def\u5f84\u3002\u901a\u8fc7\u67e5\u770b\u8fd9\u4e9b\u4fe1\u606f\uff0c\u4f60\u53ef\u4ee5\u77e5\u9053\u5f53\u524d\u4f7f\u7528\u7684Python\u7248\u672c\u53ca\u5176\u5b89\u88c5\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u67e5\u770b\u5df2\u5b89\u88c5\u7684Python\u5e93<\/strong><\/li>\n<\/ol>\n<p><p>\u4f7f\u7528<code>pip<\/code>\u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u5df2\u5b89\u88c5\u7684Python\u5e93\u53ca\u5176\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5217\u51fa\u6240\u6709\u5df2\u5b89\u88c5\u7684Python\u5e93\u53ca\u5176\u7248\u672c\u53f7\uff0c\u5e2e\u52a9\u4f60\u786e\u8ba4\u9879\u76ee\u6240\u9700\u7684\u4f9d\u8d56\u662f\u5426\u5df2\u6b63\u786e\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u67e5\u770b\u73af\u5883\u53d8\u91cf<\/strong><\/li>\n<\/ol>\n<p><p>Python\u7684\u884c\u4e3a\u53ef\u80fd\u4f1a\u53d7\u5230\u73af\u5883\u53d8\u91cf\u7684\u5f71\u54cd\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u4e0ePython\u76f8\u5173\u7684\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">env | grep -i python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e00\u547d\u4ee4\u4f1a\u8fc7\u6ee4\u51fa\u6240\u6709\u5305\u542b\u201cpython\u201d\u5b57\u6837\u7684\u73af\u5883\u53d8\u91cf\uff0c\u5e2e\u52a9\u4f60\u4e86\u89e3\u54ea\u4e9b\u73af\u5883\u53d8\u91cf\u53ef\u80fd\u5f71\u54cdPython\u7684\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u67e5\u770b\u865a\u62df\u73af\u5883\u914d\u7f6e<\/p>\n<\/p>\n<ol>\n<li><strong>\u865a\u62df\u73af\u5883\u57fa\u7840<\/strong><\/li>\n<\/ol>\n<p><p>\u865a\u62df\u73af\u5883\u662fPython\u4e2d\u7528\u4e8e\u9694\u79bb\u9879\u76ee\u4f9d\u8d56\u7684\u5de5\u5177\u3002\u521b\u5efa\u865a\u62df\u73af\u5883\u53ef\u4ee5\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u4f9d\u8d56\u51b2\u7a81\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6fc0\u6d3b\u548c\u67e5\u770b\u865a\u62df\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u8981\u67e5\u770b\u865a\u62df\u73af\u5883\u7684\u8bbe\u7f6e\uff0c\u9996\u5148\u9700\u8981\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002\u5728Unix\u6216Mac\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6fc0\u6d3b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source \/path\/to\/venv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u4f7f\u7528\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">\\path\\to\\venv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u540e\uff0c\u4f7f\u7528<code>pip list<\/code>\u548c<code>which python<\/code>\u547d\u4ee4\u67e5\u770b\u8be5\u865a\u62df\u73af\u5883\u4e2d\u7684\u5e93\u548cPython\u89e3\u91ca\u5668\u8def\u5f84\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u67e5\u770b\u865a\u62df\u73af\u5883\u914d\u7f6e\u6587\u4ef6<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u76ee\u5f55\u4e2d\uff0c\u4e00\u822c\u4f1a\u6709\u4e00\u4e2a<code>pyvenv.cfg<\/code>\u6587\u4ef6\uff0c\u5305\u542b\u865a\u62df\u73af\u5883\u7684\u914d\u7f6e\u4fe1\u606f\u3002\u53ef\u4ee5\u901a\u8fc7\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00\u67e5\u770b\u5176\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528IDE\u7279\u6027<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528PyCharm\u67e5\u770bPython\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>PyCharm\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python IDE\uff0c\u63d0\u4f9b\u4e86\u76f4\u89c2\u7684\u65b9\u5f0f\u67e5\u770b\u548c\u7ba1\u7406Python\u73af\u5883\u3002\u5728PyCharm\u4e2d\uff0c\u6253\u5f00\u201cFile\u201d -&gt; \u201cSettings\u201d -&gt; \u201cProject: <project_name>\u201d -&gt; \u201cPython Interpreter\u201d\uff0c\u5373\u53ef\u67e5\u770b\u5f53\u524d\u9879\u76ee\u4f7f\u7528\u7684Python\u89e3\u91ca\u5668\u548c\u5df2\u5b89\u88c5\u7684\u5e93\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528VSCode\u67e5\u770bPython\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u5728Visual Studio Code\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u9762\u677f\uff08Ctrl+Shift+P\uff09\u8f93\u5165\u201cPython: Select Interpreter\u201d\uff0c\u9009\u62e9\u548c\u67e5\u770b\u5f53\u524d\u9879\u76ee\u7684Python\u73af\u5883\u3002VSCode\u4f1a\u5217\u51fa\u53ef\u7528\u7684Python\u89e3\u91ca\u5668\u4f9b\u9009\u62e9\uff0c\u5e76\u663e\u793a\u5f53\u524d\u4f7f\u7528\u7684\u89e3\u91ca\u5668\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7<strong>\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u3001\u67e5\u770b\u865a\u62df\u73af\u5883\u914d\u7f6e\u3001\u4f7f\u7528IDE\u7279\u6027<\/strong>\u7b49\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5168\u9762\u4e86\u89e3\u548c\u7ba1\u7406Python\u73af\u5883\u8bbe\u7f6e\u3002\u8fd9\u4e9b\u65b9\u6cd5\u4e0d\u4ec5\u5e2e\u52a9\u5f00\u53d1\u8005\u786e\u8ba4\u9879\u76ee\u4f7f\u7528\u7684Python\u7248\u672c\u548c\u4f9d\u8d56\u5e93\uff0c\u4e5f\u4e3a\u9879\u76ee\u7684\u73af\u5883\u914d\u7f6e\u548c\u8fc1\u79fb\u63d0\u4f9b\u4e86\u4fbf\u5229\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u7075\u6d3b\u8fd0\u7528\u8fd9\u4e9b\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u907f\u514d\u4f9d\u8d56\u51b2\u7a81\u548c\u73af\u5883\u914d\u7f6e\u95ee\u9898\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u4ee3\u7801\u8d28\u91cf\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u68c0\u67e5\u6211\u5f53\u524d\u4f7f\u7528\u7684Python\u7248\u672c\uff1f<\/strong><br \/>\u8981\u67e5\u770b\u60a8\u5f53\u524d\u4f7f\u7528\u7684Python\u7248\u672c\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u3002\u8fd9\u5c06\u663e\u793a\u60a8\u5b89\u88c5\u7684Python\u7248\u672c\u4fe1\u606f\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u865a\u62df\u73af\u5883\uff0c\u786e\u4fdd\u5728\u6fc0\u6d3b\u8be5\u73af\u5883\u540e\u8fd0\u884c\u6b64\u547d\u4ee4\uff0c\u4ee5\u83b7\u5f97\u6b63\u786e\u7684\u7248\u672c\u4fe1\u606f\u3002<\/p>\n<p><strong>\u5982\u4f55\u67e5\u770bPython\u5e93\u548c\u6a21\u5757\u7684\u5b89\u88c5\u60c5\u51b5\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>pip list<\/code>\u547d\u4ee4\u6765\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5e93\u548c\u6a21\u5757\u3002\u8fd9\u6761\u547d\u4ee4\u5c06\u5728\u7ec8\u7aef\u4e2d\u5217\u51fa\u6240\u6709\u901a\u8fc7pip\u5b89\u88c5\u7684\u5305\u53ca\u5176\u7248\u672c\u3002\u5982\u679c\u60a8\u60f3\u83b7\u53d6\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip freeze<\/code>\uff0c\u5b83\u5c06\u4ee5\u4e00\u79cd\u53ef\u91cd\u5b9a\u5411\u5230requirements.txt\u6587\u4ef6\u7684\u683c\u5f0f\u5217\u51fa\u6240\u6709\u5305\u3002<\/p>\n<p><strong>\u6211\u8be5\u5982\u4f55\u68c0\u67e5\u6211\u7684Python\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\uff1f<\/strong><br \/>\u8981\u67e5\u770bPython\u7684\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>echo $PATH<\/code>\uff08\u5728Linux\u548cMac\u4e0a\uff09\u6216<code>echo %PATH%<\/code>\uff08\u5728Windows\u4e0a\uff09\u3002\u8fd9\u5c06\u663e\u793a\u5305\u62ecPython\u8def\u5f84\u5728\u5185\u7684\u6240\u6709\u73af\u5883\u53d8\u91cf\u3002\u786e\u4fddPython\u7684\u5b89\u88c5\u8def\u5f84\u5728\u5217\u8868\u4e2d\uff0c\u4ee5\u4fbf\u60a8\u7684\u7cfb\u7edf\u80fd\u591f\u627e\u5230Python\u89e3\u91ca\u5668\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u67e5\u770bPython\u73af\u5883\u8bbe\u7f6e\u662f\u5f00\u53d1\u8005\u5728\u7ba1\u7406\u548c\u914d\u7f6ePython\u9879\u76ee\u65f6\u7684\u5e38\u89c1\u9700\u6c42\u3002\u8981\u67e5\u770bPython\u73af\u5883\u8bbe\u7f6e\uff0c\u4f60\u53ef\u4ee5\u901a [&hellip;]","protected":false},"author":3,"featured_media":964791,"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\/964786"}],"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=964786"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/964786\/revisions"}],"predecessor-version":[{"id":964795,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/964786\/revisions\/964795"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/964791"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=964786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=964786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=964786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}