尽管我安装了模块,但在 VS 代码中找不到模块错误 [英] Module not found error in VS code despite the fact that I installed it

查看:23
本文介绍了尽管我安装了模块,但在 VS 代码中找不到模块错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 VS 代码调试一些 Python 代码.我收到有关我确定已安装的模块的以下错误.

I'm trying to debug some python code using VS code. I'm getting the following error about a module that I am sure is installed.

Exception has occurred: ModuleNotFoundError
No module named 'SimpleITK'
  File "C:UsersMidoDesktopProstateX-projectsrc1-preprocessing3_resample_nifti.py", line 8, in <module>
    import SimpleITK as sitk

我使用

sudo pip install SimpleITK

我知道它已安装,因为我在通过命令行运行代码时遇到了类似的错误,并且通过执行上述操作修复了它.我不明白为什么 VS 代码不能识别

I know that it was installed because I was getting a similar error when I ran the code through the command line, and it was fixed by doing the above. I don't understand why VS code does not recognize that

推荐答案

sudo pip install 很可能全局安装到 Python 解释器中,该解释器与您在 VS Code 中选择的解释器不同.请选择您要使用的 Python 解释器然后使用该解释器显式安装(如果您不使用虚拟环境,则使用类似 /path/to/python -m pip install SimpleITK 之类的东西,尽管我强烈建议使用虚拟环境,不要全局安装包).

sudo pip install is most likely installing globally into a Python interpreter that is different than the one that you have selected in VS Code. Please select the Python interpreter you want to use and then install explicitly using that interpreter (if you're not using a virtual environment then use something like /path/to/python -m pip install SimpleITK, although I strongly recommend using a virtual environment and to not install packages globally).

这篇关于尽管我安装了模块,但在 VS 代码中找不到模块错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆