{"id":1013774,"date":"2024-12-27T11:50:44","date_gmt":"2024-12-27T03:50:44","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1013774.html"},"modified":"2024-12-27T11:50:46","modified_gmt":"2024-12-27T03:50:46","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e4%b8%8b%e5%8c%85","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1013774.html","title":{"rendered":"Python\u4e2d\u5982\u4f55\u4e0b\u5305"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25094103\/9be3b9d4-a602-490d-9ac8-17978d16d28c.webp\" alt=\"Python\u4e2d\u5982\u4f55\u4e0b\u5305\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u4e0b\u5305\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528pip\u3001conda\u3001\u624b\u52a8\u4e0b\u8f7d\u5e76\u5b89\u88c5\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u8fdb\u884c\u7ba1\u7406\u3002<\/strong>\u5176\u4e2d\uff0c<strong>\u4f7f\u7528pip\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5<\/strong>\uff0c\u56e0\u4e3a\u5b83\u662fPython\u5b98\u65b9\u63a8\u8350\u7684\u5305\u7ba1\u7406\u5de5\u5177\u3002\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3pip\u7684\u4f7f\u7528\uff0c\u6211\u4eec\u53ef\u4ee5\u5c55\u5f00\u4e00\u4e0b\u5176\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><p>\u8981\u4f7f\u7528pip\u5b89\u88c5Python\u5305\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86pip\u3002\u901a\u5e38\uff0cpip\u4f1a\u968f\u7740Python\u7684\u5b89\u88c5\u81ea\u52a8\u5b89\u88c5\u3002\u5982\u679c\u6ca1\u6709\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u8f7dget-pip.py\u811a\u672c\u5e76\u8fd0\u884c\u6765\u624b\u52a8\u5b89\u88c5\u3002\u5b89\u88c5\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u4f7f\u7528pip install <package_name>\u6765\u5b89\u88c5\u6240\u9700\u7684Python\u5305\u3002\u4f8b\u5982\uff0cpip install numpy\u5c06\u4f1a\u5b89\u88c5NumPy\u5e93\u3002\u5b89\u88c5\u6210\u529f\u540e\uff0c\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u901a\u8fc7import\u8bed\u53e5\u4f7f\u7528\u76f8\u5e94\u7684\u5305\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e00\u3001\u4f7f\u7528PIP\u5b89\u88c5\u5305<\/p>\n<\/p>\n<p><p>pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u80fd\u591f\u4ecePython Package Index (PyPI)\u4e0b\u8f7d\u5e76\u5b89\u88c5\u5305\u3002\u5b83\u7b80\u5355\u6613\u7528\uff0c\u662f\u8bb8\u591a\u5f00\u53d1\u8005\u7684\u9996\u9009\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5pip<\/strong><\/p>\n<\/p>\n<p><p>\u7edd\u5927\u591a\u6570Python\u53d1\u884c\u7248\u90fd\u81ea\u5e26pip\u3002\u7136\u800c\uff0c\u5982\u679c\u4f60\u7684Python\u7248\u672c\u6ca1\u6709pip\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u4e0b\u8f7dget-pip.py\u811a\u672c\u3002<\/li>\n<li>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\uff1a<code>python get-pip.py<\/code>\u3002<\/li>\n<\/ul>\n<p><p>\u786e\u4fdd\u4f60\u7684Python\u8def\u5f84\u5df2\u7ecf\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u4f7f\u7528pip\u547d\u4ee4\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528pip\u5b89\u88c5\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u65e6pip\u5b89\u88c5\u5b8c\u6bd5\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u5b89\u88c5Python\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5b89\u88c5requests\u5e93\uff0c\u53ef\u4ee5\u6267\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5347\u7ea7\u548c\u5378\u8f7d\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528pip\u4e0d\u4ec5\u53ef\u4ee5\u5b89\u88c5\uff0c\u8fd8\u53ef\u4ee5\u5347\u7ea7\u548c\u5378\u8f7d\u5305\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5347\u7ea7\u5305\uff1a<code>pip install --upgrade package_name<\/code><\/li>\n<li>\u5378\u8f7d\u5305\uff1a<code>pip uninstall package_name<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528CONDA\u7ba1\u7406\u5305<\/p>\n<\/p>\n<p><p>Conda\u662f\u4e00\u4e2a\u5f00\u6e90\u5305\u7ba1\u7406\u7cfb\u7edf\u548c\u73af\u5883\u7ba1\u7406\u7cfb\u7edf\uff0c\u5e38\u7528\u4e8eAnaconda\u548cMiniconda\u53d1\u884c\u7248\u4e2d\u3002\u5b83\u4e0d\u4ec5\u53ef\u4ee5\u7ba1\u7406Python\u5305\uff0c\u8fd8\u652f\u6301\u5176\u4ed6\u8bed\u8a00\u7684\u5305\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Conda<\/strong><\/p>\n<\/p>\n<p><p>Anaconda\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python\u53d1\u884c\u7248\uff0c\u5176\u4e2d\u5305\u542bConda\u3002\u53ef\u4ee5\u4eceAnaconda\u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5\u5305\u3002\u6216\u8005\uff0c\u5982\u679c\u4f60\u4ec5\u9700\u8981Conda\u800c\u4e0d\u9700\u8981Anaconda\u7684\u5176\u4ed6\u5de5\u5177\uff0c\u53ef\u4ee5\u9009\u62e9\u66f4\u5c0f\u7684Miniconda\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Conda\u5b89\u88c5\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5Conda\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda install package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5b89\u88c5pandas\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ba1\u7406\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>Conda\u7684\u4e00\u4e2a\u5f3a\u5927\u529f\u80fd\u662f\u73af\u5883\u7ba1\u7406\uff0c\u53ef\u4ee5\u4e3a\u4e0d\u540c\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684\u73af\u5883\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u521b\u5efa\u65b0\u73af\u5883\uff1a<code>conda create --name env_name python=3.8<\/code><\/li>\n<li>\u6fc0\u6d3b\u73af\u5883\uff1a<code>conda activate env_name<\/code><\/li>\n<li>\u5220\u9664\u73af\u5883\uff1a<code>conda remove --name env_name --all<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u624b\u52a8\u4e0b\u8f7d\u5e76\u5b89\u88c5<\/p>\n<\/p>\n<p><p>\u6709\u65f6\uff0c\u67d0\u4e9b\u5305\u53ef\u80fd\u65e0\u6cd5\u901a\u8fc7pip\u6216conda\u76f4\u63a5\u5b89\u88c5\u3002\u6b64\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u624b\u52a8\u4e0b\u8f7d\u5e76\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7d\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u524d\u5f80\u5305\u7684\u5b98\u65b9\u7f51\u7ad9\u6216PyPI\u9875\u9762\uff0c\u4e0b\u8f7d\u5bf9\u5e94\u7248\u672c\u7684\u6e90\u4ee3\u7801\u538b\u7f29\u5305\u6216wheel\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u89e3\u538b\u4e0b\u8f7d\u7684\u6587\u4ef6\uff0c\u8fdb\u5165\u89e3\u538b\u540e\u7684\u76ee\u5f55\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py install<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\uff0c\u5982\u679c\u662fwheel\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install package_name.whl<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u907f\u514d\u5728\u4e0d\u540c\u9879\u76ee\u95f4\u5305\u7248\u672c\u7684\u51b2\u7a81\uff0c\u63a8\u8350\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528venv\u6a21\u5757\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv env_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728Windows\u4e0a\uff1a<code>.\\env_name\\Scripts\\activate<\/code><\/li>\n<li>\u5728macOS\/Linux\u4e0a\uff1a<code>source env_name\/bin\/activate<\/code><\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5728\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u6240\u6709pip\u5b89\u88c5\u7684\u5305\u90fd\u4f1a\u5b89\u88c5\u5230\u8fd9\u4e2a\u73af\u5883\u4e2d\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u5168\u5c40\u7684Python\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u8f93\u5165<code>deactivate<\/code>\u547d\u4ee4\u53ef\u4ee5\u9000\u51fa\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u603b\u7ed3\u6765\u8bf4\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u5f0f\u6765\u7ba1\u7406\u548c\u5b89\u88c5\u5305\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u5f00\u53d1\u8005\u7684\u9700\u6c42\u3002\u6839\u636e\u9879\u76ee\u7684\u5177\u4f53\u60c5\u51b5\u548c\u4e2a\u4eba\u504f\u597d\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u5f0f\u8fdb\u884c\u5305\u7ba1\u7406\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\uff0c\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u9ebb\u70e6\u3002\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u786e\u4fddPython\u73af\u5883\u7684\u6574\u6d01\u548c\u5305\u7684\u6b63\u786e\u7248\u672c\u662f\u4fdd\u8bc1\u9879\u76ee\u7a33\u5b9a\u8fd0\u884c\u7684\u5173\u952e\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\u53ef\u4ee5\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177pip\u3002\u9996\u5148\u6253\u5f00\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\uff0c\u8f93\u5165<code>pip install \u5e93\u540d<\/code>\uff08\u4f8b\u5982<code>pip install requests<\/code>\uff09\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002\u5982\u679c\u4f60\u7684Python\u73af\u5883\u6709\u591a\u4e2a\u7248\u672c\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528<code>pip3<\/code>\u6765\u786e\u4fdd\u5e93\u5b89\u88c5\u5230Python 3.x\u7248\u672c\u4e2d\u3002<\/p>\n<p><strong>\u5b89\u88c5\u5305\u65f6\u9047\u5230\u6743\u9650\u95ee\u9898\u8be5\u600e\u4e48\u529e\uff1f<\/strong><br \/>\u5982\u679c\u5728\u5b89\u88c5Python\u5305\u65f6\u9047\u5230\u6743\u9650\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u5728\u547d\u4ee4\u524d\u52a0\u4e0a<code>sudo<\/code>\uff08\u5bf9\u4e8eLinux\u548cmacOS\u7528\u6237\uff09\uff0c\u5982<code>sudo pip install \u5e93\u540d<\/code>\u3002\u5bf9\u4e8eWindows\u7528\u6237\uff0c\u53ef\u4ee5\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884c\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>--user<\/code>\u9009\u9879\uff0c\u5982<code>pip install --user \u5e93\u540d<\/code>\uff0c\u53ef\u4ee5\u5c06\u5305\u5b89\u88c5\u5230\u7528\u6237\u76ee\u5f55\uff0c\u907f\u514d\u6743\u9650\u95ee\u9898\u3002<\/p>\n<p><strong>\u5982\u4f55\u67e5\u770b\u5df2\u5b89\u88c5\u7684Python\u5305\uff1f<\/strong><br \/>\u8981\u67e5\u770b\u5df2\u5b89\u88c5\u7684Python\u5305\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>pip list<\/code>\u3002\u8fd9\u5c06\u663e\u793a\u7cfb\u7edf\u4e2d\u6240\u6709\u5df2\u5b89\u88c5\u5305\u7684\u5217\u8868\u53ca\u5176\u7248\u672c\u4fe1\u606f\u3002\u5982\u679c\u4f60\u60f3\u83b7\u53d6\u67d0\u4e2a\u7279\u5b9a\u5305\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip show \u5305\u540d<\/code>\u547d\u4ee4\uff0c\u83b7\u53d6\u66f4\u8be6\u7ec6\u7684\u63cf\u8ff0\u548c\u4f9d\u8d56\u5173\u7cfb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u4e0b\u5305\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528pip\u3001conda\u3001\u624b\u52a8\u4e0b\u8f7d\u5e76\u5b89\u88c5\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u8fdb\u884c\u7ba1\u7406\u3002\u5176\u4e2d\uff0c\u4f7f\u7528pip\u662f [&hellip;]","protected":false},"author":3,"featured_media":1013781,"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\/1013774"}],"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=1013774"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1013774\/revisions"}],"predecessor-version":[{"id":1013783,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1013774\/revisions\/1013783"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1013781"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1013774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1013774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1013774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}