{"id":1101322,"date":"2025-01-08T15:48:34","date_gmt":"2025-01-08T07:48:34","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1101322.html"},"modified":"2025-01-08T15:48:44","modified_gmt":"2025-01-08T07:48:44","slug":"python%e5%a6%82%e4%bd%95%e9%93%be%e6%8e%a5%e7%ac%ac%e4%b8%89%e6%96%b9%e5%ba%93-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1101322.html","title":{"rendered":"python\u5982\u4f55\u94fe\u63a5\u7b2c\u4e09\u65b9\u5e93"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25064146\/15bae75e-d155-4f7d-8491-5563a62e4eb3.webp\" alt=\"python\u5982\u4f55\u94fe\u63a5\u7b2c\u4e09\u65b9\u5e93\" \/><\/p>\n<p><p> <strong>Python\u5982\u4f55\u94fe\u63a5\u7b2c\u4e09\u65b9\u5e93\uff1a\u901a\u8fc7pip\u5b89\u88c5\u3001\u4f7f\u7528import\u8bed\u53e5\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>Python\u4e2d\u94fe\u63a5\u7b2c\u4e09\u65b9\u5e93\u7684\u4e3b\u8981\u65b9\u5f0f\u6709\uff1a<strong>\u901a\u8fc7pip\u5b89\u88c5\u3001\u4f7f\u7528import\u8bed\u53e5\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883<\/strong>\u3002\u5176\u4e2d\uff0c\u901a\u8fc7pip\u5b89\u88c5\u662f\u6700\u5e38\u7528\u4e14\u4fbf\u6377\u7684\u65b9\u5f0f\u3002pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u4ecePython\u5305\u7d22\u5f15\uff08Python Package Index, PyPI\uff09\u4e2d\u4e0b\u8f7d\u5e76\u5b89\u88c5\u7b2c\u4e09\u65b9\u5e93\u3002\u4f7f\u7528import\u8bed\u53e5\u53ef\u4ee5\u5c06\u5b89\u88c5\u597d\u7684\u5e93\u5bfc\u5165\u5230\u4f60\u7684Python\u811a\u672c\u4e2d\uff0c\u65b9\u4fbf\u8c03\u7528\u5176\u529f\u80fd\u3002\u914d\u7f6e\u865a\u62df\u73af\u5883\u53ef\u4ee5\u4e3a\u4f60\u7684\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684\u5305\u7ba1\u7406\u73af\u5883\uff0c\u907f\u514d\u5305\u7684\u7248\u672c\u51b2\u7a81\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u901a\u8fc7pip\u5b89\u88c5<\/h3>\n<\/p>\n<p><p>pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u7528\u4e8e\u5b89\u88c5\u548c\u7ba1\u7406Python\u7684\u5305\u548c\u4f9d\u8d56\u9879\u3002\u5728\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u901a\u8fc7pip\u6765\u5b89\u88c5\u8fd9\u4e9b\u5e93\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5pip\u662f\u5426\u5b89\u88c5<\/strong>\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>pip --version<\/code>\uff0c\u5982\u679c\u663e\u793apip\u7684\u7248\u672c\u4fe1\u606f\uff0c\u8bf4\u660e\u5df2\u7ecf\u5b89\u88c5\u597dpip\uff1b\u5426\u5219\u9700\u8981\u5148\u5b89\u88c5pip\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u7b2c\u4e09\u65b9\u5e93<\/strong>\uff1a\u4f7f\u7528\u547d\u4ee4<code>pip install \u5e93\u540d<\/code>\u5373\u53ef\u5b89\u88c5\u6240\u9700\u7684\u7b2c\u4e09\u65b9\u5e93\u3002\u4f8b\u5982\uff0c\u5b89\u88c5requests\u5e93\uff0c\u8f93\u5165<code>pip install requests<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5e93<\/strong>\uff1a\u4f7f\u7528\u547d\u4ee4<code>pip list<\/code>\u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u73af\u5883\u4e0b\u6240\u6709\u5df2\u5b89\u88c5\u7684\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5347\u7ea7\u5e93<\/strong>\uff1a\u5982\u679c\u9700\u8981\u5347\u7ea7\u67d0\u4e2a\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>pip install --upgrade \u5e93\u540d<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5378\u8f7d\u5e93<\/strong>\uff1a\u5982\u679c\u4e0d\u518d\u9700\u8981\u67d0\u4e2a\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>pip uninstall \u5e93\u540d<\/code>\u6765\u5378\u8f7d\u8be5\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u4f7f\u7528import\u8bed\u53e5<\/h3>\n<\/p>\n<p><p>\u5b89\u88c5\u597d\u7b2c\u4e09\u65b9\u5e93\u540e\uff0c\u9700\u8981\u5728Python\u4ee3\u7801\u4e2d\u5bfc\u5165\u8fd9\u4e9b\u5e93\u624d\u80fd\u4f7f\u7528\u5b83\u4eec\u7684\u529f\u80fd\u3002\u5bfc\u5165\u5e93\u7684\u65b9\u5f0f\u662f\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5bfc\u5165\u6574\u4e2a\u5e93<\/strong>\uff1a\u6700\u7b80\u5355\u7684\u5bfc\u5165\u65b9\u5f0f\u662f\u76f4\u63a5\u4f7f\u7528<code>import \u5e93\u540d<\/code>\uff0c\u4f8b\u5982<code>import requests<\/code>\u3002\u8fd9\u6837\u5bfc\u5165\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u5e93\u540d\u6765\u8c03\u7528\u5176\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u5165\u5e93\u7684\u90e8\u5206\u529f\u80fd<\/strong>\uff1a\u6709\u65f6\u53ea\u9700\u8981\u4f7f\u7528\u5e93\u4e2d\u7684\u67d0\u4e2a\u6a21\u5757\u6216\u51fd\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7<code>from \u5e93\u540d import \u6a21\u5757\/\u51fd\u6570<\/code>\u7684\u65b9\u5f0f\u5bfc\u5165\u3002\u4f8b\u5982\uff0c<code>from math import sqrt<\/code>\u8868\u793a\u53ea\u5bfc\u5165math\u5e93\u4e2d\u7684sqrt\u51fd\u6570\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u522b\u540d<\/strong>\uff1a\u4e3a\u4e86\u7b80\u5316\u4ee3\u7801\uff0c\u53ef\u4ee5\u7ed9\u5bfc\u5165\u7684\u5e93\u6216\u6a21\u5757\u8d77\u4e00\u4e2a\u522b\u540d\u3002\u4f7f\u7528<code>import \u5e93\u540d as \u522b\u540d<\/code>\u7684\u65b9\u5f0f\uff0c\u4f8b\u5982<code>import numpy as np<\/code>\uff0c\u8fd9\u6837\u5728\u540e\u7eed\u4ee3\u7801\u4e2d\u53ef\u4ee5\u4f7f\u7528\u522b\u540dnp\u6765\u4ee3\u66ffnumpy\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u914d\u7f6e\u865a\u62df\u73af\u5883\u662f\u4e3a\u4e86\u5728\u4e0d\u540c\u9879\u76ee\u4e2d\u4f7f\u7528\u4e0d\u540c\u7248\u672c\u7684\u5305\uff0c\u907f\u514d\u5305\u7684\u7248\u672c\u51b2\u7a81\u3002\u865a\u62df\u73af\u5883\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684\u5305\u7ba1\u7406\u73af\u5883\u3002\u5e38\u7528\u7684\u865a\u62df\u73af\u5883\u7ba1\u7406\u5de5\u5177\u6709virtualenv\u548cvenv\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5virtualenv<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528pip\u6765\u5b89\u88c5virtualenv\uff0c\u547d\u4ee4\u662f<code>pip install virtualenv<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u4f7f\u7528\u547d\u4ee4<code>virtualenv \u73af\u5883\u540d<\/code>\u6765\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u4f8b\u5982<code>virtualenv venv<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\u8fdb\u5165\u9879\u76ee\u76ee\u5f55\uff0c\u4f7f\u7528\u547d\u4ee4<code>source \u73af\u5883\u540d\/bin\/activate<\/code>\u6765\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff0c\u4f8b\u5982<code>source venv\/bin\/activate<\/code>\uff08Windows\u7cfb\u7edf\u4e0b\u662f<code>venv\\Scripts\\activate<\/code>\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u5305<\/strong>\uff1a\u5728\u6fc0\u6d3b\u7684\u865a\u62df\u73af\u5883\u4e2d\u4f7f\u7528pip\u6765\u5b89\u88c5\u6240\u9700\u7684\u5305\uff0c\u8fd9\u6837\u5b89\u88c5\u7684\u5305\u53ea\u5728\u8be5\u865a\u62df\u73af\u5883\u4e2d\u53ef\u7528\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5168\u5c40\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u4f7f\u7528\u547d\u4ee4<code>deactivate<\/code>\u53ef\u4ee5\u9000\u51fa\u865a\u62df\u73af\u5883\uff0c\u8fd4\u56de\u5230\u5168\u5c40\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6cd5<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f51\u7edc\u95ee\u9898\u5bfc\u81f4pip\u5b89\u88c5\u5931\u8d25<\/strong>\uff1a\u53ef\u4ee5\u5c1d\u8bd5\u66f4\u6362pip\u7684\u4e0b\u8f7d\u6e90\uff0c\u4f8b\u5982\u4f7f\u7528\u56fd\u5185\u7684\u955c\u50cf\u6e90\u3002\u5e38\u7528\u7684\u955c\u50cf\u6e90\u6709\u8c46\u74e3\u3001\u6e05\u534e\u7b49\u3002\u4f7f\u7528<code>pip install -i \u955c\u50cf\u6e90\u5730\u5740 \u5e93\u540d<\/code>\u6765\u5b89\u88c5\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6743\u9650\u95ee\u9898<\/strong>\uff1a\u5728\u67d0\u4e9b\u7cfb\u7edf\u4e2d\uff0c\u5b89\u88c5\u5e93\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u6743\u9650\u95ee\u9898\u3002\u53ef\u4ee5\u4f7f\u7528<code>sudo pip install \u5e93\u540d<\/code>\u6765\u63d0\u5347\u6743\u9650\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5305\u7248\u672c\u51b2\u7a81<\/strong>\uff1a\u5728\u4e00\u4e2a\u9879\u76ee\u4e2d\u4f7f\u7528\u591a\u4e2a\u5305\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5305\u7248\u672c\u51b2\u7a81\u7684\u95ee\u9898\u3002\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u865a\u62df\u73af\u5883\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u786e\u4fdd\u6bcf\u4e2a\u9879\u76ee\u4f7f\u7528\u72ec\u7acb\u7684\u5305\u7ba1\u7406\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5e93\u7684\u4f9d\u8d56\u95ee\u9898<\/strong>\uff1a\u67d0\u4e9b\u7b2c\u4e09\u65b9\u5e93\u53ef\u80fd\u4f9d\u8d56\u5176\u4ed6\u5e93\uff0c\u5b89\u88c5\u65f6\u9700\u8981\u4e00\u8d77\u5b89\u88c5\u8fd9\u4e9b\u4f9d\u8d56\u5e93\u3002pip\u4f1a\u81ea\u52a8\u5904\u7406\u4f9d\u8d56\u95ee\u9898\uff0c\u4f46\u6709\u65f6\u9700\u8981\u624b\u52a8\u6307\u5b9a\u4f9d\u8d56\u5e93\u7684\u7248\u672c\u3002\u53ef\u4ee5\u5728\u5b89\u88c5\u65f6\u4f7f\u7528<code>pip install \u5e93\u540d==\u7248\u672c\u53f7<\/code>\u6765\u6307\u5b9a\u5e93\u7684\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u627e\u5e93\u7684\u6587\u6863\u548c\u793a\u4f8b<\/strong>\uff1a\u5728\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u65f6\uff0c\u67e5\u9605\u5b98\u65b9\u6587\u6863\u548c\u793a\u4f8b\u4ee3\u7801\u662f\u975e\u5e38\u6709\u5e2e\u52a9\u7684\u3002\u5927\u591a\u6570\u5e93\u5728PyPI\u9875\u9762\u4e0a\u90fd\u6709\u8be6\u7ec6\u7684\u6587\u6863\u94fe\u63a5\u548c\u793a\u4f8b\u4ee3\u7801\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u793a\u4f8b\u4ee3\u7801<\/h3>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528requests\u5e93\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u901a\u8fc7pip\u5b89\u88c5\u5e93\u3001\u5bfc\u5165\u5e93\u5e76\u4f7f\u7528\u5176\u529f\u80fd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b89\u88c5requests\u5e93<\/p>\n<h2><strong>pip install requests<\/strong><\/h2>\n<h2><strong>\u5bfc\u5165requests\u5e93<\/strong><\/h2>\n<p>import requests<\/p>\n<h2><strong>\u4f7f\u7528requests\u5e93\u53d1\u9001HTTP\u8bf7\u6c42<\/strong><\/h2>\n<p>response = requests.get(&#39;https:\/\/api.github.com&#39;)<\/p>\n<h2><strong>\u8f93\u51fa\u54cd\u5e94\u5185\u5bb9<\/strong><\/h2>\n<p>print(response.text)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u9996\u5148\u901a\u8fc7pip\u5b89\u88c5requests\u5e93\uff0c\u7136\u540e\u5728\u4ee3\u7801\u4e2d\u5bfc\u5165requests\u5e93\uff0c\u6700\u540e\u4f7f\u7528requests\u5e93\u53d1\u9001\u4e00\u4e2aHTTP GET\u8bf7\u6c42\uff0c\u5e76\u8f93\u51fa\u54cd\u5e94\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u8fdb\u9636\u4f7f\u7528<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efarequirements.txt\u6587\u4ef6<\/strong>\uff1a\u5728\u9879\u76ee\u4e2d\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2arequirements.txt\u6587\u4ef6\u6765\u5217\u51fa\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u7b2c\u4e09\u65b9\u5e93\u53ca\u5176\u7248\u672c\u53f7\u3002\u4f7f\u7528<code>pip freeze &gt; requirements.txt<\/code>\u547d\u4ee4\u53ef\u4ee5\u751f\u6210\u8be5\u6587\u4ef6\u3002\u5176\u4ed6\u4eba\u53ef\u4ee5\u901a\u8fc7<code>pip install -r requirements.txt<\/code>\u6765\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528pipenv\u7ba1\u7406\u865a\u62df\u73af\u5883<\/strong>\uff1apipenv\u662f\u4e00\u4e2a\u96c6\u6210\u4e86pip\u548cvirtualenv\u7684\u5de5\u5177\uff0c\u7528\u4e8e\u7b80\u5316\u865a\u62df\u73af\u5883\u7684\u7ba1\u7406\u548c\u4f9d\u8d56\u9879\u7684\u5b89\u88c5\u3002\u4f7f\u7528<code>pip install pipenv<\/code>\u5b89\u88c5pipenv\uff0c\u7136\u540e\u4f7f\u7528<code>pipenv install \u5e93\u540d<\/code>\u6765\u5b89\u88c5\u5e93\u5e76\u81ea\u52a8\u521b\u5efa\u548c\u7ba1\u7406\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528conda\u7ba1\u7406\u5305\u548c\u73af\u5883<\/strong>\uff1aconda\u662fAnaconda\u53d1\u884c\u7248\u4e2d\u7684\u5305\u548c\u73af\u5883\u7ba1\u7406\u5668\uff0c\u9002\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\u3002\u4f7f\u7528<code>conda create -n \u73af\u5883\u540d python=\u7248\u672c\u53f7<\/code>\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u4f7f\u7528<code>conda install \u5e93\u540d<\/code>\u5b89\u88c5\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9605\u8bfb\u5e93\u7684\u6e90\u7801<\/strong>\uff1a\u5728\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u65f6\uff0c\u9605\u8bfb\u5e93\u7684\u6e90\u7801\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u5176\u5b9e\u73b0\u539f\u7406\u548c\u7528\u6cd5\u3002\u5927\u591a\u6570\u5e93\u7684\u6e90\u7801\u90fd\u6258\u7ba1\u5728GitHub\u7b49\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\u4e0a\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u67e5\u770b\u548c\u5b66\u4e60\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8d21\u732e\u5f00\u6e90\u9879\u76ee<\/strong>\uff1a\u5982\u679c\u4f60\u5bf9\u67d0\u4e2a\u7b2c\u4e09\u65b9\u5e93\u6709\u6539\u8fdb\u5efa\u8bae\u6216\u53d1\u73b0\u4e86bug\uff0c\u53ef\u4ee5\u901a\u8fc7\u63d0\u4ea4pull request\u7684\u65b9\u5f0f\u4e3a\u5f00\u6e90\u9879\u76ee\u505a\u51fa\u8d21\u732e\u3002\u8fd9\u4e0d\u4ec5\u53ef\u4ee5\u63d0\u9ad8\u4f60\u7684\u6280\u672f\u6c34\u5e73\uff0c\u8fd8\u53ef\u4ee5\u5e2e\u52a9\u5176\u4ed6\u5f00\u53d1\u8005\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7pip\u5b89\u88c5\u3001\u4f7f\u7528import\u8bed\u53e5\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883\u662fPython\u4e2d\u94fe\u63a5\u7b2c\u4e09\u65b9\u5e93\u7684\u4e3b\u8981\u65b9\u5f0f\u3002\u901a\u8fc7pip\u5b89\u88c5\u5e93\u975e\u5e38\u65b9\u4fbf\uff0cimport\u8bed\u53e5\u53ef\u4ee5\u8f7b\u677e\u5bfc\u5165\u5e93\uff0c\u914d\u7f6e\u865a\u62df\u73af\u5883\u53ef\u4ee5\u907f\u514d\u5305\u7248\u672c\u51b2\u7a81\u3002\u5b66\u4e60\u548c\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8ba9\u4f60\u5728Python\u5f00\u53d1\u4e2d\u66f4\u52a0\u9ad8\u6548\u5730\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u63d0\u9ad8\u4f60\u7684Python\u5f00\u53d1\u6280\u80fd\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b89\u88c5\u7b2c\u4e09\u65b9\u5e93\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u5b89\u88c5\u7b2c\u4e09\u65b9\u5e93\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177pip\u3002\u9996\u5148\uff0c\u786e\u4fdd\u60a8\u7684\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5\u4e86Python\u548cpip\u3002\u6253\u5f00\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\uff0c\u8f93\u5165\u201cpip install \u5e93\u540d\u201d\uff0c\u5c06\u201c\u5e93\u540d\u201d\u66ff\u6362\u4e3a\u60a8\u60f3\u8981\u5b89\u88c5\u7684\u5e93\u7684\u540d\u79f0\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u60f3\u5b89\u88c5Requests\u5e93\uff0c\u53ef\u4ee5\u8f93\u5165\u201cpip install requests\u201d\u3002\u5b89\u88c5\u6210\u529f\u540e\uff0c\u60a8\u5c31\u53ef\u4ee5\u5728\u60a8\u7684Python\u4ee3\u7801\u4e2d\u5bfc\u5165\u548c\u4f7f\u7528\u8be5\u5e93\u4e86\u3002<\/p>\n<p><strong>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u65f6\uff0c\u786e\u4fdd\u60a8\u9009\u62e9\u7684\u5e93\u662f\u6d3b\u8dc3\u7ef4\u62a4\u7684\uff0c\u5e76\u4e14\u6709\u826f\u597d\u7684\u6587\u6863\u652f\u6301\u3002\u6b64\u5916\uff0c\u6ce8\u610f\u5e93\u7684\u7248\u672c\u517c\u5bb9\u6027\uff0c\u6709\u4e9b\u5e93\u53ef\u80fd\u53ea\u652f\u6301\u7279\u5b9a\u7248\u672c\u7684Python\u6216\u5176\u4ed6\u5e93\u3002\u5982\u679c\u53d1\u73b0\u5e93\u5b58\u5728bug\u6216\u6027\u80fd\u95ee\u9898\uff0c\u53ef\u4ee5\u8003\u8651\u67e5\u770b\u76f8\u5173\u793e\u533a\u7684\u8ba8\u8bba\u6216\u63d0\u4ea4\u95ee\u9898\u4ee5\u5bfb\u6c42\u5e2e\u52a9\u3002<\/p>\n<p><strong>\u5982\u4f55\u7ba1\u7406Python\u9879\u76ee\u4e2d\u7684\u7b2c\u4e09\u65b9\u5e93\u4f9d\u8d56\uff1f<\/strong><br \/>\u7ba1\u7406Python\u9879\u76ee\u4e2d\u7684\u7b2c\u4e09\u65b9\u5e93\u4f9d\u8d56\u53ef\u4ee5\u4f7f\u7528requirements.txt\u6587\u4ef6\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u201cpip freeze &gt; requirements.txt\u201d\u547d\u4ee4\u6765\u751f\u6210\u6b64\u6587\u4ef6\uff0c\u6587\u4ef6\u4e2d\u5c06\u5217\u51fa\u60a8\u5f53\u524d\u73af\u5883\u4e2d\u6240\u6709\u5df2\u5b89\u88c5\u7684\u5e93\u53ca\u5176\u7248\u672c\u3002\u5176\u4ed6\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u201cpip install -r requirements.txt\u201d\u547d\u4ee4\u6765\u5b89\u88c5\u76f8\u540c\u7684\u4f9d\u8d56\u5e93\uff0c\u786e\u4fdd\u9879\u76ee\u5728\u4e0d\u540c\u73af\u5883\u4e2d\u7684\u4e00\u81f4\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5982\u4f55\u94fe\u63a5\u7b2c\u4e09\u65b9\u5e93\uff1a\u901a\u8fc7pip\u5b89\u88c5\u3001\u4f7f\u7528import\u8bed\u53e5\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883 Python\u4e2d\u94fe\u63a5\u7b2c\u4e09\u65b9\u5e93\u7684 [&hellip;]","protected":false},"author":3,"featured_media":1101335,"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\/1101322"}],"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=1101322"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1101322\/revisions"}],"predecessor-version":[{"id":1101341,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1101322\/revisions\/1101341"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1101335"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1101322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1101322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1101322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}