{"id":985152,"date":"2024-12-27T07:34:17","date_gmt":"2024-12-26T23:34:17","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/985152.html"},"modified":"2024-12-27T07:34:19","modified_gmt":"2024-12-26T23:34:19","slug":"%e5%a6%82%e4%bd%95%e6%8a%8apython%e5%bd%bb%e5%ba%95%e5%88%a0%e9%99%a4","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/985152.html","title":{"rendered":"\u5982\u4f55\u628apython\u5f7b\u5e95\u5220\u9664"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24212444\/7f64df2a-e454-4cb9-b187-8be5e3ec4f03.webp\" alt=\"\u5982\u4f55\u628apython\u5f7b\u5e95\u5220\u9664\" \/><\/p>\n<p><p> <strong>\u8981\u5f7b\u5e95\u5220\u9664Python\uff0c\u4f60\u9700\u8981\u4ece\u8ba1\u7b97\u673a\u4e2d\u79fb\u9664\u6240\u6709\u4e0ePython\u76f8\u5173\u7684\u6587\u4ef6\u3001\u6587\u4ef6\u5939\u548c\u6ce8\u518c\u8868\u9879\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u5378\u8f7dPython\u89e3\u91ca\u5668\u3001\u5220\u9664Python\u76f8\u5173\u7684\u73af\u5883\u53d8\u91cf\u3001\u79fb\u9664Python\u7684\u5b89\u88c5\u76ee\u5f55\u548c\u6e05\u7406\u7cfb\u7edf\u6ce8\u518c\u8868\u3002\u9996\u5148\uff0c\u9700\u901a\u8fc7\u63a7\u5236\u9762\u677f\u5378\u8f7dPython\uff0c\u63a5\u7740\u5728\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u5220\u9664Python\u8def\u5f84\uff0c\u6700\u540e\u624b\u52a8\u5220\u9664\u6b8b\u7559\u6587\u4ef6\u5939\u548c\u6ce8\u518c\u8868\u952e\u503c\u3002<\/strong>\u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u8fd9\u4e9b\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5378\u8f7dPython\u89e3\u91ca\u5668<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u901a\u8fc7\u64cd\u4f5c\u7cfb\u7edf\u7684\u7a0b\u5e8f\u7ba1\u7406\u5de5\u5177\u5378\u8f7dPython\u89e3\u91ca\u5668\u3002\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u8fd9\u662f\u901a\u8fc7\u63a7\u5236\u9762\u677f\u6216\u8005\u7cfb\u7edf\u8bbe\u7f6e\u6765\u5b9e\u73b0\u7684\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Windows\u7cfb\u7edf<\/strong>\uff1a\u6253\u5f00\u201c\u63a7\u5236\u9762\u677f\u201d\uff0c\u9009\u62e9\u201c\u7a0b\u5e8f\u548c\u529f\u80fd\u201d\uff0c\u5728\u5217\u8868\u4e2d\u627e\u5230Python\uff0c\u53f3\u952e\u70b9\u51fb\u9009\u62e9\u201c\u5378\u8f7d\u201d\uff0c\u7136\u540e\u6309\u7167\u63d0\u793a\u5b8c\u6210\u5378\u8f7d\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>MacOS\u7cfb\u7edf<\/strong>\uff1aPython\u901a\u5e38\u9884\u88c5\u5728MacOS\u7cfb\u7edf\u4e2d\uff0c\u65e0\u6cd5\u901a\u8fc7\u7b80\u5355\u7684\u62d6\u653e\u64cd\u4f5c\u5378\u8f7d\u3002\u4f60\u53ef\u4ee5\u6253\u5f00\u7ec8\u7aef\uff08Terminal\uff09\uff0c\u7136\u540e\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5378\u8f7dPython\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo rm -rf \/Library\/Frameworks\/Python.framework\/Versions\/X.X<\/p>\n<p>sudo rm -rf &quot;\/Applications\/Python X.X&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d<code>X.X<\/code>\u4ee3\u8868\u5177\u4f53\u7684Python\u7248\u672c\u53f7\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Linux\u7cfb\u7edf<\/strong>\uff1a\u5728Linux\u4e0a\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u8fdb\u884c\u5378\u8f7d\u3002\u4f8b\u5982\uff0c\u5728Ubuntu\u4e0a\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt-get remove pythonX.X<\/p>\n<p>sudo apt-get autoremove<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u540c\u6837\uff0c<code>X.X<\/code>\u4ee3\u8868\u4f60\u8981\u5378\u8f7d\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u5220\u9664Python\u76f8\u5173\u7684\u73af\u5883\u53d8\u91cf<\/p>\n<\/p>\n<p><p>\u5378\u8f7dPython\u89e3\u91ca\u5668\u540e\uff0c\u53ef\u80fd\u8fd8\u4f1a\u6709\u73af\u5883\u53d8\u91cf\u6307\u5411\u5df2\u5220\u9664\u7684Python\u76ee\u5f55\u3002\u8fd9\u4e9b\u73af\u5883\u53d8\u91cf\u9700\u8981\u624b\u52a8\u5220\u9664\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Windows\u7cfb\u7edf<\/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\u3002\u5728\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u3002\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u6216\u201c\u7528\u6237\u53d8\u91cf\u201d\u4e2d\uff0c\u627e\u5230\u5e76\u5220\u9664\u4e0ePython\u76f8\u5173\u7684\u8def\u5f84\u53d8\u91cf\uff0c\u5982<code>PYTHONPATH<\/code>\u6216\u5305\u542bPython\u5b89\u88c5\u8def\u5f84\u7684<code>Path<\/code>\u6761\u76ee\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>MacOS\u548cLinux\u7cfb\u7edf<\/strong>\uff1a\u6253\u5f00\u7ec8\u7aef\uff0c\u7f16\u8f91<code>.bash_profile<\/code>\u3001<code>.bashrc<\/code>\u6216<code>.zshrc<\/code>\u6587\u4ef6\uff0c\u5220\u9664\u5176\u4e2d\u5305\u542bPython\u8def\u5f84\u7684\u884c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PATH=&quot;\/Library\/Frameworks\/Python.framework\/Versions\/X.X\/bin:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u6587\u4ef6\u5e76\u8fd0\u884c<code>source ~\/.bash_profile<\/code>\uff08\u6216\u76f8\u5e94\u6587\u4ef6\uff09\u4ee5\u5e94\u7528\u66f4\u6539\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u79fb\u9664Python\u7684\u5b89\u88c5\u76ee\u5f55<\/p>\n<\/p>\n<p><p>\u5728\u5378\u8f7d\u7a0b\u5e8f\u4e4b\u540e\uff0cPython\u7684\u5b89\u88c5\u76ee\u5f55\u53ef\u80fd\u4ecd\u7136\u5b58\u5728\u3002\u4f60\u9700\u8981\u624b\u52a8\u5220\u9664\u8fd9\u4e9b\u76ee\u5f55\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Windows\u7cfb\u7edf<\/strong>\uff1a\u901a\u5e38\u60c5\u51b5\u4e0b\uff0cPython\u7684\u5b89\u88c5\u76ee\u5f55\u4f4d\u4e8e<code>C:\\PythonX<\/code>\u6216<code>C:\\Users\\&lt;YourUsername&gt;\\AppData\\Local\\Programs\\Python<\/code>\u3002\u624b\u52a8\u6d4f\u89c8\u5230\u8be5\u76ee\u5f55\u5e76\u5220\u9664\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>MacOS\u7cfb\u7edf<\/strong>\uff1a\u5982\u679c\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\u5220\u9664\u4e86Python\uff0c\u901a\u5e38\u4e0d\u9700\u8981\u989d\u5916\u5220\u9664\u76ee\u5f55\u3002\u5982\u679c\u6709\u81ea\u5b9a\u4e49\u5b89\u88c5\uff0c\u53ef\u4ee5\u68c0\u67e5\u5e76\u5220\u9664\u8fd9\u4e9b\u76ee\u5f55\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Linux\u7cfb\u7edf<\/strong>\uff1a\u4e00\u822c\u60c5\u51b5\u4e0b\uff0cPython\u81ea\u5e26\u7684\u5305\u7ba1\u7406\u5de5\u5177\u4f1a\u81ea\u52a8\u6e05\u7406\u5b89\u88c5\u76ee\u5f55\u3002\u4f46\u5982\u679c\u6709\u81ea\u5b9a\u4e49\u5b89\u88c5\uff0c\u68c0\u67e5\u5e76\u5220\u9664\u76f8\u5173\u76ee\u5f55\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u6e05\u7406\u7cfb\u7edf\u6ce8\u518c\u8868\uff08\u4ec5\u9002\u7528\u4e8eWindows\uff09<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8eWindows\u7528\u6237\uff0cPython\u7684\u76f8\u5173\u4fe1\u606f\u53ef\u80fd\u4f1a\u5728\u6ce8\u518c\u8868\u4e2d\u6b8b\u7559\u3002\u53ef\u4ee5\u4f7f\u7528\u6ce8\u518c\u8868\u7f16\u8f91\u5668\u6e05\u7406\u8fd9\u4e9b\u6570\u636e\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u6ce8\u518c\u8868\u7f16\u8f91\u5668<\/strong>\uff1a\u6309<code>Win + R<\/code>\uff0c\u8f93\u5165<code>regedit<\/code>\u5e76\u6309Enter\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u627ePython\u76f8\u5173\u9879<\/strong>\uff1a\u5728\u6ce8\u518c\u8868\u7f16\u8f91\u5668\u4e2d\uff0c\u4f7f\u7528\u201c\u67e5\u627e\u201d\u529f\u80fd\uff08Ctrl + F\uff09\uff0c\u8f93\u5165\u201cPython\u201d\u8fdb\u884c\u641c\u7d22\u3002\u627e\u5230\u4e0ePython\u76f8\u5173\u7684\u9879\u65f6\uff0c\u5c0f\u5fc3\u5730\u5220\u9664\u8fd9\u4e9b\u9879\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a\u7f16\u8f91\u6ce8\u518c\u8868\u6709\u98ce\u9669\uff0c\u8bf7\u786e\u4fdd\u5907\u4efd\u6ce8\u518c\u8868\u6216\u7cfb\u7edf\uff0c\u4ee5\u9632\u6b62\u8bef\u64cd\u4f5c\u5bfc\u81f4\u7cfb\u7edf\u95ee\u9898\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5220\u9664\u6b8b\u7559\u6587\u4ef6\u548c\u914d\u7f6e<\/p>\n<\/p>\n<p><p>Python\u53ef\u80fd\u5728\u4f60\u7684\u7528\u6237\u76ee\u5f55\u4e0b\u7559\u4e0b\u914d\u7f6e\u6587\u4ef6\u548c\u5176\u4ed6\u7f13\u5b58\u6570\u636e\u3002\u4ee5\u4e0b\u6b65\u9aa4\u5e2e\u52a9\u4f60\u5220\u9664\u8fd9\u4e9b\u6b8b\u7559\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Windows\u7cfb\u7edf<\/strong>\uff1a\u68c0\u67e5<code>C:\\Users\\&lt;YourUsername&gt;<\/code>\u76ee\u5f55\u4e2d\u7684<code>.python_history<\/code>\u6587\u4ef6\u6216<code>.ipython<\/code>\u76ee\u5f55\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>MacOS\u548cLinux\u7cfb\u7edf<\/strong>\uff1a\u5728\u7528\u6237\u76ee\u5f55\u4e0b\uff0c\u67e5\u627e\u5e76\u5220\u9664<code>.python_history<\/code>\u3001<code>.ipython<\/code>\u4ee5\u53ca\u5176\u4ed6\u4e0ePython\u76f8\u5173\u7684\u9690\u85cf\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u5f7b\u5e95\u4ece\u7cfb\u7edf\u4e2d\u5220\u9664Python\u53ca\u5176\u76f8\u5173\u6587\u4ef6\u3002\u8bf7\u6ce8\u610f\uff0c\u8fd9\u4e9b\u64cd\u4f5c\u53ef\u80fd\u4f1a\u5f71\u54cd\u4f9d\u8d56Python\u7684\u5176\u4ed6\u7a0b\u5e8f\u6216\u811a\u672c\u8fd0\u884c\uff0c\u5728\u5220\u9664\u524d\u8bf7\u786e\u8ba4\u4e0d\u518d\u9700\u8981Python\u73af\u5883\u6216\u5df2\u505a\u597d\u5907\u4efd\u51c6\u5907\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u786e\u8ba4\u6211\u7684\u7cfb\u7edf\u4e2d\u662f\u5426\u5df2\u7ecf\u5b89\u88c5\u4e86Python\uff1f<\/strong><br \/>\u8981\u786e\u8ba4\u7cfb\u7edf\u4e2d\u662f\u5426\u5b89\u88c5\u4e86Python\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\u5b89\u88c5\u4e86Python\uff0c\u4f1a\u663e\u793a\u76f8\u5e94\u7684\u7248\u672c\u53f7\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u7cfb\u7edf\u4f1a\u63d0\u793a\u627e\u4e0d\u5230\u8be5\u547d\u4ee4\u3002<\/p>\n<p><strong>\u5728Windows\u7cfb\u7edf\u4e2d\u5982\u4f55\u5f7b\u5e95\u5378\u8f7dPython\uff1f<\/strong><br \/>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u5f7b\u5e95\u5378\u8f7dPython\u53ef\u4ee5\u901a\u8fc7\u201c\u63a7\u5236\u9762\u677f\u201d\u4e2d\u7684\u201c\u7a0b\u5e8f\u548c\u529f\u80fd\u201d\u6765\u5b8c\u6210\u3002\u627e\u5230Python\u7684\u5b89\u88c5\u8bb0\u5f55\uff0c\u53f3\u952e\u9009\u62e9\u5378\u8f7d\u3002\u4e3a\u4e86\u786e\u4fdd\u5b8c\u5168\u5220\u9664\uff0c\u8fd8\u53ef\u4ee5\u624b\u52a8\u5220\u9664Python\u7684\u5b89\u88c5\u76ee\u5f55\uff0c\u901a\u5e38\u4f4d\u4e8e<code>C:\\PythonXX<\/code>\uff08XX\u4e3a\u7248\u672c\u53f7\uff09\uff0c\u4ee5\u53ca\u5220\u9664\u73af\u5883\u53d8\u91cf\u4e2d\u7684Python\u76f8\u5173\u8def\u5f84\u3002<\/p>\n<p><strong>\u5728Mac\u6216Linux\u7cfb\u7edf\u4e2d\u5982\u4f55\u5220\u9664Python\uff1f<\/strong><br \/>\u5728Mac\u6216Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u8fdb\u884c\u5378\u8f7d\u3002\u4f8b\u5982\uff0c\u5728\u4f7f\u7528Homebrew\u7684Mac\u4e0a\uff0c\u53ef\u4ee5\u8f93\u5165<code>brew uninstall python<\/code>\u547d\u4ee4\u3002\u5bf9\u4e8eLinux\u7528\u6237\uff0c\u53ef\u4ee5\u4f7f\u7528\u76f8\u5e94\u7684\u5305\u7ba1\u7406\u547d\u4ee4\uff0c\u5982<code>sudo apt remove python3<\/code>\u3002\u5378\u8f7d\u5b8c\u6210\u540e\uff0c\u5efa\u8bae\u68c0\u67e5\u7cfb\u7edf\u7684PATH\u73af\u5883\u53d8\u91cf\uff0c\u786e\u4fdd\u6ca1\u6709\u6b8b\u7559\u7684Python\u8def\u5f84\u3002<\/p>\n<p><strong>\u5728\u5220\u9664Python\u540e\uff0c\u6211\u5982\u4f55\u786e\u4fdd\u76f8\u5173\u7684\u5e93\u548c\u4f9d\u8d56\u4e5f\u88ab\u5220\u9664\uff1f<\/strong><br \/>\u5728\u5220\u9664Python\u4e4b\u524d\uff0c\u4e86\u89e3\u662f\u5426\u4f7f\u7528\u4e86\u865a\u62df\u73af\u5883\u7ba1\u7406\u5de5\u5177\uff08\u5982venv\u6216virtualenv\uff09\u53ef\u4ee5\u5e2e\u52a9\u7ba1\u7406\u4f9d\u8d56\u3002\u5728\u5378\u8f7dPython\u540e\uff0c\u624b\u52a8\u5220\u9664\u76f8\u5173\u7684\u865a\u62df\u73af\u5883\u6587\u4ef6\u5939\u662f\u786e\u4fdd\u5b8c\u5168\u6e05\u9664\u7684\u597d\u65b9\u6cd5\u3002\u540c\u65f6\uff0c\u68c0\u67e5\u7cfb\u7edf\u7684\u5305\u7ba1\u7406\u5de5\u5177\u662f\u5426\u8fd8\u5b58\u7559\u6709Python\u76f8\u5173\u7684\u5e93\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5f7b\u5e95\u5220\u9664Python\uff0c\u4f60\u9700\u8981\u4ece\u8ba1\u7b97\u673a\u4e2d\u79fb\u9664\u6240\u6709\u4e0ePython\u76f8\u5173\u7684\u6587\u4ef6\u3001\u6587\u4ef6\u5939\u548c\u6ce8\u518c\u8868\u9879\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u5378\u8f7d [&hellip;]","protected":false},"author":3,"featured_media":985159,"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\/985152"}],"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=985152"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985152\/revisions"}],"predecessor-version":[{"id":985160,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985152\/revisions\/985160"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/985159"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=985152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=985152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=985152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}