{"id":1004994,"date":"2024-12-27T10:31:38","date_gmt":"2024-12-27T02:31:38","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1004994.html"},"modified":"2024-12-27T10:31:41","modified_gmt":"2024-12-27T02:31:41","slug":"python-%e5%a6%82%e4%bd%95%e5%8d%87%e7%ba%a7%e7%89%88%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1004994.html","title":{"rendered":"python \u5982\u4f55\u5347\u7ea7\u7248\u672c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25081709\/a10cc414-c798-4fb5-b406-eab9b2033517.webp\" alt=\"python \u5982\u4f55\u5347\u7ea7\u7248\u672c\" \/><\/p>\n<p><p> \u5f00\u5934\u6bb5\u843d\uff1a<br \/><strong>Python\u5347\u7ea7\u7248\u672c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5305\u62ec\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u3001\u5b89\u88c5\u7ba1\u7406\u5de5\u5177\u5982pyenv\u3001\u6e90\u7801\u5b89\u88c5\u7b49\u3002<\/strong> \u4f7f\u7528\u5305\u7ba1\u7406\u5668\uff08\u5982apt\u3001yum\u3001brew\u7b49\uff09\u662f\u6700\u5e38\u89c1\u4e14\u7b80\u4fbf\u7684\u65b9\u5f0f\uff0c\u56e0\u4e3a\u5b83\u4eec\u901a\u5e38\u4f1a\u81ea\u52a8\u5904\u7406\u4f9d\u8d56\u5173\u7cfb\u548c\u7cfb\u7edf\u96c6\u6210\u3002\u5bf9\u4e8e\u9700\u8981\u5728\u540c\u4e00\u7cfb\u7edf\u4e0a\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u7684\u7528\u6237\uff0cpyenv\u662f\u4e00\u4e2a\u7406\u60f3\u7684\u5de5\u5177\uff0c\u56e0\u4e3a\u5b83\u80fd\u591f\u8f7b\u677e\u5207\u6362\u4e0d\u540c\u7248\u672c\uff0c\u9002\u7528\u4e8e\u5f00\u53d1\u73af\u5883\u7684\u591a\u6837\u5316\u9700\u6c42\u3002\u6b64\u5916\uff0c\u901a\u8fc7\u6e90\u7801\u5b89\u88c5Python\u53ef\u4ee5\u4e3a\u7528\u6237\u63d0\u4f9b\u6700\u5927\u7684\u7075\u6d3b\u6027\uff0c\u5c3d\u7ba1\u8fd9\u9700\u8981\u66f4\u591a\u7684\u6280\u672f\u7ec6\u8282\u548c\u624b\u52a8\u64cd\u4f5c\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u6bcf\u79cd\u65b9\u6cd5\u7684\u4f18\u7f3a\u70b9\u548c\u5b9e\u73b0\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5347\u7ea7Python\u7248\u672c  <\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u56e0\u4e3a\u5b83\u4eec\u4f1a\u81ea\u52a8\u7ba1\u7406\u4f9d\u8d56\u5173\u7cfb\u548c\u7cfb\u7edf\u96c6\u6210\u3002\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u6709\u4e0d\u540c\u7684\u5305\u7ba1\u7406\u5668\uff0c\u5982Linux\u7684apt\u548cyum\uff0cmacOS\u7684brew\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li>apt\uff08\u9002\u7528\u4e8eUbuntu\u53caDebian\u7cfb\uff09<br \/>\u5728Ubuntu\u6216Debian\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7apt\u6765\u5347\u7ea7Python\u7248\u672c\u3002\u9996\u5148\uff0c\u786e\u4fdd\u66f4\u65b0\u672c\u5730\u5305\u7d22\u5f15\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">sudo apt update<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u641c\u7d22\u53ef\u7528\u7684Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">apt list python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u9009\u62e9\u6240\u9700\u7684\u7248\u672c\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt install python3.x<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u9a8c\u8bc1\u5b89\u88c5\u7684\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>yum\uff08\u9002\u7528\u4e8eCentOS\u53caRedHat\u7cfb\uff09<br \/>\u5728CentOS\u6216RedHat\u7cfb\u7edf\u4e2d\uff0c\u4f7f\u7528yum\u8fdb\u884cPython\u5347\u7ea7\u3002\u9996\u5148\uff0c\u540c\u6837\u66f4\u65b0\u5305\u7d22\u5f15\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">sudo yum check-update<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u67e5\u627e\u53ef\u7528\u7684Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">yum list av<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>lable python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u9009\u62e9\u6240\u9700\u7684\u7248\u672c\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo yum install python3.x<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u68c0\u67e5\u5b89\u88c5\u7684Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>brew\uff08\u9002\u7528\u4e8emacOS\uff09<br \/>\u5728macOS\u4e2d\uff0cbrew\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u5305\u7ba1\u7406\u5668\u3002\u9996\u5148\uff0c\u66f4\u65b0brew\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">brew update<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u901a\u8fc7brew\u5b89\u88c5\u6216\u5347\u7ea7Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">brew install python@3.x<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b8c\u6210\u540e\uff0c\u68c0\u67e5\u5b89\u88c5\u7684Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528pyenv\u7ba1\u7406\u548c\u5347\u7ea7Python\u7248\u672c  <\/p>\n<\/p>\n<p><p>pyenv \u662f\u4e00\u4e2a\u7528\u4e8e\u7ba1\u7406\u591a\u7248\u672cPython\u7684\u5de5\u5177\uff0c\u5c24\u5176\u9002\u5408\u5f00\u53d1\u73af\u5883\u4e2d\u9700\u8981\u540c\u65f6\u4f7f\u7528\u591a\u4e2aPython\u7248\u672c\u7684\u7528\u6237\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5pyenv<br \/>\u9996\u5148\uff0c\u9700\u8981\u786e\u4fdd\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86\u5fc5\u8981\u7684\u4f9d\u8d56\u5de5\u5177\u3002\u5bf9\u4e8eUbuntu\u7528\u6237\uff0c\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">sudo apt-get update<\/p>\n<p>sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u5b89\u88c5pyenv\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">curl https:\/\/pyenv.run | bash<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u540e\uff0c\u914d\u7f6eshell\u73af\u5883\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>\u4f7f\u7528pyenv\u5b89\u88c5Python\u7248\u672c<br \/>\u4f7f\u7528pyenv\u5b89\u88c5Python\u7248\u672c\u975e\u5e38\u7b80\u5355\uff0c\u9996\u5148\u67e5\u770b\u53ef\u7528\u7248\u672c\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">pyenv install --list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u9009\u62e9\u6240\u9700\u7248\u672c\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv install 3.x.x<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8bbe\u7f6e\u5168\u5c40\u6216\u672c\u5730Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv global 3.x.x<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\u9488\u5bf9\u67d0\u4e2a\u9879\u76ee\u8bbe\u7f6e\u672c\u5730\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv local 3.x.x<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u5207\u6362Python\u7248\u672c<br \/>pyenv\u4f7f\u5f97\u5728\u4e0d\u540cPython\u7248\u672c\u4e4b\u95f4\u7684\u5207\u6362\u53d8\u5f97\u975e\u5e38\u7b80\u5355\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">pyenv global 3.x.x<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u68c0\u67e5\u5f53\u524d\u4f7f\u7528\u7684Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u6e90\u7801\u5b89\u88c5Python  <\/p>\n<\/p>\n<p><p>\u6e90\u7801\u5b89\u88c5Python\u63d0\u4f9b\u4e86\u6700\u5927\u7684\u7075\u6d3b\u6027\uff0c\u4f46\u4e5f\u9700\u8981\u66f4\u591a\u7684\u624b\u52a8\u914d\u7f6e\u548c\u4f9d\u8d56\u7ba1\u7406\u3002<\/p>\n<\/p>\n<ol>\n<li>\u51c6\u5907\u5b89\u88c5\u73af\u5883<br \/>\u9996\u5148\uff0c\u786e\u4fdd\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86\u7f16\u8bd1Python\u6240\u9700\u7684\u5de5\u5177\u548c\u5e93\u3002\u5bf9\u4e8eUbuntu\u7528\u6237\uff0c\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">sudo apt-get update<\/p>\n<p>sudo apt-get install -y build-essential checkinstall<\/p>\n<p>sudo apt-get install -y libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u4e0b\u8f7d\u5e76\u89e3\u538b\u6e90\u7801<br \/>\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6240\u9700\u7248\u672c\u7684\u6e90\u7801\u3002\u4ee5Python 3.x.x\u4e3a\u4f8b\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">wget https:\/\/www.python.org\/ftp\/python\/3.x.x\/Python-3.x.x.tgz<\/p>\n<p>tar -xvf Python-3.x.x.tgz<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u7f16\u8bd1\u548c\u5b89\u88c5<br \/>\u8fdb\u5165\u89e3\u538b\u540e\u7684\u76ee\u5f55\uff0c\u914d\u7f6e\u7f16\u8bd1\u73af\u5883\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">cd Python-3.x.x<\/p>\n<p>.\/configure --enable-optimizations<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u7f16\u8bd1\u5e76\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">make<\/p>\n<p>sudo make install<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b8c\u6210\u540e\uff0c\u68c0\u67e5\u5b89\u88c5\u7684Python\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u7ba1\u7406Python\u7248\u672c  <\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u5728\u4e0d\u540c\u7684\u9879\u76ee\u4e2d\u4f7f\u7528\u4e0d\u540c\u7684Python\u7248\u672c\u548c\u4f9d\u8d56\u3002<\/p>\n<\/p>\n<ol>\n<li>\u521b\u5efa\u865a\u62df\u73af\u5883<br \/>\u5728\u7cfb\u7edf\u4e2d\u5b89\u88c5\u4e86\u591a\u4e2aPython\u7248\u672c\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>venv<\/code>\u6a21\u5757\u521b\u5efa\u865a\u62df\u73af\u5883\u3002\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u9879\u76ee\u76ee\u5f55\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">mkdir myproject<\/p>\n<p>cd myproject<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3.x -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u6fc0\u6d3b\u548c\u4f7f\u7528\u865a\u62df\u73af\u5883<br \/>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u6240\u6709\u7684Python\u547d\u4ee4\u548c\u5305\u7ba1\u7406\u64cd\u4f5c\u90fd\u4f1a\u5728\u8be5\u73af\u5883\u4e2d\u8fdb\u884c\u3002\u5bf9\u4e8eLinux\u548cmacOS\u7528\u6237\uff0c\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>\u5bf9\u4e8eWindows\u7528\u6237\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">myenv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u540e\uff0c\u53ef\u4ee5\u5b89\u88c5\u6240\u9700\u7684\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install &lt;package_name&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u9000\u51fa\u865a\u62df\u73af\u5883<br \/>\u5b8c\u6210\u5f00\u53d1\u5de5\u4f5c\u540e\uff0c\u53ef\u4ee5\u9000\u51fa\u865a\u62df\u73af\u5883\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u6ce8\u610f\u4e8b\u9879  <\/p>\n<\/p>\n<p><p>\u5728\u5347\u7ea7Python\u7248\u672c\u65f6\uff0c\u6709\u4e00\u4e9b\u5e38\u89c1\u7684\u6ce8\u610f\u4e8b\u9879\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u907f\u514d\u6f5c\u5728\u7684\u95ee\u9898\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5907\u4efd\u5f53\u524d\u73af\u5883<br \/>\u5728\u8fdb\u884cPython\u5347\u7ea7\u4e4b\u524d\uff0c\u5907\u4efd\u5f53\u524d\u7684\u73af\u5883\u914d\u7f6e\u548c\u4f9d\u8d56\u5217\u8868\u662f\u4e00\u4e2a\u826f\u597d\u7684\u4e60\u60ef\u3002\u53ef\u4ee5\u4f7f\u7528<code>pip freeze<\/code>\u547d\u4ee4\u8f93\u51fa\u5f53\u524d\u73af\u5883\u7684\u4f9d\u8d56\u5217\u8868\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">pip freeze &gt; requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\n<p>\u68c0\u67e5\u517c\u5bb9\u6027<br \/>\u5728\u5347\u7ea7Python\u7248\u672c\u540e\uff0c\u90e8\u5206\u65e7\u7684\u5e93\u548c\u4ee3\u7801\u53ef\u80fd\u4f1a\u51fa\u73b0\u517c\u5bb9\u6027\u95ee\u9898\u3002\u5728\u5347\u7ea7\u4e4b\u524d\uff0c\u68c0\u67e5\u9879\u76ee\u4f9d\u8d56\u5e93\u7684\u517c\u5bb9\u6027\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u73af\u5883<br \/>\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u8fdb\u884c\u5347\u7ea7\u524d\uff0c\u5efa\u8bae\u5728\u6d4b\u8bd5\u73af\u5883\u4e2d\u8fdb\u884c\u5f7b\u5e95\u7684\u9a8c\u8bc1\uff0c\u4ee5\u786e\u4fdd\u5347\u7ea7\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\u548c\u6ce8\u610f\u4e8b\u9879\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u5176\u7cfb\u7edf\u4e2d\u987a\u5229\u5b8c\u6210Python\u7248\u672c\u7684\u5347\u7ea7\uff0c\u5e76\u6709\u6548\u7ba1\u7406\u591a\u4e2a\u7248\u672c\u7684Python\uff0c\u6ee1\u8db3\u4e0d\u540c\u9879\u76ee\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u68c0\u67e5\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\uff1f<\/strong><br \/>\u8981\u68c0\u67e5\u60a8\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\u60a8\u5f53\u524d\u7684Python\u7248\u672c\u4fe1\u606f\uff0c\u5e2e\u52a9\u60a8\u786e\u8ba4\u662f\u5426\u9700\u8981\u8fdb\u884c\u5347\u7ea7\u3002<\/p>\n<p><strong>\u5728Windows\u4e0a\u5982\u4f55\u5347\u7ea7Python\uff1f<\/strong><br \/>\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u60a8\u53ef\u4ee5\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684\u5b89\u88c5\u7a0b\u5e8f\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f\uff0c\u5e76\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\u3002\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u60a8\u53ef\u4ee5\u9009\u62e9\u201cUpgrade Now\u201d\u6765\u76f4\u63a5\u5347\u7ea7\u5230\u6700\u65b0\u7248\u672c\u3002<\/p>\n<p><strong>\u5728macOS\u4e0a\u5982\u4f55\u4f7f\u7528Homebrew\u5347\u7ea7Python\uff1f<\/strong><br \/>\u5982\u679c\u60a8\u4f7f\u7528Homebrew\u6765\u7ba1\u7406\u8f6f\u4ef6\u5305\uff0c\u53ef\u4ee5\u901a\u8fc7\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165<code>brew update<\/code>\u6765\u66f4\u65b0Homebrew\u672c\u8eab\uff0c\u7136\u540e\u8f93\u5165<code>brew upgrade python<\/code>\u6765\u5347\u7ea7Python\u7248\u672c\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u60a8\u83b7\u5f97\u6700\u65b0\u7684\u53ef\u7528\u7248\u672c\uff0c\u4e14\u64cd\u4f5c\u7b80\u5355\u5feb\u6377\u3002<\/p>\n<p><strong>\u5728Linux\u7cfb\u7edf\u4e2d\u5982\u4f55\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5347\u7ea7Python\uff1f<\/strong><br \/>\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u53d1\u884c\u7248\u4f7f\u7528\u4e0d\u540c\u7684\u5305\u7ba1\u7406\u5668\u3002\u4f8b\u5982\uff0c\u5728Ubuntu\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>sudo apt update<\/code>\u548c<code>sudo apt upgrade python3<\/code>\u6765\u5347\u7ea7Python\u3002\u786e\u4fdd\u5728\u5347\u7ea7\u524d\u67e5\u770b\u60a8\u7684\u7cfb\u7edf\u517c\u5bb9\u6027\uff0c\u4ee5\u907f\u514d\u6f5c\u5728\u95ee\u9898\u3002<\/p>\n<p><strong>\u662f\u5426\u9700\u8981\u5907\u4efd\u6211\u7684Python\u73af\u5883\u548c\u9879\u76ee\uff1f<\/strong><br \/>\u5728\u8fdb\u884cPython\u7248\u672c\u5347\u7ea7\u4e4b\u524d\uff0c\u5907\u4efd\u60a8\u7684\u9879\u76ee\u548c\u73af\u5883\u662f\u4e00\u4e2a\u597d\u4e60\u60ef\u3002\u4f7f\u7528\u865a\u62df\u73af\u5883\uff08\u5982venv\u6216conda\uff09\u53ef\u4ee5\u5e2e\u52a9\u60a8\u7ba1\u7406\u4f9d\u8d56\u548c\u7248\u672c\uff0c\u786e\u4fdd\u5728\u5347\u7ea7\u540e\u9879\u76ee\u4ecd\u80fd\u6b63\u5e38\u8fd0\u884c\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662fpip\uff0c\u53ef\u4ee5\u901a\u8fc7<code>pip freeze &gt; requirements.txt<\/code>\u547d\u4ee4\u4fdd\u5b58\u5f53\u524d\u73af\u5883\u7684\u4f9d\u8d56\u5217\u8868\uff0c\u4ee5\u4fbf\u5728\u9700\u8981\u65f6\u6062\u590d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d\uff1aPython\u5347\u7ea7\u7248\u672c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5305\u62ec\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u3001\u5b89\u88c5\u7ba1\u7406\u5de5\u5177\u5982pyenv\u3001\u6e90\u7801\u5b89\u88c5\u7b49\u3002 [&hellip;]","protected":false},"author":3,"featured_media":1004999,"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\/1004994"}],"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=1004994"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1004994\/revisions"}],"predecessor-version":[{"id":1005000,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1004994\/revisions\/1005000"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1004999"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1004994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1004994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1004994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}