{"id":982209,"date":"2024-12-27T07:08:58","date_gmt":"2024-12-26T23:08:58","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/982209.html"},"modified":"2024-12-27T07:09:00","modified_gmt":"2024-12-26T23:09:00","slug":"%e5%a6%82%e4%bd%95%e7%bc%96%e8%af%91%e8%87%aa%e5%b7%b1%e7%9a%84python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/982209.html","title":{"rendered":"\u5982\u4f55\u7f16\u8bd1\u81ea\u5df1\u7684python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24210813\/59d627c4-4ad4-4ee4-a6de-ba76a1435371.webp\" alt=\"\u5982\u4f55\u7f16\u8bd1\u81ea\u5df1\u7684python\" \/><\/p>\n<p><p> <strong>\u7f16\u8bd1\u81ea\u5df1\u7684Python\u6d89\u53ca\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4\uff1a\u4e0b\u8f7dPython\u6e90\u4ee3\u7801\u3001\u914d\u7f6e\u7f16\u8bd1\u73af\u5883\u3001\u8fd0\u884c\u7f16\u8bd1\u547d\u4ee4\u3001\u6d4b\u8bd5\u7f16\u8bd1\u7ed3\u679c\u3002<\/strong> \u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u8fdb\u884c\u8fd9\u4e9b\u6b65\u9aa4\u5e76\u89e3\u51b3\u53ef\u80fd\u9047\u5230\u7684\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4e0b\u8f7dPython\u6e90\u4ee3\u7801<\/p>\n<\/p>\n<p><p>\u4e0b\u8f7dPython\u6e90\u4ee3\u7801\u662f\u7f16\u8bd1Python\u7684\u7b2c\u4e00\u6b65\u3002Python\u7684\u6e90\u4ee3\u7801\u53ef\u4ee5\u4ece\u5b98\u65b9Python\u7f51\u7ad9\uff08<a href=\"https:\/\/www.python.org\/%EF%BC%89%E4%B8%8A%E8%8E%B7%E5%8F%96%E3%80%82%E5%9C%A8%E4%B8%8B%E8%BD%BD%E9%A1%B5%E9%9D%A2%EF%BC%8C%E9%80%89%E6%8B%A9%E9%80%82%E5%90%88%E6%82%A8%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%9A%84%E7%89%88%E6%9C%AC%EF%BC%8C%E9%80%9A%E5%B8%B8%E4%BC%9A%E4%BB%A5.tar.xz%E6%88%96.zip%E6%A0%BC%E5%BC%8F%E6%8F%90%E4%BE%9B%E3%80%82%E5%9C%A8%E4%B8%8B%E8%BD%BD%E5%AE%8C%E6%88%90%E5%90%8E%EF%BC%8C%E8%A7%A3%E5%8E%8B%E6%96%87%E4%BB%B6%E5%88%B0%E6%9C%AC%E5%9C%B0%E7%9B%AE%E5%BD%95%E3%80%82\">https:\/\/www.python.org\/\uff09\u4e0a\u83b7\u53d6\u3002\u5728\u4e0b\u8f7d\u9875\u9762\uff0c\u9009\u62e9\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u7248\u672c\uff0c\u901a\u5e38\u4f1a\u4ee5.tar.xz\u6216.zip\u683c\u5f0f\u63d0\u4f9b\u3002\u5728\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u89e3\u538b\u6587\u4ef6\u5230\u672c\u5730\u76ee\u5f55\u3002<\/a><\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u914d\u7f6e\u7f16\u8bd1\u73af\u5883<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u5fc5\u8981\u7684\u5de5\u5177\u548c\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u7f16\u8bd1Python\u9700\u8981\u4e00\u4e9b\u7279\u5b9a\u7684\u5de5\u5177\u548c\u5e93\u3002\u5bf9\u4e8eLinux\u7cfb\u7edf\uff0c\u901a\u5e38\u9700\u8981\u5b89\u88c5gcc\u3001make\u548c\u5176\u4ed6\u5fc5\u8981\u7684\u5f00\u53d1\u5305\u3002\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\uff08\u5982apt\u3001yum\u3001dnf\u7b49\uff09\u6765\u5b89\u88c5\u8fd9\u4e9b\u5de5\u5177\u3002\u4f8b\u5982\uff0c\u5728Debian\u6216Ubuntu\u7cfb\u7edf\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt-get update<\/p>\n<p>sudo apt-get install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5bf9\u4e8eWindows\u7cfb\u7edf\uff0c\u53ef\u4ee5\u4f7f\u7528Cygwin\u6216MinGW\u6765\u63d0\u4f9b\u7c7b\u4f3c\u7684\u7f16\u8bd1\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u914d\u7f6e\u7f16\u8bd1\u9009\u9879<\/strong><\/p>\n<\/p>\n<p><p>\u8fdb\u5165\u89e3\u538b\u540e\u7684Python\u6e90\u4ee3\u7801\u76ee\u5f55\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u914d\u7f6e\u7f16\u8bd1\u9009\u9879\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">.\/configure<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u5c06\u68c0\u67e5\u4f60\u7684\u7f16\u8bd1\u73af\u5883\uff0c\u5e76\u751f\u6210\u4e00\u4e2aMakefile\u6587\u4ef6\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u53c2\u6570\u6765\u5b9a\u5236\u7f16\u8bd1\u9009\u9879\uff0c\u4f8b\u5982\u6307\u5b9a\u5b89\u88c5\u8def\u5f84\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">.\/configure --prefix=\/opt\/python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u8fd0\u884c\u7f16\u8bd1\u547d\u4ee4<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u8bd1Python<\/strong><\/p>\n<\/p>\n<p><p>\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u4f7f\u7528make\u547d\u4ee4\u5f00\u59cb\u7f16\u8bd1\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">make<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u8fc7\u7a0b\u53ef\u80fd\u9700\u8981\u4e00\u4e9b\u65f6\u95f4\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u4f60\u7684\u8ba1\u7b97\u673a\u6027\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u7f16\u8bd1\u7ed3\u679c<\/strong><\/p>\n<\/p>\n<p><p>\u7f16\u8bd1\u5b8c\u6210\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u7f16\u8bd1\u597d\u7684Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo make install<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u628a\u7f16\u8bd1\u597d\u7684Python\u4e8c\u8fdb\u5236\u6587\u4ef6\u5b89\u88c5\u5230\u6307\u5b9a\u7684\u76ee\u5f55\u4e2d\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u6d4b\u8bd5\u7f16\u8bd1\u7ed3\u679c<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9a8c\u8bc1Python\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u9a8c\u8bc1\u7f16\u8bd1\u7684Python\u7248\u672c\u662f\u5426\u6b63\u786e\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770bPython\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">\/opt\/python\/bin\/python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5e94\u8be5\u8f93\u51fa\u4f60\u7f16\u8bd1\u7684Python\u7248\u672c\u53f7\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u7b80\u5355\u7684Python\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\u6765\u6d4b\u8bd5\u7f16\u8bd1\u7684Python\u662f\u5426\u6b63\u5e38\u5de5\u4f5c\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3atest.py\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, Python!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u8fd0\u884c\u8fd9\u4e2a\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">\/opt\/python\/bin\/python3 test.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u8f93\u51fa\u201cHello, Python!\u201d\uff0c\u5219\u8bf4\u660e\u7f16\u8bd1\u548c\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u89e3\u51b3\u7f16\u8bd1\u4e2d\u7684\u5e38\u89c1\u95ee\u9898<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f3a\u5c11\u5e93\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u7f3a\u5c11\u67d0\u4e9b\u5e93\u6587\u4ef6\u7684\u9519\u8bef\u3002\u8fd9\u901a\u5e38\u662f\u56e0\u4e3a\u6ca1\u6709\u5b89\u88c5\u5fc5\u8981\u7684\u5f00\u53d1\u5305\u3002\u6839\u636e\u9519\u8bef\u4fe1\u606f\uff0c\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5b89\u88c5\u7f3a\u5931\u7684\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u914d\u7f6e\u9009\u9879\u9519\u8bef<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u914d\u7f6e\u9009\u9879\u4e0d\u6b63\u786e\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7f16\u8bd1\u5931\u8d25\u6216\u5b89\u88c5\u8def\u5f84\u9519\u8bef\u3002\u786e\u4fdd\u5728\u8fd0\u884c.\/configure\u547d\u4ee4\u65f6\u4f7f\u7528\u4e86\u6b63\u786e\u7684\u9009\u9879\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6743\u9650\u95ee\u9898<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u6743\u9650\u4e0d\u8db3\u7684\u95ee\u9898\u3002\u786e\u4fdd\u4f7f\u7528sudo\u6743\u9650\u8fd0\u884cmake install\u547d\u4ee4\uff0c\u6216\u8005\u5c06\u5b89\u88c5\u8def\u5f84\u8bbe\u7f6e\u4e3a\u7528\u6237\u6709\u5199\u6743\u9650\u7684\u76ee\u5f55\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u6210\u529f\u7f16\u8bd1\u81ea\u5df1\u7684Python\u7248\u672c\u3002\u8fd9\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728\u9700\u8981\u5b9a\u5236Python\u529f\u80fd\u6216\u8005\u5728\u4e0d\u652f\u6301\u5b98\u65b9\u9884\u7f16\u8bd1\u7248\u672c\u7684\u5e73\u53f0\u4e0a\u8fd0\u884cPython\u65f6\uff0c\u63d0\u4f9b\u7075\u6d3b\u7684\u89e3\u51b3\u65b9\u6848\u3002\u7f16\u8bd1Python\u867d\u7136\u9700\u8981\u4e00\u5b9a\u7684\u6280\u672f\u77e5\u8bc6\uff0c\u4f46\u4e5f\u662f\u4e00\u4e2a\u5b66\u4e60\u8ba1\u7b97\u673a\u7f16\u8bd1\u8fc7\u7a0b\u548cPython\u5185\u90e8\u5b9e\u73b0\u7684\u597d\u673a\u4f1a\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5f00\u59cb\u7f16\u8bd1\u81ea\u5df1\u7684Python\u7248\u672c\uff1f<\/strong><br \/>\u7f16\u8bd1\u81ea\u5df1\u7684Python\u7248\u672c\u9700\u8981\u4e00\u4e9b\u57fa\u7840\u77e5\u8bc6\u548c\u5de5\u5177\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684\u7cfb\u7edf\u4e0a\u5b89\u88c5\u6709\u5fc5\u8981\u7684\u7f16\u8bd1\u5de5\u5177\uff0c\u5982GCC\u6216Clang\u3002\u7136\u540e\uff0c\u4ecePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6e90\u4ee3\u7801\u5305\uff0c\u5e76\u89e3\u538b\u7f29\u3002\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528\u7ec8\u7aef\u8fdb\u5165\u89e3\u538b\u540e\u7684\u76ee\u5f55\uff0c\u8fd0\u884c<code>.\/configure<\/code>\u547d\u4ee4\u6765\u914d\u7f6e\u7f16\u8bd1\u9009\u9879\u3002\u6700\u540e\uff0c\u6267\u884c<code>make<\/code>\u547d\u4ee4\u8fdb\u884c\u7f16\u8bd1\uff0c\u5e76\u4f7f\u7528<code>make install<\/code>\u5c06\u7f16\u8bd1\u540e\u7684\u7248\u672c\u5b89\u88c5\u5230\u7cfb\u7edf\u4e2d\u3002\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u62e5\u6709\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684Python\u7248\u672c\u3002<\/p>\n<p><strong>\u7f16\u8bd1Python\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4f9d\u8d56\u9879\uff1f<\/strong><br \/>\u5728\u7f16\u8bd1Python\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u7684\u7cfb\u7edf\u5177\u5907\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u9879\u3002\u5e38\u89c1\u7684\u4f9d\u8d56\u9879\u5305\u62ec<code>libffi-dev<\/code>\u3001<code>libssl-dev<\/code>\u3001<code>zlib1g-dev<\/code>\u3001<code>libbz2-dev<\/code>\u3001<code>libsqlite3-dev<\/code>\u7b49\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u6765\u5b89\u88c5\u8fd9\u4e9b\u4f9d\u8d56\u9879\uff0c\u4f8b\u5982\u5728Ubuntu\u4e0a\u4f7f\u7528<code>apt-get install<\/code>\u547d\u4ee4\u3002\u7f3a\u5c11\u4efb\u4f55\u4e00\u4e2a\u4f9d\u8d56\u9879\u53ef\u80fd\u5bfc\u81f4\u7f16\u8bd1\u5931\u8d25\uff0c\u56e0\u6b64\u5728\u5f00\u59cb\u7f16\u8bd1\u4e4b\u524d\uff0c\u4ed4\u7ec6\u68c0\u67e5\u5e76\u5b89\u88c5\u6240\u6709\u9700\u8981\u7684\u5e93\u3002<\/p>\n<p><strong>\u7f16\u8bd1Python\u540e\u5982\u4f55\u7ba1\u7406\u591a\u4e2a\u7248\u672c\uff1f<\/strong><br \/>\u5982\u679c\u4f60\u5e0c\u671b\u5728\u540c\u4e00\u53f0\u673a\u5668\u4e0a\u8fd0\u884c\u591a\u4e2aPython\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528\u865a\u62df\u73af\u5883\u5de5\u5177\uff0c\u5982<code>venv<\/code>\u6216<code>virtualenv<\/code>\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u4f60\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684\u73af\u5883\uff0c\u907f\u514d\u7248\u672c\u51b2\u7a81\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>pyenv<\/code>\u5de5\u5177\u4e5f\u80fd\u65b9\u4fbf\u5730\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u3002\u901a\u8fc7<code>pyenv<\/code>\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5b89\u88c5\u3001\u5207\u6362\u548c\u8bbe\u7f6e\u4e0d\u540c\u7684Python\u7248\u672c\uff0c\u786e\u4fdd\u9879\u76ee\u7684\u517c\u5bb9\u6027\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u7f16\u8bd1\u81ea\u5df1\u7684Python\u6d89\u53ca\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4\uff1a\u4e0b\u8f7dPython\u6e90\u4ee3\u7801\u3001\u914d\u7f6e\u7f16\u8bd1\u73af\u5883\u3001\u8fd0\u884c\u7f16\u8bd1\u547d\u4ee4\u3001\u6d4b\u8bd5\u7f16\u8bd1\u7ed3\u679c\u3002 \u4e0b [&hellip;]","protected":false},"author":3,"featured_media":982218,"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\/982209"}],"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=982209"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/982209\/revisions"}],"predecessor-version":[{"id":982222,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/982209\/revisions\/982222"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/982218"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=982209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=982209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=982209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}