参考原文:https://blog.csdn.net/txpp520/article/details/71774054
在python中运行下面命令时,提示错误:
>>> from numpy import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
原因是numpy库没有安装。
安装方法:在win命令行中运行pip install numpy。
但会遇到一个新问题,安装包下载速度极慢。
对策:在当前用户目录中创建一个pip.ini文件,写入一个服务器地址:
path: c:\users\xxxx\pip\pip.ini
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
然后在运行pip install numpy,速度会有大幅提升。
测试:
C:\Python27>python
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from numpy import *
>>> random.rand(4,4)
array([[0.22396301, 0.60189013, 0.12196128, 0.47619496],
[0.28444112, 0.04305441, 0.32312667, 0.81355242],
[0.25706765, 0.05148857, 0.43571714, 0.7125802 ],
[0.20603429, 0.94365001, 0.05604095, 0.11769018]])
>>>