在 VSCode 中切换 venv

Switching between venvs in VSCode

提问人:elksie5000 提问时间:11/17/2023 更新时间:11/17/2023 访问量:38

问:

我正在学习在 VSCode 中运行 python 的教程,并且正在努力切换到运行 numpy。https://code.visualstudio.com/docs/python/python-tutorial

import numpy as np

msg = "Roll a dice"
print(msg)

print(np.random.randint(1,9))

错误是:

ModuleNotFoundError: No module named 'numpy'

尽管使用终端来pip install numpy。

如果这有帮助,它出现在右下角,所以我认为 venv 设置正确。

enter image description here

但底部中间的面板指向其他地方的文件夹。

enter image description here

我需要做些什么来解决这个问题

python numpy visual-studio代码

评论


答:

0赞 JialeDu 11/17/2023 #1

您可能未安装在当前的虚拟环境中。 您可以使用终端中的命令来检查 的安装位置。numpypip show numpynumpy

enter image description here

解决方案:安装 .venv 或将解释器切换到已安装的解释器。numpynumpy

当然,你也需要注意使用Python扩展来执行脚本。如果您使用 CodeRunner,则某些设置将不起作用。

Run Python File不。Run Code

enter image description here