{"id":928518,"date":"2024-12-26T16:36:49","date_gmt":"2024-12-26T08:36:49","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/928518.html"},"modified":"2024-12-26T16:36:51","modified_gmt":"2024-12-26T08:36:51","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/928518.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u5b89\u88c5"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25064146\/1e22df97-9053-45ef-abf5-6c19d709d7ae.webp\" alt=\"python\u4e2d\u5982\u4f55\u5b89\u88c5\" \/><\/p>\n<p><p> \u5b89\u88c5Python\u662f\u4e00\u9879\u91cd\u8981\u7684\u4efb\u52a1\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u90a3\u4e9b\u5e0c\u671b\u5f00\u59cb\u7f16\u7a0b\u6216\u5728\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884cPython\u7a0b\u5e8f\u7684\u4eba\u6765\u8bf4\u3002<strong>\u5728Python\u4e2d\u5b89\u88c5\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u8fdb\u884c\uff0c\u5305\u62ec\u4f7f\u7528Python\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u3001\u901a\u8fc7\u5305\u7ba1\u7406\u5668\uff08\u5982Homebrew\u3001apt-get\u7b49\uff09\u3001\u4f7f\u7528Anaconda\u3001\u901a\u8fc7Docker\u7b49\u65b9\u6cd5<\/strong>\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u70b9\u548c\u7f3a\u70b9\uff0c\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u5e2e\u52a9\u4f60\u9009\u62e9\u9002\u5408\u4f60\u7684\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Python\u5b98\u65b9\u7f51\u7ad9\u5b89\u88c5<\/h3>\n<\/p>\n<p><h4>1. \u4e0b\u8f7d\u5e76\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>Python\u7684\u5b98\u65b9\u7f51\u7ad9\u63d0\u4f9b\u4e86\u6700\u76f4\u63a5\u7684\u4e0b\u8f7d\u548c\u5b89\u88c5\u65b9\u5f0f\u3002\u4f60\u53ef\u4ee5\u8bbf\u95ee <a href=\"https:\/\/www.python.org\/\">Python\u5b98\u65b9\u7f51\u7ad9<\/a> \u4e0b\u8f7d\u9002\u5408\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>Windows\u7528\u6237\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u8bbf\u95eePython\u5b98\u7f51\u5e76\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684Python\u5b89\u88c5\u6587\u4ef6\uff08\u901a\u5e38\u662f\u4e00\u4e2a.exe\u6587\u4ef6\uff09\u3002<\/li>\n<li>\u8fd0\u884c\u4e0b\u8f7d\u7684\u5b89\u88c5\u7a0b\u5e8f\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u8fd9\u5c06\u4f7f\u4f60\u80fd\u591f\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u76f4\u63a5\u4f7f\u7528<code>python<\/code>\u547d\u4ee4\u3002<\/li>\n<li>\u6309\u7167\u5b89\u88c5\u5411\u5bfc\u5b8c\u6210\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Mac\u7528\u6237\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u540c\u6837\u8bbf\u95eePython\u5b98\u7f51\uff0c\u4e0b\u8f7d\u9002\u5408macOS\u7684\u5b89\u88c5\u6587\u4ef6\uff08\u901a\u5e38\u662f\u4e00\u4e2a.pkg\u6587\u4ef6\uff09\u3002<\/li>\n<li>\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f\uff0c\u6309\u7167\u6307\u793a\u5b8c\u6210\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Linux\u7528\u6237\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5927\u591a\u6570Linux\u53d1\u884c\u7248\u5df2\u7ecf\u9884\u88c5\u4e86Python\u3002\u5982\u679c\u6ca1\u6709\uff0c\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\uff08\u4f8b\u5982apt-get\uff09\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><h4>2. \u9a8c\u8bc1\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177\uff08Windows\u7684cmd\u3001Mac\u7684Terminal\u6216Linux\u7684\u7ec8\u7aef\uff09\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u663e\u793a\u4e86Python\u7684\u7248\u672c\u53f7\uff0c\u5219\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5b89\u88c5<\/h3>\n<\/p>\n<p><h4>1. Homebrew\uff08Mac\uff09<\/h4>\n<\/p>\n<p><p>Homebrew\u662fMac\u4e0a\u975e\u5e38\u6d41\u884c\u7684\u5305\u7ba1\u7406\u5668\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew install python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Homebrew\u4f1a\u81ea\u52a8\u4e0b\u8f7d\u5e76\u5b89\u88c5Python\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u4f60\u7684\u7cfb\u7edf\u8def\u5f84\u4e2d\u3002<\/p>\n<\/p>\n<p><h4>2. apt-get\uff08Linux\uff09<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4f7f\u7528Debian\u6216Ubuntu\u7684\u7528\u6237\uff0c\u53ef\u4ee5\u4f7f\u7528apt-get\u6765\u5b89\u88c5Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt-get update<\/p>\n<p>sudo apt-get install python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>apt-get\u4f1a\u4ece\u8f6f\u4ef6\u4ed3\u5e93\u4e2d\u4e0b\u8f7d\u5e76\u5b89\u88c5Python\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528Anaconda\u5b89\u88c5<\/h3>\n<\/p>\n<p><p>Anaconda\u662f\u4e00\u4e2a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\u7684Python\u53d1\u884c\u7248\uff0c\u5185\u7f6e\u4e86\u8bb8\u591a\u5e38\u7528\u7684\u5305\u548c\u5de5\u5177\u3002\u9002\u5408\u9700\u8981\u5927\u91cfPython\u5e93\u7684\u7528\u6237\u3002<\/p>\n<\/p>\n<p><h4>1. \u4e0b\u8f7d\u5e76\u5b89\u88c5<\/h4>\n<\/p>\n<ul>\n<li>\u8bbf\u95ee <a href=\"https:\/\/www.anaconda.com\/\">Anaconda\u5b98\u65b9\u7f51\u7ad9<\/a> \u4e0b\u8f7d\u9002\u5408\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684Anaconda\u5b89\u88c5\u5305\u3002<\/li>\n<li>\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f\uff0c\u6309\u7167\u6307\u793a\u5b8c\u6210\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<p><h4>2. \u9a8c\u8bc1\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5728\u547d\u4ee4\u884c\u5de5\u5177\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u9a8c\u8bc1\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u663e\u793a\u4e86Conda\u7684\u7248\u672c\u53f7\uff0c\u5219\u8bf4\u660eAnaconda\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528Docker\u5b89\u88c5<\/h3>\n<\/p>\n<p><p>Docker\u662f\u4e00\u79cd\u5bb9\u5668\u5316\u6280\u672f\uff0c\u53ef\u4ee5\u7528\u6765\u5feb\u901f\u90e8\u7f72\u548c\u8fd0\u884cPython\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5Docker<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5728\u4f60\u7684\u673a\u5668\u4e0a\u5b89\u88c5Docker\u3002\u53ef\u4ee5\u8bbf\u95ee <a href=\"https:\/\/www.docker.com\/\">Docker\u5b98\u65b9\u7f51\u7ad9<\/a> \u4e0b\u8f7d\u5e76\u5b89\u88c5Docker\u3002<\/p>\n<\/p>\n<p><h4>2. \u8fd0\u884cPython\u5bb9\u5668<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5Docker\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884cPython\u5bb9\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">docker run -it python:latest<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4e0b\u8f7d\u6700\u65b0\u7684Python\u955c\u50cf\u5e76\u5728\u5bb9\u5668\u4e2d\u8fd0\u884cPython\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u9009\u62e9\u9002\u5408\u4f60\u7684\u5b89\u88c5\u65b9\u5f0f<\/h3>\n<\/p>\n<ul>\n<li><strong>\u521d\u5b66\u8005<\/strong>\uff1a\u5efa\u8bae\u4f7f\u7528Python\u5b98\u65b9\u7f51\u7ad9\u76f4\u63a5\u5b89\u88c5\uff0c\u7b80\u5355\u6613\u884c\u3002<\/li>\n<li><strong>Mac\u7528\u6237<\/strong>\uff1aHomebrew\u662f\u4e00\u79cd\u65b9\u4fbf\u7684\u9009\u62e9\uff0c\u6613\u4e8e\u7ba1\u7406\u548c\u66f4\u65b0\u3002<\/li>\n<li><strong>Linux\u7528\u6237<\/strong>\uff1aapt-get\u662f\u4e00\u79cd\u4f20\u7edf\u4e14\u6709\u6548\u7684\u5b89\u88c5\u65b9\u5f0f\u3002<\/li>\n<li><strong>\u6570\u636e\u79d1\u5b66\u5bb6\u6216\u5206\u6790\u5e08<\/strong>\uff1aAnaconda\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u79d1\u5b66\u8ba1\u7b97\u5de5\u5177\uff0c\u9002\u5408\u9700\u8981\u5927\u91cfPython\u5e93\u7684\u7528\u6237\u3002<\/li>\n<li><strong>\u5f00\u53d1\u73af\u5883\u9694\u79bb<\/strong>\uff1aDocker\u53ef\u4ee5\u5728\u4e0d\u5f71\u54cd\u4e3b\u673a\u73af\u5883\u7684\u60c5\u51b5\u4e0b\u5feb\u901f\u90e8\u7f72Python\u73af\u5883\u3002<\/li>\n<\/ul>\n<p><h3>\u516d\u3001\u5e38\u89c1\u95ee\u9898\u89e3\u7b54<\/h3>\n<\/p>\n<p><h4>1. \u5b89\u88c5\u65f6\u9047\u5230\u6743\u9650\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u5728Windows\u4e0a\uff0c\u786e\u4fdd\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f\u3002\u5728Linux\u548cMac\u4e0a\uff0c\u4f7f\u7528<code>sudo<\/code>\u547d\u4ee4\u63d0\u5347\u6743\u9650\u3002<\/p>\n<\/p>\n<p><h4>2. \u73af\u5883\u53d8\u91cf\u914d\u7f6e<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u5728\u547d\u4ee4\u884c\u4e2d\u65e0\u6cd5\u8bc6\u522b<code>python<\/code>\u547d\u4ee4\uff0c\u53ef\u80fd\u662f\u56e0\u4e3aPython\u672a\u6b63\u786e\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u53ef\u4ee5\u624b\u52a8\u5c06Python\u7684\u5b89\u88c5\u8def\u5f84\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/p>\n<\/p>\n<p><h4>3. \u5b89\u88c5\u591a\u4e2aPython\u7248\u672c<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177\u5982<code>pyenv<\/code>\u6765\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\uff0c\u65b9\u4fbf\u5728\u4e0d\u540c\u9879\u76ee\u95f4\u5207\u6362\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3\uff0c\u5b89\u88c5Python\u7684\u65b9\u6cd5\u591a\u79cd\u591a\u6837\uff0c\u9009\u62e9\u5408\u9002\u7684\u5b89\u88c5\u65b9\u6cd5\u53ef\u4ee5\u5927\u5927\u63d0\u5347\u5f00\u53d1\u6548\u7387\u3002\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u4f60\u80fd\u5feb\u901f\u3001\u987a\u5229\u5730\u5b8c\u6210Python\u7684\u5b89\u88c5\uff0c\u5e76\u5f00\u59cb\u4f60\u7684\u7f16\u7a0b\u65c5\u7a0b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\uff0c\u5b89\u88c5\u8f6f\u4ef6\u5305\u7684\u6700\u4f73\u65b9\u5f0f\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5b89\u88c5\u8f6f\u4ef6\u5305\u901a\u5e38\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177pip\u3002\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165<code>pip install package_name<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684\u8f6f\u4ef6\u5305\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u4f7f\u7528<code>pip<\/code>\u5bf9\u5e94\u4e8e\u4f60\u60f3\u8981\u5b89\u88c5\u5305\u7684Python\u7248\u672c\u3002\u5bf9\u4e8e\u865a\u62df\u73af\u5883\uff0c\u9996\u5148\u9700\u8981\u6fc0\u6d3b\u73af\u5883\u540e\u518d\u6267\u884c\u5b89\u88c5\u547d\u4ee4\uff0c\u4ee5\u907f\u514d\u4e0e\u7cfb\u7edf\u7ea7\u522b\u7684\u5305\u51b2\u7a81\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5728Windows\u4e0a\uff0c\u53ef\u4ee5\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u53ef\u6267\u884c\u5b89\u88c5\u6587\u4ef6\uff0c\u8fd0\u884c\u540e\u6309\u7167\u63d0\u793a\u5b8c\u6210\u5b89\u88c5\u3002\u5728macOS\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528Homebrew\u6216\u76f4\u63a5\u4e0b\u8f7d.dmg\u6587\u4ef6\u8fdb\u884c\u5b89\u88c5\u3002Linux\u7528\u6237\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u53d1\u884c\u7248\u7684\u5305\u7ba1\u7406\u5668\uff08\u5982apt\u6216yum\uff09\u8fdb\u884c\u5b89\u88c5\uff0c\u547d\u4ee4\u5982<code>sudo apt install python3<\/code>\u3002<\/p>\n<p><strong>\u5982\u679c\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u9519\u8bef\uff0c\u6211\u8be5\u5982\u4f55\u89e3\u51b3\uff1f<\/strong><br \/>\u5b89\u88c5Python\u6216\u8f6f\u4ef6\u5305\u65f6\uff0c\u5982\u679c\u9047\u5230\u9519\u8bef\uff0c\u68c0\u67e5\u9519\u8bef\u4fe1\u606f\u901a\u5e38\u662f\u89e3\u51b3\u95ee\u9898\u7684\u7b2c\u4e00\u6b65\u3002\u5e38\u89c1\u95ee\u9898\u5305\u62ec\u7f51\u7edc\u8fde\u63a5\u95ee\u9898\u3001\u6743\u9650\u4e0d\u8db3\u6216\u7248\u672c\u517c\u5bb9\u6027\u3002\u53ef\u4ee5\u5c1d\u8bd5\u66f4\u65b0pip\uff0c\u4f7f\u7528\u547d\u4ee4<code>pip install --upgrade pip<\/code>\uff0c\u6216\u8005\u67e5\u770bPython\u7684\u5b98\u65b9\u6587\u6863\u548c\u793e\u533a\u8bba\u575b\uff0c\u5bfb\u627e\u5177\u4f53\u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5b89\u88c5Python\u662f\u4e00\u9879\u91cd\u8981\u7684\u4efb\u52a1\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u90a3\u4e9b\u5e0c\u671b\u5f00\u59cb\u7f16\u7a0b\u6216\u5728\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884cPython\u7a0b\u5e8f\u7684\u4eba\u6765\u8bf4\u3002\u5728Pyt [&hellip;]","protected":false},"author":3,"featured_media":928523,"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\/928518"}],"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=928518"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/928518\/revisions"}],"predecessor-version":[{"id":928524,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/928518\/revisions\/928524"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/928523"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=928518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=928518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=928518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}