发生异常:VScode 中的 ModuleNotFoundError 但没有其他编辑器 [英] Exception has occurred: ModuleNotFoundError in VScode but no other editors
问题描述
此错误发生在 pip 安装模块
的 VS 代码中.
This error occurs in VS code for pip installed modules
.
发生异常:ModuleNotFoundError
它在前几天都在工作.我相信我可能已经删除了 *.pyc 文件或其他内容.
It was working on all previous days. I believe that i may have deleted a *.pyc file or something to this extent.
如果我执行 pip freeze
我可以看到模块.例如 import tweepy
无法解析,但我可以看到它存在于 pip freeze tweepy==3.10.0
并且我可以看到 python --版本
,我有正确的版本Python 3.9.0
.
If i do pip freeze
i can see the module.
For example import tweepy
could not be resolved, but i can see that it exists in pip freeze tweepy==3.10.0
and i can see with python --version
that i have the correct version Python 3.9.0
.
如果我在 IDLE (python3.9
) 上运行相同的代码,则代码有效,这让我相信这是一个 VScode 问题,但我不知道这是什么或如何解决它.
If i run the same on IDLE (python3.9
) the code works, which leads me to believe that this is a VScode issue, but i cannot tell what this is or how to fix it.
事实上,如果我在 VS 代码中重新创建新文件夹,导入也能工作.
In fact, if i recreate new folders in VS code, the imports work too.
那么问题是,我如何确定损坏的位置(哪个文件夹或文件)或导致 VS 代码以这种方式破坏的原因?
So the quesiton is, how can i identify where (which folder or file) the corruption is or what has caused VS code to break in this way ?
推荐答案
一种解决方案(有效)是重新创建所有文件夹和子文件夹.
One solution (which works) is to recreate all the folders and subfolders.
还需要注意的是,这并非特定于 python
,如下所示:
It is also noted that this is not specific to python
as seen here:
https://github.com/Microsoft/vscode/issues/10391
这里还有一个建议(很接近,但没有解决问题):
There is also a suggestion here (which is close, but did not resolve the issue):
我注意到,如果我使用 File ->关闭文件夹,然后文件 ->打开文件夹...并再次打开项目文件夹,错误是走了.
这篇关于发生异常:VScode 中的 ModuleNotFoundError 但没有其他编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!