{"id":973360,"date":"2024-12-27T05:56:20","date_gmt":"2024-12-26T21:56:20","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/973360.html"},"modified":"2024-12-27T05:56:22","modified_gmt":"2024-12-26T21:56:22","slug":"python%e5%a6%82%e4%bd%95%e6%b7%bb%e5%8a%a0%e5%a4%96%e9%83%a8%e5%ba%93","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/973360.html","title":{"rendered":"python\u5982\u4f55\u6dfb\u52a0\u5916\u90e8\u5e93"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24195558\/8589d6fd-afd0-4fd1-84ea-4b30fa42beb4.webp\" alt=\"python\u5982\u4f55\u6dfb\u52a0\u5916\u90e8\u5e93\" \/><\/p>\n<p><p> Python\u4e2d\u6dfb\u52a0\u5916\u90e8\u5e93\u901a\u5e38\u662f\u901a\u8fc7\u5305\u7ba1\u7406\u5de5\u5177\u5982pip\u6765\u5b9e\u73b0\u7684\u3002<strong>\u4f7f\u7528pip\u5b89\u88c5\u5e93\u3001\u901a\u8fc7\u6e90\u7801\u5b89\u88c5\u3001\u5229\u7528conda\u8fdb\u884c\u5b89\u88c5<\/strong>\u662f\u5e38\u7528\u7684\u51e0\u79cd\u65b9\u6cd5\u3002\u5176\u4e2d\uff0cpip\u662f\u6700\u5e38\u7528\u7684\u5de5\u5177\uff0c\u56e0\u4e3a\u5b83\u7b80\u5355\u6613\u7528\uff0c\u5e76\u4e14\u4e0ePython\u751f\u6001\u7cfb\u7edf\u96c6\u6210\u5f97\u5f88\u597d\u3002\u901a\u8fc7pip\u5b89\u88c5\u5e93\u65f6\uff0c\u53ea\u9700\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528<code>pip install \u5e93\u540d<\/code>\u5373\u53ef\u5b8c\u6210\u5b89\u88c5\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4f1a\u8be6\u7ec6\u8ba8\u8bba\u8fd9\u51e0\u79cd\u65b9\u6cd5\uff0c\u5e76\u63a2\u8ba8\u5982\u4f55\u6709\u6548\u7ba1\u7406\u548c\u4f7f\u7528\u8fd9\u4e9b\u5916\u90e8\u5e93\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528PIP\u5b89\u88c5\u5e93<\/p>\n<\/p>\n<p><p>pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u51e0\u4e4e\u6240\u6709\u7684Python\u5916\u90e8\u5e93\u90fd\u53ef\u4ee5\u901a\u8fc7pip\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528pip\u5b89\u88c5<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u53ef\u4ee5\u5b89\u88c5\u6240\u9700\u7684Python\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install \u5e93\u540d<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u60f3\u5b89\u88c5NumPy\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>pip\u4f1a\u81ea\u52a8\u4ecePython Package Index\uff08PyPI\uff09\u4e0b\u8f7d\u5e76\u5b89\u88c5\u8be5\u5e93\u53ca\u5176\u4f9d\u8d56\u9879\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6307\u5b9a\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u9700\u8981\u5b89\u88c5\u7279\u5b9a\u7248\u672c\u7684\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install \u5e93\u540d==\u7248\u672c\u53f7<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5b89\u88c5NumPy\u76841.18.5\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy==1.18.5<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5347\u7ea7\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u53ef\u4ee5\u5347\u7ea7\u5df2\u5b89\u88c5\u7684\u5e93\u5230\u6700\u65b0\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install --upgrade \u5e93\u540d<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5347\u7ea7NumPy\u5230\u6700\u65b0\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install --upgrade numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u901a\u8fc7\u6e90\u7801\u5b89\u88c5<\/p>\n<\/p>\n<p><p>\u6709\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u4ece\u6e90\u7801\u5b89\u88c5\u5e93\uff0c\u6bd4\u5982\u4f7f\u7528\u67d0\u4e2a\u5e93\u7684\u5f00\u53d1\u7248\u672c\u6216\u8005\u4fee\u6539\u8fc7\u7684\u7248\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7d\u6e90\u7801<\/strong><\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4eceGitHub\u7b49\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\u4e0b\u8f7d\u6240\u9700\u5e93\u7684\u6e90\u7801\u3002\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u514b\u9686Git\u4ed3\u5e93\u6765\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">git clone \u4ed3\u5e93\u5730\u5740<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u8fdb\u5165\u4e0b\u8f7d\u7684\u6e90\u7801\u76ee\u5f55\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u5e93\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>\u8fd9\u79cd\u65b9\u5f0f\u4f1a\u6839\u636e\u6e90\u7801\u4e2d\u7684<code>setup.py<\/code>\u6587\u4ef6\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528CONDA\u8fdb\u884c\u5b89\u88c5<\/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\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<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Conda<\/strong><\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5Anaconda\u6216Miniconda\u3002Anaconda\u662f\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u79d1\u5b66\u8ba1\u7b97\u5e93\u7684Python\u53d1\u884c\u7248\uff0c\u800cMiniconda\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7248\u672c\uff0c\u53ea\u5305\u542bConda\u548cPython\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Conda\u5b89\u88c5\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Python\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda install \u5e93\u540d<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5b89\u88c5NumPy\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u548c\u7ba1\u7406\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>Conda\u5141\u8bb8\u521b\u5efa\u72ec\u7acb\u7684\u73af\u5883\u4ee5\u4fbf\u7ba1\u7406\u4e0d\u540c\u9879\u76ee\u7684\u4f9d\u8d56\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Conda\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda create --name \u73af\u5883\u540d python=\u7248\u672c\u53f7<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2aPython 3.8\u7684\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda create --name myenv python=3.8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u8be5\u73af\u5883\u540e\uff0c\u5c31\u53ef\u4ee5\u5728\u8be5\u73af\u5883\u4e2d\u5b89\u88c5\u548c\u7ba1\u7406\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda activate myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u7ba1\u7406\u548c\u4f7f\u7528\u5916\u90e8\u5e93<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528pip\u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u73af\u5883\u4e0b\u5df2\u5b89\u88c5\u7684\u6240\u6709\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Conda\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5378\u8f7d\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u4e0d\u518d\u9700\u8981\u67d0\u4e2a\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5378\u8f7d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip uninstall \u5e93\u540d<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\u4f7f\u7528Conda\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda remove \u5e93\u540d<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u51bb\u7ed3\u5f53\u524d\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u4fbf\u4e8e\u5728\u5176\u4ed6\u73af\u5883\u4e2d\u91cd\u73b0\u5f53\u524d\u73af\u5883\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u7684\u51bb\u7ed3\u529f\u80fd\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\u6837\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u751f\u6210\u4e00\u4e2a<code>requirements.txt<\/code>\u6587\u4ef6\uff0c\u8bb0\u5f55\u5f53\u524d\u73af\u5883\u4e0b\u6240\u6709\u5e93\u53ca\u5176\u7248\u672c\u3002\u4e4b\u540e\u53ef\u4ee5\u5728\u53e6\u4e00\u73af\u5883\u4e2d\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u8fd9\u4e9b\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u5916\u90e8\u5e93\u662fPython\u5f00\u53d1\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002<strong>\u901a\u8fc7pip\u6216Conda\u5b89\u88c5\u5e93\u3001\u7ba1\u7406\u73af\u5883\u3001\u7ef4\u62a4\u4f9d\u8d56\u5173\u7cfb<\/strong>\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u5e76\u786e\u4fdd\u9879\u76ee\u7684\u53ef\u7ef4\u62a4\u6027\u3002\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u80fd\u591f\u66f4\u597d\u5730\u9002\u5e94\u5404\u79cd\u5f00\u53d1\u9700\u6c42\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u5982\u4f55\u5728Python\u4e2d\u6dfb\u52a0\u5916\u90e8\u5e93\u63d0\u4f9b\u4e86\u6709\u7528\u7684\u6307\u5bfc\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b89\u88c5\u5916\u90e8\u5e93\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5b89\u88c5\u5916\u90e8\u5e93\u901a\u5e38\u901a\u8fc7\u5305\u7ba1\u7406\u5de5\u5177pip\u8fdb\u884c\u3002\u60a8\u53ef\u4ee5\u6253\u5f00\u547d\u4ee4\u884c\u754c\u9762\uff0c\u8f93\u5165<code>pip install \u5e93\u540d<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002\u4f8b\u5982\uff0c\u5b89\u88c5NumPy\u5e93\u7684\u547d\u4ee4\u662f<code>pip install numpy<\/code>\u3002\u786e\u4fdd\u60a8\u7684Python\u73af\u5883\u5df2\u6b63\u786e\u914d\u7f6e\uff0c\u5e76\u4e14pip\u5df2\u5b89\u88c5\u3002<\/p>\n<p><strong>\u5728Python\u865a\u62df\u73af\u5883\u4e2d\u5982\u4f55\u7ba1\u7406\u5916\u90e8\u5e93\uff1f<\/strong><br \/>\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u6709\u6548\u7ba1\u7406\u9879\u76ee\u6240\u9700\u7684\u5916\u90e8\u5e93\u3002\u901a\u8fc7<code>python -m venv \u73af\u5883\u540d<\/code>\u521b\u5efa\u865a\u62df\u73af\u5883\u540e\uff0c\u6fc0\u6d3b\u5b83\uff08\u5728Windows\u4e0a\u4f7f\u7528<code>\u73af\u5883\u540d\\Scripts\\activate<\/code>\uff0c\u5728Linux\/Mac\u4e0a\u4f7f\u7528<code>source \u73af\u5883\u540d\/bin\/activate<\/code>\uff09\uff0c\u7136\u540e\u5728\u6fc0\u6d3b\u7684\u73af\u5883\u4e2d\u4f7f\u7528pip\u5b89\u88c5\u5e93\u3002\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u5e93\u51b2\u7a81\u5e76\u4fdd\u6301\u9879\u76ee\u7684\u72ec\u7acb\u6027\u3002<\/p>\n<p><strong>\u5982\u4f55\u67e5\u770b\u5df2\u5b89\u88c5\u7684Python\u5916\u90e8\u5e93\u5217\u8868\uff1f<\/strong><br \/>\u8981\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5916\u90e8\u5e93\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>pip list<\/code>\u3002\u6b64\u547d\u4ee4\u5c06\u663e\u793a\u5f53\u524d\u73af\u5883\u4e2d\u5b89\u88c5\u7684\u6240\u6709\u5e93\u53ca\u5176\u7248\u672c\u4fe1\u606f\u3002\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>pip show \u5e93\u540d<\/code>\u67e5\u770b\u7279\u5b9a\u5e93\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u7248\u672c\u3001\u4f9d\u8d56\u5173\u7cfb\u548c\u5b89\u88c5\u8def\u5f84\u7b49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4e2d\u6dfb\u52a0\u5916\u90e8\u5e93\u901a\u5e38\u662f\u901a\u8fc7\u5305\u7ba1\u7406\u5de5\u5177\u5982pip\u6765\u5b9e\u73b0\u7684\u3002\u4f7f\u7528pip\u5b89\u88c5\u5e93\u3001\u901a\u8fc7\u6e90\u7801\u5b89\u88c5\u3001\u5229\u7528conda\u8fdb [&hellip;]","protected":false},"author":3,"featured_media":973366,"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\/973360"}],"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=973360"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/973360\/revisions"}],"predecessor-version":[{"id":973367,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/973360\/revisions\/973367"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/973366"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=973360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=973360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=973360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}