{"id":1168721,"date":"2025-01-15T16:01:42","date_gmt":"2025-01-15T08:01:42","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1168721.html"},"modified":"2025-01-15T16:01:45","modified_gmt":"2025-01-15T08:01:45","slug":"python%e5%a6%82%e4%bd%95%e8%87%aa%e5%ae%9a%e4%b9%89%e5%ae%89%e8%a3%85","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1168721.html","title":{"rendered":"python\u5982\u4f55\u81ea\u5b9a\u4e49\u5b89\u88c5"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26065900\/7f326fc3-8cf4-44eb-8bc3-9a8f85040acd.webp\" alt=\"python\u5982\u4f55\u81ea\u5b9a\u4e49\u5b89\u88c5\" \/><\/p>\n<p><p> <strong>Python\u81ea\u5b9a\u4e49\u5b89\u88c5\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u865a\u62df\u73af\u5883\u3001\u4fee\u6539\u5b89\u88c5\u8def\u5f84\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u6765\u5b9e\u73b0\u3002<\/strong> \u5176\u4e2d\uff0c<strong>\u4f7f\u7528\u865a\u62df\u73af\u5883<\/strong>\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5305\u7248\u672c\u51b2\u7a81\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u4e0d\u5f71\u54cd\u5168\u5c40Python\u73af\u5883\u7684\u60c5\u51b5\u4e0b\u5b89\u88c5\u548c\u7ba1\u7406\u9879\u76ee\u6240\u9700\u7684\u5305\u3002\u5728\u521b\u5efa\u865a\u62df\u73af\u5883\u65f6\uff0c\u53ef\u4ee5\u6307\u5b9aPython\u89e3\u91ca\u5668\u7248\u672c\u3001\u5b89\u88c5\u8def\u5f84\u4ee5\u53ca\u9700\u8981\u7684\u4f9d\u8d56\u5305\uff0c\u4ece\u800c\u5b9e\u73b0\u81ea\u5b9a\u4e49\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\u4f7f\u7528\u865a\u62df\u73af\u5883\u7684\u6b65\u9aa4<\/strong>\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Python 3.3\u6216\u66f4\u9ad8\u7248\u672c\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u7248\u672c\u81ea\u5e26\u4e86venv\u6a21\u5757\u3002<\/li>\n<li>\u4f7f\u7528\u547d\u4ee4\u884c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\uff0c\u4f8b\u5982\uff1a<code>python -m venv myenv<\/code>\uff0c\u5176\u4e2d<code>myenv<\/code>\u662f\u4f60\u5e0c\u671b\u521b\u5efa\u7684\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\u3002<\/li>\n<li>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002\u5728Windows\u4e0a\uff0c\u8fd0\u884c<code>myenv\\Scripts\\activate<\/code>\uff0c\u5728Unix\u6216Mac\u4e0a\uff0c\u8fd0\u884c<code>source myenv\/bin\/activate<\/code>\u3002<\/li>\n<li>\u5728\u6fc0\u6d3b\u7684\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684\u5305\uff0c\u4f8b\u5982\uff1a<code>pip install requests<\/code>\u3002<\/li>\n<li>\u5b8c\u6210\u9879\u76ee\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c<code>deactivate<\/code>\u547d\u4ee4\u6765\u9000\u51fa\u865a\u62df\u73af\u5883\u3002<\/li>\n<\/ol>\n<hr>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><h4>1. \u521b\u5efa\u548c\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u8ba9\u4f60\u5728\u540c\u4e00\u53f0\u673a\u5668\u4e0a\u5e76\u884c\u5f00\u53d1\u591a\u4e2aPython\u9879\u76ee\uff0c\u800c\u4e0d\u4f1a\u4ea7\u751f\u5305\u7248\u672c\u51b2\u7a81\u3002\u521b\u5efa\u865a\u62df\u73af\u5883\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Python 3.3\u6216\u66f4\u9ad8\u7248\u672c\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u7248\u672c\u81ea\u5e26\u4e86<code>venv<\/code>\u6a21\u5757\u3002\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u547d\u4ee4\u4e2d\uff0c<code>myenv<\/code>\u662f\u4f60\u5e0c\u671b\u521b\u5efa\u7684\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\u3002\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u865a\u62df\u73af\u5883\u4f1a\u5305\u542b\u4e00\u4e2a\u72ec\u7acb\u7684Python\u89e3\u91ca\u5668\u548c\u4e00\u5957\u72ec\u7acb\u7684\u5305\u7ba1\u7406\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728Windows\u4e0a\uff0c\u8fd0\u884c\uff1a\n<pre><code class=\"language-bash\">myenv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u5728Unix\u6216Mac\u4e0a\uff0c\u8fd0\u884c\uff1a\n<pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u4f60\u4f1a\u6ce8\u610f\u5230\u547d\u4ee4\u884c\u63d0\u793a\u7b26\u524d\u9762\u4f1a\u591a\u51fa\u865a\u62df\u73af\u5883\u7684\u540d\u5b57\uff0c\u4f8b\u5982<code>(myenv)<\/code>\uff0c\u8fd9\u8868\u660e\u4f60\u73b0\u5728\u6b63\u5904\u4e8e\u865a\u62df\u73af\u5883\u4e2d\u3002<\/p>\n<\/p>\n<p><h4>2. \u7ba1\u7406\u865a\u62df\u73af\u5883\u4e2d\u7684\u5305<\/h4>\n<\/p>\n<p><p>\u5728\u6fc0\u6d3b\u7684\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u6765\u5b89\u88c5\u3001\u66f4\u65b0\u548c\u5378\u8f7d\u5305\u3002\u4f8b\u5982\uff0c\u5b89\u88c5<code>requests<\/code>\u5305\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6240\u6709\u5b89\u88c5\u7684\u5305\u548c\u5176\u4f9d\u8d56\u9879\u90fd\u4f1a\u4fdd\u5b58\u5728\u865a\u62df\u73af\u5883\u7684<code>site-packages<\/code>\u76ee\u5f55\u4e2d\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u5168\u5c40\u7684Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528<code>pip list<\/code>\u547d\u4ee4\u67e5\u770b\u5f53\u524d\u865a\u62df\u73af\u5883\u4e2d\u5df2\u7ecf\u5b89\u88c5\u7684\u6240\u6709\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8981\u4fdd\u5b58\u5f53\u524d\u865a\u62df\u73af\u5883\u4e2d\u7684\u5305\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip freeze &gt; requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06\u6240\u6709\u5df2\u5b89\u88c5\u5305\u53ca\u5176\u7248\u672c\u4fe1\u606f\u4fdd\u5b58\u5230\u4e00\u4e2a\u540d\u4e3a<code>requirements.txt<\/code>\u7684\u6587\u4ef6\u4e2d\uff0c\u8fd9\u4e2a\u6587\u4ef6\u53ef\u4ee5\u5728\u9879\u76ee\u4e2d\u5171\u4eab\uff0c\u4ee5\u4fbf\u5176\u4ed6\u5f00\u53d1\u8005\u53ef\u4ee5\u4f7f\u7528\u76f8\u540c\u7684\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u8981\u4f7f\u7528<code>requirements.txt<\/code>\u6587\u4ef6\u5b89\u88c5\u6240\u6709\u4f9d\u8d56\u5305\uff0c\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u9000\u51fa\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u5b8c\u6210\u9879\u76ee\u5f00\u53d1\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u9000\u51fa\u865a\u62df\u73af\u5883\u540e\uff0c\u547d\u4ee4\u884c\u63d0\u793a\u7b26\u4f1a\u6062\u590d\u5230\u539f\u6765\u7684\u72b6\u6001\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4fee\u6539\u5b89\u88c5\u8def\u5f84<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u5e0c\u671b\u5c06Python\u5b89\u88c5\u5230\u81ea\u5b9a\u4e49\u8def\u5f84\uff0c\u800c\u4e0d\u662f\u9ed8\u8ba4\u7684\u8def\u5f84\u3002\u8fd9\u53ef\u4ee5\u5728\u5b89\u88c5Python\u89e3\u91ca\u5668\u65f6\u8fdb\u884c\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><h4>1. \u5728Windows\u4e0a\u4fee\u6539\u5b89\u88c5\u8def\u5f84<\/h4>\n<\/p>\n<p><p>\u4e0b\u8f7dPython\u5b89\u88c5\u7a0b\u5e8f\u540e\uff0c\u53cc\u51fb\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f\u3002\u5728\u5b89\u88c5\u5411\u5bfc\u4e2d\uff0c\u9009\u62e9\u201cCustomize installation\u201d\u9009\u9879\u3002\u63a5\u4e0b\u6765\uff0c\u9009\u62e9\u9700\u8981\u5b89\u88c5\u7684\u7ec4\u4ef6\uff0c\u7136\u540e\u70b9\u51fb\u201cNext\u201d\u6309\u94ae\u3002\u5728\u201cAdvanced Options\u201d\u9875\u9762\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6307\u5b9a\u81ea\u5b9a\u4e49\u7684\u5b89\u88c5\u8def\u5f84\u3002\u52fe\u9009\u201cInstall for all users\u201d\u9009\u9879\uff0c\u5e76\u5728\u201cCustomize install location\u201d\u5b57\u6bb5\u4e2d\u8f93\u5165\u4f60\u60f3\u8981\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5c06Python\u5b89\u88c5\u5230<code>D:\\Python<\/code>\u76ee\u5f55\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5728\u201cCustomize install location\u201d\u5b57\u6bb5\u4e2d\u8f93\u5165<code>D:\\Python<\/code>\u3002\u5b8c\u6210\u8bbe\u7f6e\u540e\uff0c\u70b9\u51fb\u201cInstall\u201d\u6309\u94ae\u5f00\u59cb\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>2. \u5728Unix\u6216Mac\u4e0a\u4fee\u6539\u5b89\u88c5\u8def\u5f84<\/h4>\n<\/p>\n<p><p>\u5728Unix\u6216Mac\u4e0a\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u6e90\u7801\u7f16\u8bd1\u7684\u65b9\u6cd5\u6765\u81ea\u5b9a\u4e49\u5b89\u88c5\u8def\u5f84\u3002\u9996\u5148\uff0c\u4e0b\u8f7dPython\u7684\u6e90\u7801\u538b\u7f29\u5305\u5e76\u89e3\u538b\u7f29\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">wget https:\/\/www.python.org\/ftp\/python\/3.9.7\/Python-3.9.7.tgz<\/p>\n<p>tar xzf Python-3.9.7.tgz<\/p>\n<p>cd Python-3.9.7<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u4f7f\u7528<code>configure<\/code>\u811a\u672c\u6307\u5b9a\u81ea\u5b9a\u4e49\u5b89\u88c5\u8def\u5f84\u3002\u4f8b\u5982\uff0c\u5c06Python\u5b89\u88c5\u5230<code>\/opt\/python3.9<\/code>\u76ee\u5f55\u4e2d\uff0c\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">.\/configure --prefix=\/opt\/python3.9<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u7f16\u8bd1\u5e76\u5b89\u88c5Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">make<\/p>\n<p>make install<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u6765\u4f7f\u7528\u65b0\u5b89\u88c5\u7684Python\u89e3\u91ca\u5668\u3002\u4f8b\u5982\uff0c\u5c06\u4ee5\u4e0b\u884c\u6dfb\u52a0\u5230\u4f60\u7684<code>~\/.bashrc<\/code>\u6587\u4ef6\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PATH=\/opt\/python3.9\/bin:$PATH<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u91cd\u65b0\u52a0\u8f7d<code>~\/.bashrc<\/code>\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source ~\/.bashrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u73b0\u5728\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u65b0\u5b89\u88c5\u7684Python\u89e3\u91ca\u5668\u548c\u5305\u7ba1\u7406\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528<code>pip<\/code>\u7ba1\u7406\u5305\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u7684\u5305\u7ba1\u7406\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7ba1\u7406Python\u9879\u76ee\u4e2d\u7684\u4f9d\u8d56\u9879\u3002\u4f8b\u5982\uff0c<code>conda<\/code>\u548c<code>poetry<\/code>\u662f\u4e24\u4e2a\u6d41\u884c\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528Conda<\/h4>\n<\/p>\n<p><p><code>Conda<\/code>\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684\u5305\u7ba1\u7406\u548c\u73af\u5883\u7ba1\u7406\u5de5\u5177\uff0c\u7279\u522b\u9002\u7528\u4e8e\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u9886\u57df\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>Conda<\/code>\u6765\u521b\u5efa\u548c\u7ba1\u7406\u865a\u62df\u73af\u5883\uff0c\u5e76\u5b89\u88c5\u5404\u79cd\u5305\uff0c\u5305\u62ec\u975ePython\u5305\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4e0b\u8f7d\u5e76\u5b89\u88c5<code>Miniconda<\/code>\u6216<code>Anaconda<\/code>\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda create --name myenv python=3.9<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u547d\u4ee4\u4e2d\uff0c<code>myenv<\/code>\u662f\u73af\u5883\u7684\u540d\u79f0\uff0c<code>python=3.9<\/code>\u6307\u5b9a\u4e86Python\u7684\u7248\u672c\u3002<\/p>\n<\/p>\n<p><p>\u6fc0\u6d3b\u73af\u5883\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda activate myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6fc0\u6d3b\u7684\u73af\u5883\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>conda<\/code>\u6216<code>pip<\/code>\u6765\u5b89\u88c5\u5305\u3002\u4f8b\u5982\uff0c\u5b89\u88c5<code>numpy<\/code>\u5305\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8981\u67e5\u770b\u5f53\u524d\u73af\u5883\u4e2d\u5df2\u5b89\u88c5\u7684\u5305\uff0c\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8981\u4fdd\u5b58\u5f53\u524d\u73af\u5883\u4e2d\u7684\u5305\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda env export &gt; environment.yml<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06\u6240\u6709\u5df2\u5b89\u88c5\u5305\u53ca\u5176\u7248\u672c\u4fe1\u606f\u4fdd\u5b58\u5230\u4e00\u4e2a\u540d\u4e3a<code>environment.yml<\/code>\u7684\u6587\u4ef6\u4e2d\u3002<\/p>\n<\/p>\n<p><p>\u8981\u4f7f\u7528<code>environment.yml<\/code>\u6587\u4ef6\u521b\u5efa\u76f8\u540c\u7684\u73af\u5883\uff0c\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda env create -f environment.yml<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528Poetry<\/h4>\n<\/p>\n<p><p><code>Poetry<\/code>\u662f\u4e00\u4e2a\u73b0\u4ee3\u7684Python\u5305\u7ba1\u7406\u548c<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/23316.html\" target=\"_blank\">\u9879\u76ee\u7ba1\u7406<\/a>\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u81ea\u52a8\u5904\u7406\u4f9d\u8d56\u5173\u7cfb\uff0c\u5e76\u7b80\u5316\u9879\u76ee\u914d\u7f6e\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5b89\u88c5<code>Poetry<\/code>\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">curl -sSL https:\/\/install.python-poetry.org | python3 -<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">poetry new myproject<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u547d\u4ee4\u4e2d\uff0c<code>myproject<\/code>\u662f\u9879\u76ee\u7684\u540d\u79f0\u3002\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u76ee\u5f55\uff0c\u5176\u4e2d\u5305\u542b\u57fa\u672c\u7684\u9879\u76ee\u7ed3\u6784\u548c\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u8981\u6dfb\u52a0\u4f9d\u8d56\u5305\uff0c\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd myproject<\/p>\n<p>poetry add requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06<code>requests<\/code>\u5305\u6dfb\u52a0\u5230\u9879\u76ee\u7684\u4f9d\u8d56\u5217\u8868\u4e2d\uff0c\u5e76\u81ea\u52a8\u5b89\u88c5\u5b83\u3002<\/p>\n<\/p>\n<p><p>\u8981\u542f\u52a8\u865a\u62df\u73af\u5883\uff0c\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">poetry shell<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\uff0c\u5e76\u6fc0\u6d3b\u5b83\u3002<\/p>\n<\/p>\n<p><p>\u8981\u751f\u6210\u4f9d\u8d56\u5305\u7684\u9501\u6587\u4ef6\uff0c\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">poetry lock<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u751f\u6210\u4e00\u4e2a\u540d\u4e3a<code>poetry.lock<\/code>\u7684\u6587\u4ef6\uff0c\u5176\u4e2d\u8bb0\u5f55\u4e86\u6240\u6709\u4f9d\u8d56\u5305\u53ca\u5176\u7248\u672c\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><p>\u8981\u5b89\u88c5\u9879\u76ee\u7684\u6240\u6709\u4f9d\u8d56\u5305\uff0c\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">poetry install<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u6839\u636e<code>pyproject.toml<\/code>\u548c<code>poetry.lock<\/code>\u6587\u4ef6\u5b89\u88c5\u6240\u6709\u4f9d\u8d56\u5305\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528Docker<\/h3>\n<\/p>\n<p><p>Docker\u662f\u4e00\u79cd\u5bb9\u5668\u5316\u6280\u672f\uff0c\u53ef\u4ee5\u8ba9\u4f60\u5728\u4e00\u4e2a\u9694\u79bb\u7684\u73af\u5883\u4e2d\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\uff0c\u5305\u62ecPython\u9879\u76ee\u3002\u4f7f\u7528Docker\u53ef\u4ee5\u786e\u4fdd\u4f60\u7684\u9879\u76ee\u5728\u4efb\u4f55\u73af\u5883\u4e2d\u90fd\u80fd\u4e00\u81f4\u5730\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efaDockerfile<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>Dockerfile<\/code>\u7684\u6587\u4ef6\u3002\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5b9a\u4e49\u5982\u4f55\u6784\u5efaDocker\u955c\u50cf\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684<code>Dockerfile<\/code>\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-Dockerfile\"># \u4f7f\u7528\u5b98\u65b9\u7684Python\u57fa\u7840\u955c\u50cf<\/p>\n<p>FROM python:3.9<\/p>\n<h2><strong>\u8bbe\u7f6e\u5de5\u4f5c\u76ee\u5f55<\/strong><\/h2>\n<p>WORKDIR \/app<\/p>\n<h2><strong>\u590d\u5236\u9879\u76ee\u6587\u4ef6\u5230\u5bb9\u5668\u4e2d<\/strong><\/h2>\n<p>COPY . \/app<\/p>\n<h2><strong>\u5b89\u88c5\u9879\u76ee\u4f9d\u8d56\u5305<\/strong><\/h2>\n<p>RUN pip install -r requirements.txt<\/p>\n<h2><strong>\u8bbe\u7f6e\u5bb9\u5668\u542f\u52a8\u547d\u4ee4<\/strong><\/h2>\n<p>CMD [&quot;python&quot;, &quot;app.py&quot;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u5b98\u65b9\u7684Python 3.9\u57fa\u7840\u955c\u50cf\uff0c\u8bbe\u7f6e\u4e86\u5de5\u4f5c\u76ee\u5f55\uff0c\u5c06\u9879\u76ee\u6587\u4ef6\u590d\u5236\u5230\u5bb9\u5668\u4e2d\uff0c\u5e76\u5b89\u88c5\u4e86\u4f9d\u8d56\u5305\u3002\u6700\u540e\uff0c\u6211\u4eec\u8bbe\u7f6e\u4e86\u5bb9\u5668\u542f\u52a8\u65f6\u8fd0\u884c<code>app.py<\/code>\u811a\u672c\u3002<\/p>\n<\/p>\n<p><h4>2. \u6784\u5efa\u548c\u8fd0\u884cDocker\u955c\u50cf<\/h4>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6784\u5efaDocker\u955c\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">docker build -t myproject .<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u547d\u4ee4\u4e2d\uff0c<code>myproject<\/code>\u662f\u955c\u50cf\u7684\u540d\u79f0\uff0c<code>.<\/code>\u8868\u793a\u5f53\u524d\u76ee\u5f55\u3002<\/p>\n<\/p>\n<p><p>\u6784\u5efa\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8\u5bb9\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">docker run -it --rm myproject<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u547d\u4ee4\u4e2d\uff0c<code>-it<\/code>\u9009\u9879\u8868\u793a\u4ee5\u4ea4\u4e92\u6a21\u5f0f\u8fd0\u884c\u5bb9\u5668\uff0c<code>--rm<\/code>\u9009\u9879\u8868\u793a\u5bb9\u5668\u505c\u6b62\u540e\u81ea\u52a8\u5220\u9664\u3002<\/p>\n<\/p>\n<p><h4>3. \u4f7f\u7528Docker Compose<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684\u9879\u76ee\u4f9d\u8d56\u591a\u4e2a\u670d\u52a1\uff08\u4f8b\u5982\u6570\u636e\u5e93\u3001\u7f13\u5b58\u7b49\uff09\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528Docker Compose\u6765\u5b9a\u4e49\u548c\u7ba1\u7406\u8fd9\u4e9b\u670d\u52a1\u3002\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>docker-compose.yml<\/code>\u7684\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684<code>docker-compose.yml<\/code>\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-yaml\">version: &#39;3&#39;<\/p>\n<p>services:<\/p>\n<p>  app:<\/p>\n<p>    build: .<\/p>\n<p>    ports:<\/p>\n<p>      - &quot;5000:5000&quot;<\/p>\n<p>    volumes:<\/p>\n<p>      - .:\/app<\/p>\n<p>    environment:<\/p>\n<p>      - FLASK_ENV=development<\/p>\n<p>  db:<\/p>\n<p>    image: postgres:13<\/p>\n<p>    environment:<\/p>\n<p>      POSTGRES_USER: user<\/p>\n<p>      POSTGRES_PASSWORD: password<\/p>\n<p>      POSTGRES_DB: mydatabase<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e24\u4e2a\u670d\u52a1\uff1a<code>app<\/code>\u548c<code>db<\/code>\u3002<code>app<\/code>\u670d\u52a1\u4f7f\u7528\u6211\u4eec\u4e4b\u524d\u521b\u5efa\u7684Docker\u955c\u50cf\uff0c\u5e76\u6620\u5c04\u7aef\u53e35000\u3002<code>db<\/code>\u670d\u52a1\u4f7f\u7528\u5b98\u65b9\u7684PostgreSQL 13\u955c\u50cf\uff0c\u5e76\u8bbe\u7f6e\u4e86\u4e00\u4e9b\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><p>\u8981\u542f\u52a8\u6240\u6709\u670d\u52a1\uff0c\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">docker-compose up<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u6839\u636e<code>docker-compose.yml<\/code>\u6587\u4ef6\u542f\u52a8\u6240\u6709\u5b9a\u4e49\u7684\u670d\u52a1\u3002<\/p>\n<\/p>\n<p><p>\u8981\u505c\u6b62\u5e76\u5220\u9664\u6240\u6709\u670d\u52a1\uff0c\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">docker-compose down<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u81ea\u5b9a\u4e49Python\u89e3\u91ca\u5668<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u81ea\u5b9a\u4e49Python\u89e3\u91ca\u5668\u7684\u529f\u80fd\uff0c\u6dfb\u52a0\u6216\u4fee\u6539\u5176\u884c\u4e3a\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539Python\u6e90\u7801\u5e76\u91cd\u65b0\u7f16\u8bd1\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h4>1. \u4e0b\u8f7d\u548c\u4fee\u6539Python\u6e90\u7801<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7dPython\u7684\u6e90\u7801\u538b\u7f29\u5305\uff0c\u5e76\u89e3\u538b\u7f29\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">wget https:\/\/www.python.org\/ftp\/python\/3.9.7\/Python-3.9.7.tgz<\/p>\n<p>tar xzf Python-3.9.7.tgz<\/p>\n<p>cd Python-3.9.7<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u4f60\u53ef\u4ee5\u4fee\u6539\u6e90\u7801\u3002\u4f8b\u5982\uff0c\u7f16\u8f91<code>Python\/ceval.c<\/code>\u6587\u4ef6\uff0c\u6dfb\u52a0\u81ea\u5b9a\u4e49\u529f\u80fd\u6216\u4fee\u6539\u73b0\u6709\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h4>2. \u7f16\u8bd1\u548c\u5b89\u88c5\u81ea\u5b9a\u4e49Python\u89e3\u91ca\u5668<\/h4>\n<\/p>\n<p><p>\u4fee\u6539\u5b8c\u6210\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1\u548c\u5b89\u88c5\u81ea\u5b9a\u4e49Python\u89e3\u91ca\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">.\/configure --prefix=\/opt\/custom-python<\/p>\n<p>make<\/p>\n<p>make install<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u547d\u4ee4\u4e2d\uff0c<code>--prefix=\/opt\/custom-python<\/code>\u6307\u5b9a\u4e86\u81ea\u5b9a\u4e49\u5b89\u88c5\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u6765\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684Python\u89e3\u91ca\u5668\u3002\u4f8b\u5982\uff0c\u5c06\u4ee5\u4e0b\u884c\u6dfb\u52a0\u5230\u4f60\u7684<code>~\/.bashrc<\/code>\u6587\u4ef6\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PATH=\/opt\/custom-python\/bin:$PATH<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u91cd\u65b0\u52a0\u8f7d<code>~\/.bashrc<\/code>\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source ~\/.bashrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u73b0\u5728\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684Python\u89e3\u91ca\u5668\u548c\u5305\u7ba1\u7406\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528PyInstaller\u8fdb\u884c\u6253\u5305<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528PyInstaller\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5PyInstaller<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5b89\u88c5PyInstaller\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pyinstaller<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528PyInstaller\u6253\u5305\u5e94\u7528\u7a0b\u5e8f<\/h4>\n<\/p>\n<p><p>\u8981\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile app.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u547d\u4ee4\u4e2d\uff0c<code>--onefile<\/code>\u9009\u9879\u8868\u793a\u5c06\u6240\u6709\u4f9d\u8d56\u5305\u6253\u5305\u6210\u4e00\u4e2a\u5355\u72ec\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c<code>app.py<\/code>\u662f\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u5165\u53e3\u811a\u672c\u3002<\/p>\n<\/p>\n<p><p>\u6253\u5305\u5b8c\u6210\u540e\uff0c\u4f60\u4f1a\u5728<code>dist<\/code>\u76ee\u5f55\u4e2d\u627e\u5230\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>3. \u81ea\u5b9a\u4e49\u6253\u5305\u914d\u7f6e<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u9700\u8981\u66f4\u591a\u7684\u63a7\u5236\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684<code>spec<\/code>\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u751f\u6210\u4e00\u4e2a\u9ed8\u8ba4\u7684<code>spec<\/code>\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --name myapp app.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u547d\u4ee4\u4e2d\uff0c<code>--name myapp<\/code>\u9009\u9879\u6307\u5b9a\u4e86\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u7684\u540d\u79f0\u3002<\/p>\n<\/p>\n<p><p>\u751f\u6210\u7684<code>myapp.spec<\/code>\u6587\u4ef6\u5305\u542b\u4e86\u6253\u5305\u914d\u7f6e\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u4fee\u6539\u3002\u5b8c\u6210\u4fee\u6539\u540e\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684<code>spec<\/code>\u6587\u4ef6\u8fdb\u884c\u6253\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller myapp.spec<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528\u865a\u62df\u73af\u5883\u3001\u4fee\u6539\u5b89\u88c5\u8def\u5f84\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u3001\u4f7f\u7528Docker\u3001\u81ea\u5b9a\u4e49Python\u89e3\u91ca\u5668\u548c\u4f7f\u7528PyInstaller\u8fdb\u884c\u6253\u5305\uff0c\u4f60\u53ef\u4ee5\u5b9e\u73b0Python\u7684\u81ea\u5b9a\u4e49\u5b89\u88c5\u548c\u7ba1\u7406\u3002\u8fd9\u4e9b\u65b9\u6cd5\u4e0d\u4ec5\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\uff0c\u8fd8\u53ef\u4ee5\u63d0\u9ad8\u9879\u76ee\u7684\u53ef\u79fb\u690d\u6027\u548c\u7a33\u5b9a\u6027\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u4f7f\u4f60\u7684\u5f00\u53d1\u8fc7\u7a0b\u66f4\u52a0\u9ad8\u6548\u548c\u7075\u6d3b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u81ea\u5b9a\u4e49\u5b89\u88c5Python\u6709\u54ea\u4e9b\u6b65\u9aa4\uff1f<\/strong><br \/>\u81ea\u5b9a\u4e49\u5b89\u88c5Python\u7684\u6b65\u9aa4\u5305\u62ec\u4e0b\u8f7d\u5b98\u65b9\u5b89\u88c5\u5305\u3001\u9009\u62e9\u5b89\u88c5\u76ee\u5f55\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u548c\u9009\u62e9\u5b89\u88c5\u7ec4\u4ef6\u3002\u5728\u4e0b\u8f7dPython\u65f6\uff0c\u8bbf\u95ee\u5b98\u7f51\u5e76\u9009\u62e9\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u7248\u672c\u3002\u5b89\u88c5\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u81ea\u5b9a\u4e49\u5b89\u88c5\uff0c\u8bbe\u5b9a\u5b89\u88c5\u8def\u5f84\uff0c\u4ee5\u53ca\u9009\u62e9\u662f\u5426\u5b89\u88c5pip\u3001\u6587\u6863\u7b49\u989d\u5916\u7ec4\u4ef6\u3002\u5b8c\u6210\u5b89\u88c5\u540e\uff0c\u786e\u4fdd\u5c06Python\u7684\u5b89\u88c5\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u8fd9\u6837\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u4f7f\u7528Python\u3002<\/p>\n<p><strong>\u5728Windows\u548cMac\u4e0a\u81ea\u5b9a\u4e49\u5b89\u88c5Python\u6709\u4f55\u4e0d\u540c\uff1f<\/strong><br \/>\u5728Windows\u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b98\u65b9\u7684\u5b89\u88c5\u7a0b\u5e8f\u8fdb\u884c\u56fe\u5f62\u5316\u5b89\u88c5\uff0c\u9009\u62e9\u5b89\u88c5\u8def\u5f84\u548c\u7ec4\u4ef6\u3002\u800c\u5728Mac\u4e0a\uff0c\u901a\u5e38\u4f7f\u7528Homebrew\u6216\u76f4\u63a5\u4ece\u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5\u5305\u3002Mac\u7684\u5b89\u88c5\u8fc7\u7a0b\u76f8\u5bf9\u7b80\u5355\uff0c\u901a\u5e38\u53ea\u9700\u62d6\u653e\u5230\u5e94\u7528\u7a0b\u5e8f\u6587\u4ef6\u5939\u5373\u53ef\u3002\u6b64\u5916\uff0cWindows\u9700\u8981\u624b\u52a8\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u800cMac\u901a\u5e38\u4f1a\u81ea\u52a8\u914d\u7f6e\u3002<\/p>\n<p><strong>\u81ea\u5b9a\u4e49\u5b89\u88c5Python\u65f6\uff0c\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u7248\u672c\uff1f<\/strong><br \/>\u9009\u62e9\u5408\u9002\u7684Python\u7248\u672c\u65f6\uff0c\u5efa\u8bae\u6839\u636e\u60a8\u7684\u9879\u76ee\u9700\u6c42\u548c\u4f9d\u8d56\u5e93\u6765\u51b3\u5b9a\u3002\u5bf9\u4e8e\u65b0\u9879\u76ee\uff0c\u63a8\u8350\u4f7f\u7528\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u672c\uff0c\u4ee5\u4fbf\u4eab\u53d7\u6700\u65b0\u7684\u7279\u6027\u548c\u5b89\u5168\u66f4\u65b0\u3002\u5982\u679c\u60a8\u7684\u9879\u76ee\u4f9d\u8d56\u67d0\u4e9b\u7279\u5b9a\u5e93\uff0c\u52a1\u5fc5\u68c0\u67e5\u8fd9\u4e9b\u5e93\u662f\u5426\u652f\u6301\u8be5\u7248\u672c\u3002\u6b64\u5916\uff0c\u8003\u8651\u4f7f\u7528\u865a\u62df\u73af\u5883\u6765\u7ba1\u7406\u4e0d\u540c\u9879\u76ee\u6240\u9700\u7684Python\u7248\u672c\u548c\u5e93\uff0c\u4ee5\u907f\u514d\u51b2\u7a81\u548c\u517c\u5bb9\u6027\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u81ea\u5b9a\u4e49\u5b89\u88c5\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u865a\u62df\u73af\u5883\u3001\u4fee\u6539\u5b89\u88c5\u8def\u5f84\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u6765\u5b9e\u73b0\u3002 \u5176\u4e2d\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u662f\u6700\u5e38\u7528\u7684 [&hellip;]","protected":false},"author":3,"featured_media":1168727,"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\/1168721"}],"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=1168721"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1168721\/revisions"}],"predecessor-version":[{"id":1168728,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1168721\/revisions\/1168728"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1168727"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1168721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1168721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1168721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}