我已经使用 pip 安装了 numpy 同样,下面的代码在 python IDLE 中可以顺利运行,但在 vs code 中则不行
我写:
import numpy as np np.ones(8)
错误显示: PS C:\Users nshu\Documents\VScode Python> python -u "c:\Users nshu\Documents\VScode Python xtra.py" 回溯(最近一次调用最后一次): 文件“c:\Users nshu\Documents\VScode Python xtra.py”,第 1 行,位于 将 numpy 导入为 np ModuleNotFoundError:没有名为“numpy”的模块 PS C:\Users nshu\Documents\VScode Python>
我检查了很多问题,他们通常说使用 pip install numpy 安装 numpy。 或者其他 IDE 中有一些东西,例如 anaconda(我没有安装)或 pycharm 等。
我只是想在 VS Code 中解决这个问题,而不是在任何其他 IDE 中。
如果您正在使用
python -u file
我建议检查您使用的python是否与您安装numpy的Python相同,它可能使用不同的安装。
许多用户通常有多个 python 安装或虚拟环境(更多信息请参见:https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/)可能会导致别名和所需依赖项以及它们的安装位置发生冲突。
我建议确保将 numpy 安装到您运行的同一安装中,为此您可以执行以下操作:
python -m pip install numpy