{"id":921395,"date":"2024-12-26T14:12:16","date_gmt":"2024-12-26T06:12:16","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/921395.html"},"modified":"2024-12-26T14:12:19","modified_gmt":"2024-12-26T06:12:19","slug":"%e5%a6%82%e4%bd%95%e6%b7%bb%e5%8a%a0python%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/921395.html","title":{"rendered":"\u5982\u4f55\u6dfb\u52a0python\u73af\u5883\u53d8\u91cf"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24210401\/da9ab1fb-c0bf-4480-8ecf-8bcd350e967b.webp\" alt=\"\u5982\u4f55\u6dfb\u52a0python\u73af\u5883\u53d8\u91cf\" \/><\/p>\n<p><p> \u6dfb\u52a0Python\u73af\u5883\u53d8\u91cf\u662f\u4e00\u4e2a\u57fa\u672c\u5374\u91cd\u8981\u7684\u6b65\u9aa4\uff0c\u5b83\u53ef\u4ee5\u8ba9\u4f60\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u76f4\u63a5\u8fd0\u884cPython\u547d\u4ee4\u6216\u811a\u672c\uff0c\u800c\u4e0d\u9700\u8981\u6bcf\u6b21\u90fd\u6307\u5b9aPython\u7684\u5b89\u88c5\u8def\u5f84\u3002<strong>\u6dfb\u52a0Python\u73af\u5883\u53d8\u91cf\u7684\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\uff1a\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84\u3001\u5c06\u8be5\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\u3001\u9a8c\u8bc1\u914d\u7f6e\u662f\u5426\u6210\u529f<\/strong>\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u8fdb\u884c\u8fd9\u4e9b\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u627e\u5230Python\u7684\u5b89\u88c5\u8def\u5f84<\/p>\n<\/p>\n<p><p>\u5728\u6dfb\u52a0\u73af\u5883\u53d8\u91cf\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u786e\u5b9aPython\u7684\u5b89\u88c5\u8def\u5f84\u3002\u901a\u5e38\uff0c\u5b89\u88c5Python\u540e\uff0c\u4f1a\u5728\u7cfb\u7edf\u4e2d\u521b\u5efa\u4e00\u4e2a\u9ed8\u8ba4\u7684\u5b89\u88c5\u76ee\u5f55\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Windows\u7cfb\u7edf\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\n<p>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08Cmd\uff09\uff0c\u8f93\u5165<code>python<\/code>\uff0c\u5982\u679c\u7cfb\u7edf\u63d0\u793a\u201c\u672a\u627e\u5230\u547d\u4ee4\u201d\uff0c\u5219\u53ef\u80fd\u672a\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u4f60\u53ef\u4ee5\u5728\u5b89\u88c5Python\u65f6\uff0c\u901a\u8fc7Python\u5b89\u88c5\u7a0b\u5e8f\u68c0\u67e5\u5b89\u88c5\u8def\u5f84\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cPython\u901a\u5e38\u5b89\u88c5\u5728<code>C:\\Users\\&lt;YourUsername&gt;\\AppData\\Local\\Programs\\Python\\PythonXX<\/code>\uff08XX\u4ee3\u8868\u7248\u672c\u53f7\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u53e6\u5916\uff0c\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165<code>where python<\/code>\u6765\u67e5\u627ePython\u7684\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>macOS\u548cLinux\u7cfb\u7edf\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165<code>which python<\/code>\u6216<code>which python3<\/code>\uff0c\u901a\u5e38\u4f1a\u663e\u793aPython\u7684\u5b89\u88c5\u8def\u5f84\u3002\u5982\u679c\u4f60\u4f7f\u7528\u4e86\u5305\u7ba1\u7406\u5de5\u5177\uff08\u5982Homebrew\uff09\u5b89\u88c5\u7684Python\uff0c\u8def\u5f84\u53ef\u80fd\u5728<code>\/usr\/local\/bin\/python<\/code>\u6216<code>\/usr\/local\/bin\/python3<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u5c06Python\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d<\/p>\n<\/p>\n<p><p>\u6dfb\u52a0\u8def\u5f84\u5230\u73af\u5883\u53d8\u91cf\u7684\u5177\u4f53\u6b65\u9aa4\u56e0\u64cd\u4f5c\u7cfb\u7edf\u800c\u5f02\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u5206\u522b\u4ecb\u7ecd\u5728Windows\u3001macOS\u548cLinux\u7cfb\u7edf\u4e0a\u5982\u4f55\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5728Windows\u7cfb\u7edf\u4e0a\u6dfb\u52a0Python\u73af\u5883\u53d8\u91cf\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\n<p>\u6253\u5f00\u201c\u63a7\u5236\u9762\u677f\u201d\uff0c\u9009\u62e9\u201c\u7cfb\u7edf\u548c\u5b89\u5168\u201d\uff0c\u7136\u540e\u9009\u62e9\u201c\u7cfb\u7edf\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\uff0c\u5728\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u7a97\u53e3\u4e2d\u9009\u62e9\u201c\u73af\u5883\u53d8\u91cf\u201d\u6309\u94ae\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u6216\u201c\u7528\u6237\u53d8\u91cf\u201d\u4e2d\u627e\u5230\u201cPath\u201d\u53d8\u91cf\uff0c\u9009\u4e2d\u5b83\u5e76\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u5728\u7f16\u8f91\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u65b0\u5efa\u201d\uff0c\u7136\u540e\u8f93\u5165Python\u7684\u5b89\u88c5\u8def\u5f84\uff08\u5982<code>C:\\Python39<\/code>\u6216\u5176\u4ed6\u7248\u672c\u8def\u5f84\uff09\u3002\u786e\u4fdd\u8def\u5f84\u4e2d\u5305\u542bPython\u53ef\u6267\u884c\u6587\u4ef6\uff08\u5982<code>python.exe<\/code>\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u8bbe\u7f6e\uff0c\u5e76\u5173\u95ed\u6240\u6709\u7a97\u53e3\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5728macOS\u548cLinux\u7cfb\u7edf\u4e0a\u6dfb\u52a0Python\u73af\u5883\u53d8\u91cf\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\n<p>\u6253\u5f00\u7ec8\u7aef\uff0c\u7f16\u8f91\u7528\u6237\u4e3b\u76ee\u5f55\u4e0b\u7684<code>.bash_profile<\/code>\u6216<code>.bashrc<\/code>\u6587\u4ef6\uff08\u53d6\u51b3\u4e8e\u7cfb\u7edf\u9ed8\u8ba4\u4f7f\u7528\u7684Shell\uff09\u3002\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982nano\u6216vi\uff09\u6253\u5f00\u6587\u4ef6\uff0c\u4f8b\u5982\uff1a<code>nano ~\/.bash_profile<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4e00\u884c\uff1a<code>export PATH=&quot;\/usr\/local\/bin\/python:$PATH&quot;<\/code>\uff08\u8bf7\u5c06<code>\/usr\/local\/bin\/python<\/code>\u66ff\u6362\u4e3a\u5b9e\u9645Python\u8def\u5f84\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u4fdd\u5b58\u6587\u4ef6\u5e76\u9000\u51fa\u7f16\u8f91\u5668\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u8fd0\u884c<code>source ~\/.bash_profile<\/code>\uff08\u6216<code>source ~\/.bashrc<\/code>\uff09\u547d\u4ee4\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u9a8c\u8bc1Python\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u662f\u5426\u6210\u529f<\/p>\n<\/p>\n<p><p>\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u4f60\u9700\u8981\u9a8c\u8bc1Python\u73af\u5883\u53d8\u91cf\u662f\u5426\u8bbe\u7f6e\u6b63\u786e\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u8fdb\u884c\u68c0\u67e5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\uff0c\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\uff0c\u786e\u8ba4\u662f\u5426\u80fd\u663e\u793aPython\u7684\u7248\u672c\u53f7\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u5c1d\u8bd5\u8fd0\u884cPython\u811a\u672c\u6216\u547d\u4ee4\uff0c\u786e\u4fddPython\u73af\u5883\u80fd\u591f\u6b63\u5e38\u5de5\u4f5c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Python\u7248\u672c\u7ba1\u7406\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684\u7cfb\u7edf\u4e2d\u6709\u591a\u4e2aPython\u7248\u672c\uff0c\u5efa\u8bae\u4f7f\u7528Python\u7248\u672c\u7ba1\u7406\u5de5\u5177\uff0c\u5982pyenv\uff08\u9002\u7528\u4e8emacOS\u548cLinux\uff09\u6216Anaconda\uff08\u8de8\u5e73\u53f0\uff09\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u7ba1\u7406\u548c\u5207\u6362\u4e0d\u540c\u7248\u672c\u7684Python\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6743\u9650\u95ee\u9898\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u7cfb\u7edf\u4e2d\uff0c\u7f16\u8f91\u73af\u5883\u53d8\u91cf\u53ef\u80fd\u9700\u8981\u7ba1\u7406\u5458\u6743\u9650\u3002\u5982\u679c\u9047\u5230\u6743\u9650\u95ee\u9898\uff0c\u8bf7\u786e\u4fdd\u4f7f\u7528\u5177\u6709\u8db3\u591f\u6743\u9650\u7684\u8d26\u6237\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6301\u7eed\u7ef4\u62a4\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u73af\u5883\u53d8\u91cf\u7684\u914d\u7f6e\u5e76\u975e\u4e00\u52b3\u6c38\u9038\u3002\u5f53\u4f60\u66f4\u65b0Python\u7248\u672c\u6216\u66f4\u6539\u5b89\u88c5\u8def\u5f84\u65f6\uff0c\u8bb0\u5f97\u53ca\u65f6\u66f4\u65b0\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u6dfb\u52a0\u5e76\u914d\u7f6ePython\u73af\u5883\u53d8\u91cf\uff0c\u4f7f\u5f97Python\u7684\u4f7f\u7528\u66f4\u52a0\u4fbf\u6377\u548c\u9ad8\u6548\u3002\u8fd9\u662fPython\u5f00\u53d1\u4e2d\u4e00\u4e2a\u57fa\u7840\u4e14\u91cd\u8981\u7684\u6280\u80fd\uff0c\u638c\u63e1\u5b83\u5c06\u4e3a\u4f60\u7684\u7f16\u7a0b\u5de5\u4f5c\u5e26\u6765\u6781\u5927\u7684\u4fbf\u5229\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u68c0\u67e5\u6211\u7684Python\u73af\u5883\u53d8\u91cf\u662f\u5426\u8bbe\u7f6e\u6b63\u786e\uff1f<\/strong><br \/>\u8981\u68c0\u67e5Python\u73af\u5883\u53d8\u91cf\u662f\u5426\u8bbe\u7f6e\u6b63\u786e\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u3002\u5982\u679c\u7cfb\u7edf\u80fd\u591f\u8fd4\u56dePython\u7684\u7248\u672c\u53f7\uff0c\u8bf4\u660e\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u6210\u529f\u3002\u5982\u679c\u51fa\u73b0\u201c\u627e\u4e0d\u5230\u547d\u4ee4\u201d\u7684\u9519\u8bef\u63d0\u793a\uff0c\u5219\u8bf4\u660e\u73af\u5883\u53d8\u91cf\u672a\u6b63\u786e\u8bbe\u7f6e\u3002<\/p>\n<p><strong>\u5728Windows\u548cMac\u7cfb\u7edf\u4e2d\uff0c\u6dfb\u52a0Python\u73af\u5883\u53d8\u91cf\u7684\u6b65\u9aa4\u6709\u4f55\u4e0d\u540c\uff1f<\/strong><br \/>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u4e2d\u7684\u201c\u73af\u5883\u53d8\u91cf\u201d\u9009\u9879\u8fdb\u884c\u8bbe\u7f6e\uff0c\u627e\u5230\u201cPath\u201d\u53d8\u91cf\u5e76\u6dfb\u52a0Python\u7684\u5b89\u88c5\u8def\u5f84\u3002\u800c\u5728Mac\u7cfb\u7edf\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u7f16\u8f91<code>.bash_profile<\/code>\u6216<code>.zshrc<\/code>\u6587\u4ef6\uff0c\u6dfb\u52a0<code>export PATH=&quot;\/usr\/local\/bin\/python3:$PATH&quot;<\/code>\u8fd9\u6837\u7684\u884c\uff0c\u4fdd\u5b58\u5e76\u91cd\u542f\u7ec8\u7aef\u4f7f\u66f4\u6539\u751f\u6548\u3002\u4e0d\u540c\u7cfb\u7edf\u7684\u8bbe\u7f6e\u65b9\u5f0f\u5404\u6709\u7279\u70b9\uff0c\u9700\u8981\u6839\u636e\u5177\u4f53\u73af\u5883\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<p><strong>\u6dfb\u52a0Python\u73af\u5883\u53d8\u91cf\u540e\uff0c\u5982\u4f55\u786e\u4fdd\u6240\u6709\u7a0b\u5e8f\u90fd\u80fd\u8bbf\u95ee\u5230\u5b83\uff1f<\/strong><br \/>\u5728\u8bbe\u7f6ePython\u73af\u5883\u53d8\u91cf\u540e\uff0c\u786e\u4fdd\u5728\u7cfb\u7edf\u7684\u201cPath\u201d\u53d8\u91cf\u4e2d\u6dfb\u52a0\u4e86Python\u7684\u5b89\u88c5\u8def\u5f84\u3002\u4e3a\u4e86\u8ba9\u6240\u6709\u7a0b\u5e8f\u90fd\u80fd\u8bbf\u95ee\u5230Python\uff0c\u53ef\u4ee5\u91cd\u65b0\u542f\u52a8\u8ba1\u7b97\u673a\uff0c\u786e\u4fdd\u6240\u6709\u5e94\u7528\u7a0b\u5e8f\u90fd\u80fd\u91cd\u65b0\u52a0\u8f7d\u73af\u5883\u53d8\u91cf\u3002\u540c\u65f6\uff0c\u5728\u5f00\u53d1\u5de5\u5177\u6216IDE\u4e2d\uff0c\u68c0\u67e5\u5176\u914d\u7f6e\u8bbe\u7f6e\uff0c\u786e\u4fdd\u6307\u5411\u6b63\u786e\u7684Python\u89e3\u91ca\u5668\u8def\u5f84\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u6dfb\u52a0Python\u73af\u5883\u53d8\u91cf\u662f\u4e00\u4e2a\u57fa\u672c\u5374\u91cd\u8981\u7684\u6b65\u9aa4\uff0c\u5b83\u53ef\u4ee5\u8ba9\u4f60\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u76f4\u63a5\u8fd0\u884cPython\u547d\u4ee4\u6216\u811a\u672c\uff0c\u800c\u4e0d [&hellip;]","protected":false},"author":3,"featured_media":921404,"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\/921395"}],"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=921395"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/921395\/revisions"}],"predecessor-version":[{"id":921406,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/921395\/revisions\/921406"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/921404"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=921395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=921395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=921395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}