ModuleNotFoundError: No module named ‘utils.tools‘; ‘utils‘ is not a package import用法


The pits that have been stepped on

Insert image description here
Setting the _init._py file in the utils folder has this, so importing it still doesn’t work.

import utils.data_augment as dataAug
import utils.tools as tools

debug error reporting

ModuleNotFoundError: No module named ‘utils.data_augment’; ‘utils’ is
not a package

Solution

After setting the directory to source root, import like this.
Insert image description here

After setting up, the color of the folder will change and the red line will no longer be needed.
Insert image description here

import data_augment as dataAug
import tools as tools

import red line but can still run normally

How to use import

https://zhuanlan.zhihu.com/p/63143493
I just saw the import red line in this blog, but it can run normally and I can’t hold down ctrl to jump to the corresponding function.

Referring to this situation, if m1 import m2 in the same directory
Insert image description here
Insert image description here
holds down ctrl and clicks m2, it will not jump to it.

Solution: Right-click the directory and set it to Source Root

Insert image description here
Insert image description here
It can run directly at this time, and there is no red line. Press and hold m2 to jump directly.

Guess you like

Origin blog.csdn.net/qq_41398619/article/details/120055424