我正在使用
pip install numpy
在我的Mac上安装NumPy。然后终端说
Requirement already satisfied: numpy in
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
我想这意味着 Numpy 已经安装了? 但是当我写的时候
from numpy import array
a=array([1,3],int)
蟒蛇外壳说
Traceback (most recent call last):
File "/Users/bamford/Documents/python/untitled-3.py", line 1, in <module>
from numpy import array
builtins.ModuleNotFoundError: No module named 'numpy'
这是怎么回事?
根据注释,请注意您的sys.path
包含名称暗示它们与 Python3.6 关联的目录:
[...'/Library/Frameworks/Python.framework/Versions/3.6/lib/pytho n36.zip', ...]
然而,NumPy已经安装在你的Python2.7发行版中:
已满足的要求:numpy in/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
(我的强调)所以你的Wing101 IDE正在使用Python3,但没有找到NumPy,因为NumPy还没有安装在你的Python3发行版中。
一种解决方案是为Python3发行版安装NumPy。(另一个,可能是将Wing101配置为运行Python2.7。通常,与 Python3 关联的pip
可执行文件被命名为pip3
(以区别于名为pip
的 Python2 版本。所以你可以尝试
pip3 install numpy
以安装NumPy。
故事的寓意:每个点都与特定的Python发行版相关联。pip
是一个 Python 脚本。运行时,它会调用与该发行版关联的 Python 可执行文件。
要使用pip
为特定的Python安装模块,您需要调用与所需的Python可执行文件相关联的pip
脚本。
消息点显示在您的系统中
已满足的要求:numpy in/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
在这里,您可以注意到,numpy
模块安装在python 2.7
的目录中。 您应该将其安装在python 3.*
的目录中。你可以试试
pip3 install numpy
pip3
在python 3.*
目录中安装 python 库
在命令开头添加sudo
以在系统范围内安装它。