尝试导入模块时,VSCode运行会产生ModuleNotFoundError

时间:2020-09-20 22:07:00

标签: python visual-studio-code

我有一个项目文件夹,其中包含一个名为“ src”的模块,其中包含我的代码。在“ src”中,还有另一个名为“ crawlers”的模块,其中包含python代码。在“ crawlers”文件夹中存储的文件之一中,我调用了“ src”文件夹中的导入文件,以从其 init .py文件中获取变量。 结构是这样的

└───src  (this is a module)
    ├───crawlers  (this is a module)
         |----- code.py
    ├───datafiles
    ├───models
    └───utils

在我的code.py文件中

import json
from src import variable1, variable 2

当代码在vscode中运行时,我得到了

Traceback (most recent call last):
  File "d:/Code files/tech projects/tree_courses_scraper/src/crawlers/course_grab.py", line 2, in <module>
    from src import umanitoba_calendar, umanitoba_codes
ModuleNotFoundError: No module named 'src'

我使用pycharm社区已有一段时间了,但从未遇到这个问题。

0 个答案:

没有答案