Python quote package error record (pycharm: ide reports an error, terminal: command line operation does not report an error)

Project: predict.py under paddleclas under SET_UP_MENU The following are the symptoms

症状一:

import utils as utils
from utils import *

# import tools.infer.utils as utils
# from tools.infer.utils import get_image_list

注释部分使用命令行可用,但是ide不可用

非注释部分,都可用,都在统一目录下,引用的包的话
症状二:

引用包下方出现红线,或者在代码中运行时也有红线,但是ide和命令行调用,依然可以成功运行!
from tools.infer.utils import get_image_list(自行想象下面的红线)

The error found with the help of the boss is handled as follows

The reason for the error: In this project, there is also a package with the same name, just like the utils in the from utils import * above. After pressing ctrl and right-clicking the mouse, the path entered is another package with the same name under the project. .

And the utils package we quoted is in the same directory as predict.py, so when the system is running, it will first search for the package in the same directory, but when the error is detected, that is, when the red line is drawn, it is from the setting The source code root (the source code root is set by yourself by left-clicking on the directory) and proceeding downward.

Solution:

	1.将包含这个包的的文件夹(这里是predict.py和utils.py )设置为源码根,这样predict.py和utils.py 系统在搜索的时候就会从最近的源码根开始了
   
   2.把同名的其中的一个包该个名字,这个有些麻烦,不过迁移环境运行的时候就不用设置那些源码根了。

Guess you like

Origin blog.csdn.net/weixin_43134049/article/details/112536621
Recommended