{"id":944911,"date":"2024-12-26T23:16:39","date_gmt":"2024-12-26T15:16:39","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/944911.html"},"modified":"2024-12-26T23:16:40","modified_gmt":"2024-12-26T15:16:40","slug":"python%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85numby","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/944911.html","title":{"rendered":"python\u5982\u4f55\u5b89\u88c5numby"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25081710\/125c0133-1175-444e-b31a-a41fd3d125df.webp\" alt=\"python\u5982\u4f55\u5b89\u88c5numby\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5b89\u88c5NumPy\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u53ef\u4ee5\u901a\u8fc7pip\u5b89\u88c5\u3001\u4f7f\u7528Anaconda\u73af\u5883\u3001\u4ece\u6e90\u4ee3\u7801\u5b89\u88c5\u7b49\uff0c\u5177\u4f53\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528pip\u547d\u4ee4\u76f4\u63a5\u5b89\u88c5\u3001\u4f7f\u7528Anaconda\u81ea\u5e26\u7684\u5305\u7ba1\u7406\u5668conda\u5b89\u88c5\u3001\u4eceNumPy\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6e90\u4ee3\u7801\u5e76\u624b\u52a8\u5b89\u88c5<\/strong>\u3002\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528pip\u548cconda\u662f\u6700\u4e3a\u4fbf\u6377\u548c\u5e38\u7528\u7684\u65b9\u5f0f\u3002\u4e0b\u9762\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\u6765\u5b89\u88c5NumPy\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528PIP\u5b89\u88c5NumPy<\/p>\n<\/p>\n<p><p>pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u5b89\u88c5Python\u5305\u548c\u8f6f\u4ef6\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528pip\u5b89\u88c5NumPy\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u786e\u4fddPython\u548cpip\u5df2\u5b89\u88c5<\/strong><br \/>\u5728\u5b89\u88c5NumPy\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u4f60\u7684\u8ba1\u7b97\u673a\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u548cpip\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u68c0\u67e5\u5b83\u4eec\u662f\u5426\u5df2\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code>python --version<\/p>\n<p>pip --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u672a\u5b89\u88c5Python\u548cpip\uff0c\u8bf7\u5148\u4e0b\u8f7d\u5e76\u5b89\u88c5Python\uff0cpip\u4f1a\u968f\u7740Python\u4e00\u8d77\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5NumPy<\/strong><br \/>\u4f7f\u7528pip\u5b89\u88c5NumPy\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code>pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4ecePython Package Index (PyPI) \u4e0b\u8f7d\u5e76\u5b89\u88c5NumPy\u7684\u6700\u65b0\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong><br \/>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728Python\u73af\u5883\u4e2d\u5bfc\u5165NumPy\u6765\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>print(np.__version__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u6ca1\u6709\u9519\u8bef\u4fe1\u606f\uff0c\u4e14\u6253\u5370\u51faNumPy\u7684\u7248\u672c\u53f7\uff0c\u5219\u8868\u793a\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528Anaconda\u5b89\u88c5NumPy<\/p>\n<\/p>\n<p><p>Anaconda\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python\u53d1\u884c\u7248\uff0c\u5185\u7f6e\u4e86\u8bb8\u591a\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\u7684\u5305\uff0c\u5305\u62ecNumPy\u3002\u4f7f\u7528Anaconda\u5b89\u88c5NumPy\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7d\u5e76\u5b89\u88c5Anaconda<\/strong><br \/>\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5Anaconda\uff0c\u53ef\u4ee5\u4eceAnaconda\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5Anaconda\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u65b0\u7684\u73af\u5883\uff08\u53ef\u9009\uff09<\/strong><br \/>\u4f7f\u7528Anaconda\uff0c\u4f60\u53ef\u4ee5\u4e3a\u4e0d\u540c\u7684\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u5305\u7248\u672c\u51b2\u7a81\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code>conda create --name myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d<code>myenv<\/code>\u662f\u73af\u5883\u7684\u540d\u79f0\u3002\u521b\u5efa\u73af\u5883\u540e\uff0c\u6fc0\u6d3b\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code>conda activate myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5NumPy<\/strong><br \/>\u5728\u6fc0\u6d3b\u7684\u73af\u5883\u4e2d\uff0c\u4f7f\u7528conda\u547d\u4ee4\u5b89\u88c5NumPy\uff1a<\/p>\n<\/p>\n<p><pre><code>conda install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4eceAnaconda\u7684\u5305\u7ba1\u7406\u5668\u4e2d\u4e0b\u8f7d\u5e76\u5b89\u88c5NumPy\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong><br \/>\u540c\u6837\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728Python\u73af\u5883\u4e2d\u5bfc\u5165NumPy\u6765\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4ece\u6e90\u4ee3\u7801\u5b89\u88c5NumPy<\/p>\n<\/p>\n<p><p>\u5c3d\u7ba1\u4f7f\u7528pip\u548cconda\u662f\u5b89\u88c5NumPy\u7684\u6700\u5e38\u7528\u65b9\u6cd5\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u4ece\u6e90\u4ee3\u7801\u5b89\u88c5NumPy\uff0c\u4f8b\u5982\u4f60\u9700\u8981\u7279\u5b9a\u7684NumPy\u7248\u672c\u6216\u9700\u8981\u4fee\u6539NumPy\u7684\u6e90\u4ee3\u7801\u3002\u4ee5\u4e0b\u662f\u4ece\u6e90\u4ee3\u7801\u5b89\u88c5NumPy\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7dNumPy\u6e90\u4ee3\u7801<\/strong><br \/>\u4f60\u53ef\u4ee5\u4eceNumPy\u7684GitHub\u4ed3\u5e93\u6216\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6e90\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u6784\u5efa\u5de5\u5177<\/strong><br \/>\u5728\u4ece\u6e90\u4ee3\u7801\u5b89\u88c5NumPy\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u7cfb\u7edf\u4e0a\u5b89\u88c5\u4e86\u5fc5\u8981\u7684\u6784\u5efa\u5de5\u5177\uff0c\u5982C\u7f16\u8bd1\u5668\u3002\u5bf9\u4e8eWindows\u7528\u6237\uff0c\u5efa\u8bae\u5b89\u88c5Microsoft Visual C++ Build Tools\uff1b\u5bf9\u4e8eLinux\u7528\u6237\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86gcc\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6784\u5efa\u548c\u5b89\u88c5NumPy<\/strong><br \/>\u5728\u4e0b\u8f7d\u7684\u6e90\u4ee3\u7801\u76ee\u5f55\u4e2d\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6784\u5efa\u548c\u5b89\u88c5NumPy\uff1a<\/p>\n<\/p>\n<p><pre><code>python setup.py install<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u7f16\u8bd1NumPy\u7684\u6e90\u4ee3\u7801\u5e76\u5b89\u88c5\u5230\u4f60\u7684Python\u73af\u5883\u4e2d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong><br \/>\u540c\u6837\uff0c\u901a\u8fc7\u5bfc\u5165NumPy\u6765\u9a8c\u8bc1\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7248\u672c\u517c\u5bb9\u6027<\/strong><br \/>\u5728\u5b89\u88c5NumPy\u65f6\uff0c\u7279\u522b\u662f\u5728\u4f7f\u7528\u65e7\u7248\u672c\u7684Python\u6216\u5176\u4ed6\u79d1\u5b66\u8ba1\u7b97\u5e93\u65f6\uff0c\u9700\u8981\u6ce8\u610fNumPy\u7248\u672c\u7684\u517c\u5bb9\u6027\u3002\u53ef\u4ee5\u53c2\u8003NumPy\u7684\u5b98\u65b9\u7f51\u7ad9\u6216\u6587\u6863\u83b7\u53d6\u7248\u672c\u517c\u5bb9\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u865a\u62df\u73af\u5883<\/strong><br \/>\u4f7f\u7528\u865a\u62df\u73af\u5883\uff08\u5982virtualenv\u6216conda\u73af\u5883\uff09\u53ef\u4ee5\u5e2e\u52a9\u4f60\u7ba1\u7406\u4e0d\u540c\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u907f\u514d\u5305\u7248\u672c\u51b2\u7a81\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u66f4\u65b0NumPy<\/strong><br \/>\u5982\u679c\u9700\u8981\u66f4\u65b0NumPy\u5230\u6700\u65b0\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code>pip install --upgrade numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\uff0c\u5982\u679c\u4f7f\u7528\u7684\u662fAnaconda\uff1a<\/p>\n<\/p>\n<p><pre><code>conda update numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u548c\u73af\u5883\u9009\u62e9\u6700\u5408\u9002\u7684\u65b9\u5f0f\u6765\u5b89\u88c5NumPy\u3002\u65e0\u8bba\u662f\u5f00\u53d1\u7b80\u5355\u7684\u811a\u672c\u8fd8\u662f\u8fdb\u884c\u590d\u6742\u7684\u79d1\u5b66\u8ba1\u7b97\uff0cNumPy\u90fd\u662fPython\u4e2d\u4e00\u4e2a\u5f3a\u5927\u4e14\u5fc5\u4e0d\u53ef\u5c11\u7684\u5e93\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b89\u88c5NumPy\uff1f<\/strong><br \/>\u5728Python\u4e2d\u5b89\u88c5NumPy\u975e\u5e38\u7b80\u5355\u3002\u53ef\u4ee5\u4f7f\u7528Python\u7684\u5305\u7ba1\u7406\u5668pip\u6765\u5b8c\u6210\u5b89\u88c5\u3002\u9996\u5148\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u548cpip\u3002\u6253\u5f00\u547d\u4ee4\u884c\uff08Windows\uff09\u6216\u7ec8\u7aef\uff08macOS\/Linux\uff09\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a  <\/p>\n<pre><code class=\"language-bash\">pip install numpy\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fPython 3\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528<code>pip3<\/code>\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728Python\u73af\u5883\u4e2d\u901a\u8fc7<code>import numpy as np<\/code>\u6765\u5bfc\u5165NumPy\u3002<\/p>\n<p><strong>\u5b89\u88c5NumPy\u65f6\u9047\u5230\u9519\u8bef\u8be5\u5982\u4f55\u89e3\u51b3\uff1f<\/strong><br \/>\u5728\u5b89\u88c5NumPy\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u9519\u8bef\uff0c\u6bd4\u5982\u6743\u9650\u95ee\u9898\u6216pip\u7248\u672c\u8fc7\u65e7\u3002\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528<code>--user<\/code>\u9009\u9879\u6765\u5b89\u88c5\uff1a<\/p>\n<pre><code class=\"language-bash\">pip install --user numpy\n<\/code><\/pre>\n<p>\u5982\u679cpip\u7248\u672c\u8fc7\u65e7\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5347\u7ea7pip\uff1a<\/p>\n<pre><code class=\"language-bash\">pip install --upgrade pip\n<\/code><\/pre>\n<p>\u786e\u4fdd\u4f60\u7684\u7f51\u7edc\u8fde\u63a5\u6b63\u5e38\u4e5f\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<p><strong>\u662f\u5426\u6709\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u5b89\u88c5NumPy\uff1f<\/strong><br \/>\u9664\u4e86\u4f7f\u7528pip\uff0c\u8fd8\u6709\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u5b89\u88c5NumPy\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u4f7f\u7528Anaconda\u4f5c\u4e3aPython\u7684\u5305\u7ba1\u7406\u5668\uff0c\u53ef\u4ee5\u5728Anaconda Prompt\u4e2d\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"language-bash\">conda install numpy\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u4f1a\u81ea\u52a8\u5904\u7406\u4f9d\u8d56\u5173\u7cfb\uff0c\u975e\u5e38\u9002\u5408\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\u7684\u73af\u5883\u3002<\/p>\n<p><strong>\u5982\u4f55\u9a8c\u8bc1NumPy\u662f\u5426\u6210\u529f\u5b89\u88c5\uff1f<\/strong><br \/>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7Python\u547d\u4ee4\u884c\u6216\u811a\u672c\u9a8c\u8bc1NumPy\u662f\u5426\u6210\u529f\u5b89\u88c5\u3002\u5728Python\u73af\u5883\u4e2d\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\nprint(np.__version__)\n<\/code><\/pre>\n<p>\u5982\u679c\u6ca1\u6709\u4efb\u4f55\u9519\u8bef\uff0c\u5e76\u4e14\u663e\u793a\u51faNumPy\u7684\u7248\u672c\u53f7\uff0c\u8bf4\u660eNumPy\u5df2\u7ecf\u6210\u529f\u5b89\u88c5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5b89\u88c5NumPy\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u53ef\u4ee5\u901a\u8fc7pip\u5b89\u88c5\u3001\u4f7f\u7528Anaconda\u73af\u5883\u3001\u4ece\u6e90\u4ee3\u7801\u5b89\u88c5\u7b49\uff0c\u5177\u4f53 [&hellip;]","protected":false},"author":3,"featured_media":944913,"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\/944911"}],"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=944911"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/944911\/revisions"}],"predecessor-version":[{"id":944914,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/944911\/revisions\/944914"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/944913"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=944911"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=944911"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=944911"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}