{"id":976970,"date":"2024-12-27T06:25:47","date_gmt":"2024-12-26T22:25:47","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/976970.html"},"modified":"2024-12-27T06:25:49","modified_gmt":"2024-12-26T22:25:49","slug":"%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85python%e9%99%84%e5%8a%a0%e5%8c%85","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/976970.html","title":{"rendered":"\u5982\u4f55\u5b89\u88c5python\u9644\u52a0\u5305"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24202434\/7bea22cc-627c-48de-8c12-dae025b476cd.webp\" alt=\"\u5982\u4f55\u5b89\u88c5python\u9644\u52a0\u5305\" \/><\/p>\n<p><p> <strong>\u5b89\u88c5Python\u9644\u52a0\u5305\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177pip\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3001\u4ece\u6e90\u4ee3\u7801\u5b89\u88c5\u3001\u4f7f\u7528Anaconda\u5b89\u88c5\u3002<\/strong>\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528pip\u662f\u6700\u5e38\u7528\u7684\u65b9\u5f0f\uff0c\u5b83\u53ef\u4ee5\u4ecePython Package Index\uff08PyPI\uff09\u4e2d\u5b89\u88c5\u548c\u7ba1\u7406\u5305\u3002\u6b64\u5916\uff0c\u521b\u5efa\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5e2e\u52a9\u60a8\u9694\u79bb\u9879\u76ee\u4f9d\u8d56\uff0c\u9632\u6b62\u5305\u4e4b\u95f4\u7684\u51b2\u7a81\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528PIP\u5b89\u88c5<\/p>\n<\/p>\n<p><p>PIP\u662fPython\u7684\u5305\u7ba1\u7406\u7cfb\u7edf\uff0c\u5141\u8bb8\u60a8\u5b89\u88c5\u548c\u7ba1\u7406\u4e0d\u5728Python\u6807\u51c6\u5e93\u4e2d\u7684\u8f6f\u4ef6\u5305\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5PIP<\/strong><br \/>\u901a\u5e38\uff0cPython\u5728\u5b89\u88c5\u65f6\u4f1a\u81ea\u52a8\u5b89\u88c5pip\u3002\u5982\u679c\u6ca1\u6709\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4e0b\u8f7dget-pip.py\u811a\u672c\u5e76\u8fd0\u884c<code>python get-pip.py<\/code>\u6765\u5b89\u88c5\u5b83\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u57fa\u672c\u7684PIP\u547d\u4ee4<\/strong><\/p>\n<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\u5b89\u88c5\u5305\uff1a\u8fd0\u884c<code>pip install package_name<\/code>\u3002<\/li>\n<li>\u5347\u7ea7\u5305\uff1a\u4f7f\u7528<code>pip install --upgrade package_name<\/code>\u3002<\/li>\n<li>\u5378\u8f7d\u5305\uff1a\u901a\u8fc7<code>pip uninstall package_name<\/code>\u3002<\/li>\n<li>\u5217\u51fa\u5df2\u5b89\u88c5\u7684\u5305\uff1a<code>pip list<\/code>\u3002<\/li>\n<\/ul>\n<ol start=\"3\">\n<li>\n<p><strong>\u5b89\u88c5\u7279\u5b9a\u7248\u672c<\/strong><br \/>\u5982\u679c\u9700\u8981\u5b89\u88c5\u7279\u5b9a\u7248\u672c\u7684\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\uff1a<code>pip install package_name==version_number<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4ecerequirements.txt\u5b89\u88c5<\/strong><br \/>\u8bb8\u591a\u9879\u76ee\u4f7f\u7528requirements.txt\u6587\u4ef6\u5217\u51fa\u6240\u6709\u4f9d\u8d56\u5305\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7<code>pip install -r requirements.txt<\/code>\u6765\u4e00\u6b21\u6027\u5b89\u88c5\u6240\u6709\u4f9d\u8d56\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u521b\u5efa\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p>\u865a\u62df\u73af\u5883\u5141\u8bb8\u60a8\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684\u5305\u7a7a\u95f4\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u7684\u4f9d\u8d56\u51b2\u7a81\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><br \/>\u4f7f\u7528<code>python -m venv env_name<\/code>\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>Windows\uff1a<code>env_name\\Scripts\\activate<\/code><\/li>\n<li>macOS\/Linux\uff1a<code>source env_name\/bin\/activate<\/code><\/li>\n<\/ul>\n<ol start=\"3\">\n<li>\n<p><strong>\u5728\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u5305<\/strong><br \/>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528pip\u5b89\u88c5\u5305\uff0c\u8fd9\u4e9b\u5305\u4ec5\u5728\u8be5\u865a\u62df\u73af\u5883\u4e2d\u53ef\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong><br \/>\u901a\u8fc7\u8fd0\u884c<code>deactivate<\/code>\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4ece\u6e90\u4ee3\u7801\u5b89\u88c5<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u4ece\u6e90\u4ee3\u7801\u5b89\u88c5\u5305\uff0c\u4f8b\u5982\uff0c\u5f53\u5305\u5728PyPI\u4e2d\u4e0d\u53ef\u7528\u6216\u60a8\u9700\u8981\u4fee\u6539\u5305\u7684\u6e90\u4ee3\u7801\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7d\u6e90\u4ee3\u7801<\/strong><br \/>\u4ece\u9879\u76ee\u7684GitHub\u4ed3\u5e93\u6216\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6e90\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u89e3\u538b\u7f29\u6587\u4ef6<\/strong><br \/>\u5982\u679c\u6e90\u4ee3\u7801\u662f\u538b\u7f29\u6587\u4ef6\uff0c\u9996\u5148\u89e3\u538b\u7f29\u5b83\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u5b89\u88c5\u547d\u4ee4<\/strong><br \/>\u5728\u89e3\u538b\u7f29\u7684\u6e90\u4ee3\u7801\u76ee\u5f55\u4e2d\uff0c\u8fd0\u884c<code>python setup.py install<\/code>\u6765\u5b89\u88c5\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528Anaconda\u5b89\u88c5<\/p>\n<\/p>\n<p><p>Anaconda\u662f\u4e00\u79cd\u6d41\u884c\u7684\u6570\u636e\u79d1\u5b66\u5e73\u53f0\uff0c\u5305\u542b\u8bb8\u591a\u9884\u88c5\u7684\u79d1\u5b66\u8ba1\u7b97\u5305\uff0c\u5e76\u63d0\u4f9bconda\u4f5c\u4e3a\u5305\u7ba1\u7406\u5de5\u5177\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Anaconda<\/strong><br \/>\u4eceAnaconda\u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5\u5305\u5e76\u5b8c\u6210\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Conda\u5b89\u88c5\u5305<\/strong><\/p>\n<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\u5b89\u88c5\u5305\uff1a\u8fd0\u884c<code>conda install package_name<\/code>\u3002<\/li>\n<li>\u66f4\u65b0\u5305\uff1a\u4f7f\u7528<code>conda update package_name<\/code>\u3002<\/li>\n<li>\u5220\u9664\u5305\uff1a\u901a\u8fc7<code>conda remove package_name<\/code>\u3002<\/li>\n<\/ul>\n<ol start=\"3\">\n<li>\n<p><strong>\u521b\u5efaConda\u73af\u5883<\/strong><br \/>\u4f7f\u7528<code>conda create --name env_name<\/code>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Conda\u73af\u5883\uff0c\u5e76\u901a\u8fc7<code>conda activate env_name<\/code>\u6fc0\u6d3b\u5b83\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4ece\u73af\u5883\u6587\u4ef6\u5b89\u88c5<\/strong><br \/>\u548cpip\u7c7b\u4f3c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>conda env create -f environment.yml<\/code>\u4eceenvironment.yml\u6587\u4ef6\u521b\u5efa\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5b89\u88c5Python\u9644\u52a0\u5305\u7684\u65b9\u6cd5\u591a\u79cd\u591a\u6837\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/23316.html\" target=\"_blank\">\u9879\u76ee\u7ba1\u7406<\/a>\u7684\u4fbf\u5229\u6027\u3002<strong>\u4f7f\u7528pip\u548c\u865a\u62df\u73af\u5883\u662f\u6700\u5e38\u7528\u7684\u7ec4\u5408\u65b9\u5f0f<\/strong>\uff0c\u9002\u5408\u5927\u591a\u6570\u5f00\u53d1\u573a\u666f\uff1b<strong>\u800cAnaconda\u5219\u66f4\u9002\u5408\u4e8e\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u9886\u57df<\/strong>\uff0c\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u9884\u88c5\u5305\u548c\u73af\u5883\u7ba1\u7406\u529f\u80fd\u3002\u65e0\u8bba\u9009\u62e9\u4f55\u79cd\u65b9\u5f0f\uff0c\u786e\u4fdd\u5b9a\u671f\u66f4\u65b0\u548c\u7ef4\u62a4\u60a8\u7684\u5305\u4f9d\u8d56\uff0c\u4ee5\u4fdd\u6301\u9879\u76ee\u7684\u5b89\u5168\u6027\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684Python\u9644\u52a0\u5305\u8fdb\u884c\u5b89\u88c5\uff1f<\/strong><br \/>\u5728\u9009\u62e9Python\u9644\u52a0\u5305\u65f6\uff0c\u60a8\u53ef\u4ee5\u5148\u786e\u5b9a\u60a8\u7684\u9879\u76ee\u9700\u6c42\uff0c\u4f8b\u5982\u6570\u636e\u5904\u7406\u3001\u7f51\u9875\u5f00\u53d1\u6216\u673a\u5668\u5b66\u4e60\u7b49\u3002\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95eePyPI\uff08Python Package Index\uff09\u7f51\u7ad9\uff0c\u641c\u7d22\u76f8\u5173\u7684\u5305\uff0c\u5e76\u67e5\u770b\u5b83\u4eec\u7684\u6587\u6863\u3001\u8bc4\u5206\u548c\u7528\u6237\u8bc4\u4ef7\u3002\u8fd9\u6837\u53ef\u4ee5\u5e2e\u52a9\u60a8\u9009\u62e9\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u4e14\u53ef\u9760\u7684\u9644\u52a0\u5305\u3002<\/p>\n<p><strong>\u5b89\u88c5Python\u9644\u52a0\u5305\u65f6\u5e38\u89c1\u7684\u95ee\u9898\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u5728\u5b89\u88c5Python\u9644\u52a0\u5305\u65f6\uff0c\u60a8\u53ef\u80fd\u4f1a\u9047\u5230\u4f9d\u8d56\u5173\u7cfb\u51b2\u7a81\u3001\u7f51\u7edc\u8fde\u63a5\u95ee\u9898\u6216\u6743\u9650\u4e0d\u8db3\u7b49\u95ee\u9898\u3002\u786e\u4fdd\u60a8\u4f7f\u7528\u7684\u662f\u6700\u65b0\u7248\u672c\u7684pip\uff0c\u5e76\u4e14\u5728\u5b89\u88c5\u65f6\u4f7f\u7528\u865a\u62df\u73af\u5883\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u4e0e\u7cfb\u7edf\u5176\u4ed6\u5305\u53d1\u751f\u51b2\u7a81\u3002\u6b64\u5916\uff0c\u67e5\u770b\u9519\u8bef\u6d88\u606f\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\uff0c\u5e76\u627e\u5230\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u5b89\u88c5Python\u9644\u52a0\u5305\uff1f<\/strong><br \/>\u5728Windows\u3001macOS\u6216Linux\u4e0a\u5b89\u88c5Python\u9644\u52a0\u5305\u7684\u65b9\u6cd5\u5927\u81f4\u76f8\u540c\uff0c\u4e3b\u8981\u662f\u4f7f\u7528pip\u547d\u4ee4\u3002\u4f8b\u5982\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u7ec8\u7aef\uff0c\u5e76\u8f93\u5165<code>pip install package_name<\/code>\u3002\u5728Windows\u4e0a\uff0c\u786e\u4fdd\u60a8\u7684Python\u548cpip\u5df2\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\uff1b\u5728macOS\u548cLinux\u4e0a\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u4f7f\u7528<code>sudo<\/code>\u6765\u83b7\u53d6\u7ba1\u7406\u5458\u6743\u9650\uff0c\u6216\u8005\u4f7f\u7528\u865a\u62df\u73af\u5883\u6765\u5b89\u88c5\u5305\uff0c\u786e\u4fdd\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u73af\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5b89\u88c5Python\u9644\u52a0\u5305\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177pip\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3001\u4ece\u6e90\u4ee3\u7801\u5b89\u88c5\u3001\u4f7f\u7528Anaconda\u5b89\u88c5\u3002 [&hellip;]","protected":false},"author":3,"featured_media":976980,"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\/976970"}],"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=976970"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/976970\/revisions"}],"predecessor-version":[{"id":976982,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/976970\/revisions\/976982"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/976980"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=976970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=976970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=976970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}