{"id":1091963,"date":"2025-01-08T14:16:36","date_gmt":"2025-01-08T06:16:36","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1091963.html"},"modified":"2025-01-08T14:16:39","modified_gmt":"2025-01-08T06:16:39","slug":"%e5%a6%82%e4%bd%95%e5%b0%86python%e9%99%8d%e4%bd%8e%e7%89%88%e6%9c%ac-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1091963.html","title":{"rendered":"\u5982\u4f55\u5c06python\u964d\u4f4e\u7248\u672c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24205219\/fec2b1b5-4839-4968-8287-73ce566a447c.webp\" alt=\"\u5982\u4f55\u5c06python\u964d\u4f4e\u7248\u672c\" \/><\/p>\n<p><p> <strong>\u8981\u5c06Python\u964d\u7ea7\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528pyenv\u3001\u901a\u8fc7Anaconda\u7ba1\u7406\u3001\u5378\u8f7d\u5f53\u524d\u7248\u672c\u5e76\u91cd\u65b0\u5b89\u88c5\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u3002<\/strong> \u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u8bf4\u660e\u5982\u4f55\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\u6765\u964d\u7ea7Python\u7248\u672c\uff0c\u5e76\u63a2\u8ba8\u6bcf\u79cd\u65b9\u6cd5\u7684\u4f18\u7f3a\u70b9\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528pyenv<\/p>\n<\/p>\n<p><p><strong>pyenv<\/strong> \u662f\u4e00\u4e2a\u7528\u4e8e\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u7684\u5de5\u5177\u3002\u5b83\u5141\u8bb8\u4f60\u5b89\u88c5\u548c\u5207\u6362\u4e0d\u540c\u7684Python\u7248\u672c\uff0c\u975e\u5e38\u9002\u5408\u9700\u8981\u5728\u591a\u4e2a\u9879\u76ee\u4e2d\u4f7f\u7528\u4e0d\u540cPython\u7248\u672c\u7684\u5f00\u53d1\u8005\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5pyenv<\/strong>\uff1a\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5pyenv\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5728macOS\u548cLinux\u4e0a\u5b89\u88c5\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">curl https:\/\/pyenv.run | bash<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6309\u7167\u5b89\u88c5\u811a\u672c\u7684\u63d0\u793a\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\u5230\u4f60\u7684shell\u914d\u7f6e\u6587\u4ef6\uff08\u4f8b\u5982\uff0c<code>~\/.bashrc<\/code>\u6216<code>~\/.zshrc<\/code>\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PATH=&quot;$HOME\/.pyenv\/bin:$PATH&quot;<\/p>\n<p>eval &quot;$(pyenv init --path)&quot;<\/p>\n<p>eval &quot;$(pyenv virtualenv-init -)&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5b89\u88c5\u6240\u9700\u7684Python\u7248\u672c<\/strong>\uff1a\u4f7f\u7528pyenv\u5b89\u88c5\u4f60\u60f3\u8981\u964d\u7ea7\u5230\u7684Python\u7248\u672c\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u60f3\u5b89\u88c5Python 3.7.9\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">pyenv install 3.7.9<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u8bbe\u7f6e\u5168\u5c40\u6216\u672c\u5730Python\u7248\u672c<\/strong>\uff1a\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pyenv global<\/code>\u547d\u4ee4\u8bbe\u7f6e\u5168\u5c40Python\u7248\u672c\uff0c\u6216\u8005\u4f7f\u7528<code>pyenv local<\/code>\u547d\u4ee4\u4e3a\u5f53\u524d\u76ee\u5f55\u8bbe\u7f6e\u672c\u5730Python\u7248\u672c\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">pyenv global 3.7.9<\/p>\n<h2><strong>\u6216\u8005<\/strong><\/h2>\n<p>pyenv local 3.7.9<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u4f60\u5c31\u6210\u529f\u5730\u5c06Python\u964d\u7ea7\u5230\u6307\u5b9a\u7248\u672c\u4e86\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528Anaconda\u7ba1\u7406<\/p>\n<\/p>\n<p><p><strong>Anaconda<\/strong> \u662f\u4e00\u4e2a\u7528\u4e8e\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u7684\u5305\u7ba1\u7406\u5668\u548c\u73af\u5883\u7ba1\u7406\u5668\u3002\u5b83\u53ef\u4ee5\u5e2e\u52a9\u4f60\u8f7b\u677e\u5730\u7ba1\u7406\u548c\u5207\u6362\u4e0d\u540c\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Anaconda<\/strong>\uff1a\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5Anaconda\uff0c\u53ef\u4ee5\u4eceAnaconda\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u65b0\u7684\u73af\u5883<\/strong>\uff1a\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Anaconda\u73af\u5883\uff0c\u5e76\u6307\u5b9a\u4f60\u60f3\u8981\u7684Python\u7248\u672c\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u60f3\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>myenv<\/code>\u7684\u73af\u5883\uff0c\u5e76\u4f7f\u7528Python 3.7.9\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">conda create --name myenv python=3.7.9<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6fc0\u6d3b\u73af\u5883<\/strong>\uff1a\u521b\u5efa\u73af\u5883\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6fc0\u6d3b\u73af\u5883\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">conda activate myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u73af\u5883\u540e\uff0c\u6240\u6709\u5728\u8be5\u73af\u5883\u4e2d\u8fd0\u884c\u7684Python\u811a\u672c\u90fd\u4f1a\u4f7f\u7528\u6307\u5b9a\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u5378\u8f7d\u5f53\u524d\u7248\u672c\u5e76\u91cd\u65b0\u5b89\u88c5<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u4e0d\u60f3\u4f7f\u7528pyenv\u6216Anaconda\uff0c\u53ef\u4ee5\u9009\u62e9\u624b\u52a8\u5378\u8f7d\u5f53\u524d\u7248\u672c\u7684Python\u5e76\u91cd\u65b0\u5b89\u88c5\u6240\u9700\u7248\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5378\u8f7d\u5f53\u524d\u7248\u672c<\/strong>\uff1a\u9996\u5148\uff0c\u9700\u8981\u5378\u8f7d\u5f53\u524d\u7248\u672c\u7684Python\u3002\u5728Windows\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u201c\u63a7\u5236\u9762\u677f\u201d\u4e2d\u7684\u201c\u7a0b\u5e8f\u548c\u529f\u80fd\u201d\u6765\u5378\u8f7dPython\u3002\u5728macOS\u548cLinux\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5378\u8f7dPython\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">sudo apt-get remove python3<\/p>\n<h2><strong>\u6216\u8005<\/strong><\/h2>\n<p>brew uninstall python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6240\u9700\u7248\u672c<\/strong>\uff1a\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u4f60\u60f3\u8981\u7684Python\u7248\u672c\uff0c\u5e76\u6309\u7167\u5b89\u88c5\u5411\u5bfc\u8fdb\u884c\u5b89\u88c5\u3002<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p><strong>\u865a\u62df\u73af\u5883<\/strong> \u662f\u4e00\u79cd\u5728\u540c\u4e00\u53f0\u8ba1\u7b97\u673a\u4e0a\u4e3a\u4e0d\u540c\u9879\u76ee\u521b\u5efa\u9694\u79bb\u7684Python\u73af\u5883\u7684\u65b9\u6cd5\u3002\u865a\u62df\u73af\u5883\u5141\u8bb8\u4f60\u5728\u4e0d\u5f71\u54cd\u5168\u5c40Python\u5b89\u88c5\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u4e0d\u540c\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5virtualenv<\/strong>\uff1a\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5<code>virtualenv<\/code>\u5de5\u5177\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">pip install virtualenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u4f7f\u7528<code>virtualenv<\/code>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\uff0c\u5e76\u6307\u5b9a\u4f60\u60f3\u8981\u7684Python\u7248\u672c\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u60f3\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>myenv<\/code>\u7684\u865a\u62df\u73af\u5883\uff0c\u5e76\u4f7f\u7528Python 3.7.9\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">virtualenv -p \/usr\/bin\/python3.7 myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong>\uff1a\u521b\u5efa\u865a\u62df\u73af\u5883\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6fc0\u6d3b\u73af\u5883\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u73af\u5883\u540e\uff0c\u6240\u6709\u5728\u8be5\u73af\u5883\u4e2d\u8fd0\u884c\u7684Python\u811a\u672c\u90fd\u4f1a\u4f7f\u7528\u6307\u5b9a\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06Python\u964d\u7ea7\u5230\u6240\u9700\u7248\u672c\u3002<strong>\u4f7f\u7528pyenv\u548cAnaconda\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u662f\u6700\u4e3a\u63a8\u8350\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u4eec\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u7248\u672c\u5207\u6362\u548c\u73af\u5883\u7ba1\u7406\u529f\u80fd\u3002<\/strong> \u800c\u624b\u52a8\u5378\u8f7d\u548c\u91cd\u65b0\u5b89\u88c5Python\u7248\u672c\u9002\u7528\u4e8e\u4e0d\u60f3\u4f9d\u8d56\u5916\u90e8\u5de5\u5177\u7684\u7528\u6237\u3002\u865a\u62df\u73af\u5883\u5219\u662f\u4e00\u4e2a\u975e\u5e38\u5b9e\u7528\u7684\u5de5\u5177\uff0c\u7279\u522b\u9002\u5408\u5728\u540c\u4e00\u53f0\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u591a\u4e2a\u9879\u76ee\u65f6\u4f7f\u7528\u3002\u5e0c\u671b\u8fd9\u4e9b\u65b9\u6cd5\u80fd\u591f\u5e2e\u52a9\u4f60\u987a\u5229\u5730\u5c06Python\u964d\u7ea7\u5230\u6240\u9700\u7248\u672c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u68c0\u67e5\u6211\u5f53\u524d\u7684Python\u7248\u672c\uff1f<\/strong><br \/>\u8981\u68c0\u67e5\u5f53\u524d\u5b89\u88c5\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\u51fa\u4f60\u5f53\u524d\u4f7f\u7528\u7684Python\u7248\u672c\u53f7\uff0c\u4f8b\u5982\u201cPython 3.9.1\u201d\u3002<\/p>\n<p><strong>\u964d\u4f4ePython\u7248\u672c\u4f1a\u5f71\u54cd\u5df2\u5b89\u88c5\u7684\u5e93\u5417\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u964d\u4f4ePython\u7248\u672c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4e00\u4e9b\u5df2\u5b89\u88c5\u7684\u5e93\u4e0d\u517c\u5bb9\u3002\u8bb8\u591a\u5e93\u5728\u7279\u5b9a\u7248\u672c\u7684Python\u4e0a\u8fdb\u884c\u4f18\u5316\uff0c\u5982\u679c\u4f60\u964d\u7ea7\u5230\u8f83\u65e7\u7684\u7248\u672c\uff0c\u67d0\u4e9b\u529f\u80fd\u53ef\u80fd\u65e0\u6cd5\u6b63\u5e38\u5de5\u4f5c\uff0c\u6216\u8005\u9700\u8981\u91cd\u65b0\u5b89\u88c5\u4e0e\u65b0\u7248\u672c\u517c\u5bb9\u7684\u5e93\u3002<\/p>\n<p><strong>\u5982\u4f55\u5b89\u5168\u5730\u5207\u6362\u5230\u8f83\u4f4e\u7248\u672c\u7684Python\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528\u865a\u62df\u73af\u5883\u6765\u5b89\u5168\u5730\u5207\u6362Python\u7248\u672c\u3002\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\uff0c\u5b89\u88c5\u6240\u9700\u7684\u8f83\u4f4e\u7248\u672cPython\uff0c\u5e76\u5728\u8be5\u73af\u5883\u4e2d\u5b89\u88c5\u6240\u6709\u5fc5\u8981\u7684\u5e93\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u907f\u514d\u5bf9\u5168\u5c40Python\u73af\u5883\u9020\u6210\u5f71\u54cd\uff0c\u5e76\u786e\u4fdd\u9879\u76ee\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u4e0d\u4f1a\u51b2\u7a81\u3002\u4f7f\u7528<code>venv<\/code>\u6216<code>virtualenv<\/code>\u5de5\u5177\u90fd\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5c06Python\u964d\u7ea7\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528pyenv\u3001\u901a\u8fc7Anaconda\u7ba1\u7406\u3001\u5378\u8f7d\u5f53\u524d\u7248\u672c\u5e76\u91cd\u65b0\u5b89\u88c5\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1091968,"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\/1091963"}],"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=1091963"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1091963\/revisions"}],"predecessor-version":[{"id":1091969,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1091963\/revisions\/1091969"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1091968"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1091963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1091963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1091963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}