{"id":1017305,"date":"2024-12-27T12:25:32","date_gmt":"2024-12-27T04:25:32","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1017305.html"},"modified":"2024-12-27T12:25:40","modified_gmt":"2024-12-27T04:25:40","slug":"%e5%a6%82%e4%bd%95%e5%bd%bb%e5%ba%95%e5%88%a0%e9%99%a4python%e8%b7%af%e5%be%84","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1017305.html","title":{"rendered":"\u5982\u4f55\u5f7b\u5e95\u5220\u9664python\u8def\u5f84"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25160234\/65537b9f-8ba2-40c4-bd90-3049b913e309.webp\" alt=\"\u5982\u4f55\u5f7b\u5e95\u5220\u9664python\u8def\u5f84\" \/><\/p>\n<p><p> \u8981\u5f7b\u5e95\u5220\u9664Python\u8def\u5f84\uff0c<strong>\u9700\u8981\u4ece\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u3001Python\u5b89\u88c5\u76ee\u5f55\u548c\u76f8\u5173\u7684\u6ce8\u518c\u8868\u9879\u4e2d\u8fdb\u884c\u6e05\u7406<\/strong>\u3002\u8fd9\u4fdd\u8bc1\u4e86Python\u53ca\u5176\u8def\u5f84\u4e0d\u4f1a\u5728\u7cfb\u7edf\u4e2d\u6b8b\u7559\uff0c\u4ece\u800c\u5f71\u54cd\u540e\u7eed\u7684\u5b89\u88c5\u548c\u8fd0\u884c\u3002\u8be6\u7ec6\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c<strong>\u786e\u4fdd\u6ca1\u6709\u5176\u4ed6\u7a0b\u5e8f\u6b63\u5728\u4f7f\u7528Python\u8def\u5f84<\/strong>\u3002\u5982\u679c\u6709\u7a0b\u5e8f\u4f9d\u8d56\u4e8ePython\u8def\u5f84\uff0c\u9700\u8981\u63d0\u524d\u505a\u597d\u5907\u4efd\u6216\u786e\u8ba4\u4e0d\u518d\u9700\u8981\u8fd9\u4e9b\u7a0b\u5e8f\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u9010\u6b65\u6e05\u9664Python\u8def\u5f84\uff1a<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u79fb\u9664\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u7684Python\u8def\u5f84<\/h3>\n<\/p>\n<p><h4>1. Windows\u7cfb\u7edf<\/h4>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0cPython\u8def\u5f84\u901a\u5e38\u5305\u542b\u5728\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u8981\u5220\u9664\u8fd9\u4e9b\u8def\u5f84\uff0c\u53ef\u4ee5\u6309\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u6253\u5f00\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e<\/strong>\uff1a\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u6211\u7684\u7535\u8111\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\uff0c\u5728\u5f39\u51fa\u7684\u7a97\u53e3\u4e2d\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u3002<\/li>\n<li><strong>\u7f16\u8f91\u8def\u5f84<\/strong>\uff1a\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u4e0b\u627e\u5230\u201cPath\u201d\uff0c\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u3002\u5728\u5f39\u51fa\u7684\u7a97\u53e3\u4e2d\uff0c\u627e\u5230\u5305\u542bPython\u8def\u5f84\u7684\u6761\u76ee\uff0c\u5982<code>C:\\Python39<\/code>\u6216<code>C:\\Python39\\Scripts<\/code>\uff0c\u9009\u62e9\u5e76\u5220\u9664\u8fd9\u4e9b\u6761\u76ee\u3002<\/li>\n<li><strong>\u4fdd\u5b58\u66f4\u6539<\/strong>\uff1a\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u66f4\u6539\uff0c\u5e76\u5173\u95ed\u6240\u6709\u7a97\u53e3\u3002<\/li>\n<\/ul>\n<p><h4>2. macOS\u548cLinux\u7cfb\u7edf<\/h4>\n<\/p>\n<p><p>\u5728macOS\u548cLinux\u7cfb\u7edf\u4e2d\uff0cPython\u8def\u5f84\u901a\u5e38\u914d\u7f6e\u5728<code>~\/.bash_profile<\/code>\u3001<code>~\/.bashrc<\/code>\u6216<code>~\/.zshrc<\/code>\u6587\u4ef6\u4e2d\u3002\u8981\u5220\u9664\u8fd9\u4e9b\u8def\u5f84\uff0c\u53ef\u4ee5\u6309\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u6253\u5f00\u7ec8\u7aef<\/strong>\uff1a\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982nano\u6216vim\uff09\u6253\u5f00\u4e0a\u8ff0\u914d\u7f6e\u6587\u4ef6\u4e4b\u4e00\u3002<\/li>\n<li><strong>\u67e5\u627e\u5e76\u5220\u9664\u8def\u5f84<\/strong>\uff1a\u627e\u5230\u7c7b\u4f3c\u4e8e<code>export PATH=&quot;\/usr\/local\/bin\/python3:$PATH&quot;<\/code>\u7684\u884c\uff0c\u5220\u9664\u6216\u6ce8\u91ca\u6389\u8fd9\u4e9b\u884c\u3002<\/li>\n<li><strong>\u5237\u65b0\u914d\u7f6e<\/strong>\uff1a\u4fdd\u5b58\u6587\u4ef6\u540e\uff0c\u8fd0\u884c<code>source ~\/.bash_profile<\/code>\u6216<code>source ~\/.bashrc<\/code>\uff08\u53d6\u51b3\u4e8e\u4f60\u6240\u7f16\u8f91\u7684\u6587\u4ef6\uff09\u4ee5\u5237\u65b0\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001\u5220\u9664Python\u5b89\u88c5\u76ee\u5f55<\/h3>\n<\/p>\n<p><p>Python\u7684\u5b89\u88c5\u76ee\u5f55\u901a\u5e38\u4f4d\u4e8e\u7cfb\u7edf\u76d8\u7684Program Files\u6216\u7528\u6237\u76ee\u5f55\u4e0b\u3002\u5220\u9664\u8fd9\u4e9b\u76ee\u5f55\u53ef\u4ee5\u786e\u4fddPython\u6587\u4ef6\u4e0d\u518d\u5b58\u5728\u4e8e\u7cfb\u7edf\u4e2d\u3002<\/p>\n<\/p>\n<p><h4>1. Windows\u7cfb\u7edf<\/h4>\n<\/p>\n<ul>\n<li><strong>\u5b9a\u4f4d\u5b89\u88c5\u76ee\u5f55<\/strong>\uff1a\u901a\u5e38\u4f4d\u4e8e<code>C:\\Python39<\/code>\u6216<code>C:\\Program Files\\Python39<\/code>\u3002<\/li>\n<li><strong>\u5220\u9664\u5b89\u88c5\u76ee\u5f55<\/strong>\uff1a\u53f3\u952e\u70b9\u51fb\u8fd9\u4e9b\u76ee\u5f55\uff0c\u9009\u62e9\u201c\u5220\u9664\u201d\u3002<\/li>\n<\/ul>\n<p><h4>2. macOS\u548cLinux\u7cfb\u7edf<\/h4>\n<\/p>\n<ul>\n<li><strong>\u67e5\u627e\u5b89\u88c5\u76ee\u5f55<\/strong>\uff1a\u4f7f\u7528\u547d\u4ee4<code>which python3<\/code>\u6216<code>whereis python3<\/code>\u6765\u67e5\u627ePython\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/li>\n<li><strong>\u5220\u9664\u5b89\u88c5\u76ee\u5f55<\/strong>\uff1a\u4f7f\u7528<code>rm -rf \/usr\/local\/bin\/python3<\/code>\u6765\u5220\u9664Python\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001\u6e05\u7406\u6ce8\u518c\u8868\u9879\uff08\u4ec5\u9002\u7528\u4e8eWindows\uff09<\/h3>\n<\/p>\n<p><p>Python\u5728Windows\u7cfb\u7edf\u4e2d\u53ef\u80fd\u4f1a\u5728\u6ce8\u518c\u8868\u4e2d\u7559\u4e0b\u76f8\u5173\u6761\u76ee\u3002\u6e05\u7406\u8fd9\u4e9b\u6761\u76ee\u53ef\u4ee5\u786e\u4fdd\u7cfb\u7edf\u4e0d\u518d\u8bc6\u522bPython\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u6253\u5f00\u6ce8\u518c\u8868\u7f16\u8f91\u5668<\/strong>\uff1a\u6309<code>Win + R<\/code>\uff0c\u8f93\u5165<code>regedit<\/code>\u5e76\u56de\u8f66\u3002<\/li>\n<li><strong>\u67e5\u627ePython\u76f8\u5173\u7684\u6ce8\u518c\u8868\u9879<\/strong>\uff1a\u5bfc\u822a\u5230<code>HKEY_LOCAL_MACHINE\\SOFTWARE\\Python<\/code>\u548c<code>HKEY_CURRENT_USER\\SOFTWARE\\Python<\/code>\u3002<\/li>\n<li><strong>\u5220\u9664\u76f8\u5173\u9879<\/strong>\uff1a\u53f3\u952e\u70b9\u51fb\u8fd9\u4e9b\u9879\uff0c\u9009\u62e9\u201c\u5220\u9664\u201d\u3002<\/li>\n<\/ul>\n<p><h3>\u56db\u3001\u68c0\u67e5\u548c\u5220\u9664Python\u76f8\u5173\u7684\u5feb\u6377\u65b9\u5f0f\u548c\u914d\u7f6e\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>Python\u5728\u5b89\u88c5\u65f6\u53ef\u80fd\u4f1a\u521b\u5efa\u5feb\u6377\u65b9\u5f0f\u548c\u914d\u7f6e\u6587\u4ef6\uff0c\u8fd9\u4e9b\u6587\u4ef6\u6709\u65f6\u4f4d\u4e8e\u7528\u6237\u76ee\u5f55\u4e0b\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u5220\u9664\u5feb\u6377\u65b9\u5f0f<\/strong>\uff1a\u68c0\u67e5\u684c\u9762\u3001\u5f00\u59cb\u83dc\u5355\u548c\u4efb\u52a1\u680f\u4e0a\u7684Python\u5feb\u6377\u65b9\u5f0f\uff0c\u5e76\u5220\u9664\u5b83\u4eec\u3002<\/li>\n<li><strong>\u5220\u9664\u914d\u7f6e\u6587\u4ef6<\/strong>\uff1a\u5728\u7528\u6237\u76ee\u5f55\u4e0b\u67e5\u627e<code>.python_history<\/code>\u3001<code>.pylintrc<\/code>\u7b49\u914d\u7f6e\u6587\u4ef6\uff0c\u5e76\u5220\u9664\u5b83\u4eec\u3002<\/li>\n<\/ul>\n<p><h3>\u4e94\u3001\u9a8c\u8bc1Python\u8def\u5f84\u5220\u9664\u6210\u529f<\/h3>\n<\/p>\n<ul>\n<li><strong>\u9a8c\u8bc1\u547d\u4ee4\u884c<\/strong>\uff1a\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\uff0c\u5982\u679c\u663e\u793a\u201c\u672a\u627e\u5230\u547d\u4ee4\u201d\u6216\u7c7b\u4f3c\u4fe1\u606f\uff0c\u8bf4\u660ePython\u8def\u5f84\u5df2\u88ab\u6210\u529f\u5220\u9664\u3002<\/li>\n<li><strong>\u68c0\u67e5\u7cfb\u7edf\u73af\u5883\u53d8\u91cf<\/strong>\uff1a\u786e\u4fdd\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u7684Python\u8def\u5f84\u5df2\u88ab\u79fb\u9664\u3002<\/li>\n<\/ul>\n<p><h3>\u516d\u3001\u603b\u7ed3\u548c\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><p>\u5f7b\u5e95\u5220\u9664Python\u8def\u5f84\u9700\u8981\u5bf9\u7cfb\u7edf\u8fdb\u884c\u591a\u65b9\u9762\u7684\u6e05\u7406\u3002<strong>\u786e\u4fdd\u5728\u6e05\u7406\u524d\u505a\u597d\u5907\u4efd\uff0c\u5c24\u5176\u662f\u91cd\u8981\u7684Python\u811a\u672c\u548c\u73af\u5883\u914d\u7f6e<\/strong>\u3002\u53e6\u5916\uff0c\u5220\u9664Python\u8def\u5f84\u540e\uff0c\u5982\u679c\u9700\u8981\u91cd\u65b0\u5b89\u88c5Python\uff0c\u52a1\u5fc5\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\uff0c\u5e76\u6309\u7167\u5b98\u65b9\u6307\u5357\u8fdb\u884c\u5b89\u88c5\uff0c\u4ee5\u907f\u514d\u8def\u5f84\u95ee\u9898\u518d\u6b21\u51fa\u73b0\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u53ef\u4ee5\u5f7b\u5e95\u5220\u9664Python\u8def\u5f84\uff0c\u786e\u4fdd\u7cfb\u7edf\u7684\u6574\u6d01\u548c\u540e\u7eedPython\u73af\u5883\u7684\u6b63\u786e\u914d\u7f6e\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u786e\u4fdd\u5728Windows\u4e0a\u5b8c\u5168\u5378\u8f7dPython\u53ca\u5176\u8def\u5f84\uff1f<\/strong><br \/>\u8981\u5728Windows\u4e0a\u5f7b\u5e95\u5378\u8f7dPython\u5e76\u5220\u9664\u5176\u8def\u5f84\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u63a7\u5236\u9762\u677f\u8fdb\u884c\u5378\u8f7d\u3002\u627e\u5230Python\u7684\u5b89\u88c5\u9879\uff0c\u70b9\u51fb\u201c\u5378\u8f7d\u201d\u3002\u63a5\u7740\uff0c\u624b\u52a8\u68c0\u67e5\u73af\u5883\u53d8\u91cf\uff0c\u786e\u4fdd\u5c06Python\u7684\u5b89\u88c5\u8def\u5f84\u4ece\u7cfb\u7edf\u53d8\u91cf\u4e2d\u5220\u9664\u3002\u53ef\u4ee5\u901a\u8fc7\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u4e2d\u7684\u201c\u73af\u5883\u53d8\u91cf\u201d\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002\u5b8c\u6210\u8fd9\u4e9b\u6b65\u9aa4\u540e\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165<code>python<\/code>\u6765\u786e\u8ba4\u662f\u5426\u5df2\u6210\u529f\u5220\u9664\u3002<\/p>\n<p><strong>\u5728Mac\u4e0a\u5982\u4f55\u6e05\u9664Python\u53ca\u5176\u76f8\u5173\u8def\u5f84\uff1f<\/strong><br \/>\u5728Mac\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u5378\u8f7dPython\u3002\u4f7f\u7528<code>brew uninstall python<\/code>\u547d\u4ee4\uff08\u5982\u679c\u662f\u901a\u8fc7Homebrew\u5b89\u88c5\u7684\uff09\uff0c\u6216\u624b\u52a8\u5220\u9664Python\u7684\u5b89\u88c5\u76ee\u5f55\u3002\u63a5\u4e0b\u6765\uff0c\u786e\u4fdd\u5728<code>~\/.bash_profile<\/code>\u6216<code>~\/.zshrc<\/code>\u7b49\u914d\u7f6e\u6587\u4ef6\u4e2d\u79fb\u9664\u76f8\u5173\u7684\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u3002\u91cd\u542f\u7ec8\u7aef\u540e\uff0c\u8f93\u5165<code>python<\/code>\u6765\u786e\u8ba4\u662f\u5426\u5df2\u6210\u529f\u6e05\u9664\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u591a\u4e2aPython\u7248\u672c\u5171\u5b58\u65f6\u7684\u8def\u5f84\u5220\u9664\u95ee\u9898\uff1f<\/strong><br \/>\u5f53\u7cfb\u7edf\u4e2d\u5b89\u88c5\u4e86\u591a\u4e2aPython\u7248\u672c\u65f6\uff0c\u5220\u9664\u67d0\u4e2a\u7248\u672c\u7684\u8def\u5f84\u53ef\u80fd\u4f1a\u5f71\u54cd\u5176\u4ed6\u7248\u672c\u3002\u5efa\u8bae\u5728\u5378\u8f7d\u65f6\u68c0\u67e5\u5404\u4e2a\u7248\u672c\u7684\u5b89\u88c5\u76ee\u5f55\uff0c\u786e\u4fdd\u53ea\u5220\u9664\u60a8\u60f3\u8981\u5378\u8f7d\u7684\u7248\u672c\u3002\u4f7f\u7528\u865a\u62df\u73af\u5883\uff08\u5982venv\u6216conda\uff09\u6765\u7ba1\u7406\u4e0d\u540c\u7684Python\u7248\u672c\u53ef\u4ee5\u51cf\u5c11\u8def\u5f84\u51b2\u7a81\u7684\u53d1\u751f\u3002\u5728\u4fee\u6539\u73af\u5883\u53d8\u91cf\u65f6\uff0c\u52a1\u5fc5\u5c0f\u5fc3\uff0c\u4ee5\u514d\u5f71\u54cd\u5176\u4ed6\u9879\u76ee\u7684\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5f7b\u5e95\u5220\u9664Python\u8def\u5f84\uff0c\u9700\u8981\u4ece\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u3001Python\u5b89\u88c5\u76ee\u5f55\u548c\u76f8\u5173\u7684\u6ce8\u518c\u8868\u9879\u4e2d\u8fdb\u884c\u6e05\u7406\u3002\u8fd9\u4fdd\u8bc1\u4e86Pyt [&hellip;]","protected":false},"author":3,"featured_media":1017319,"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\/1017305"}],"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=1017305"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1017305\/revisions"}],"predecessor-version":[{"id":1017320,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1017305\/revisions\/1017320"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1017319"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1017305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1017305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1017305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}