vscode中PyLint报错Unable to import解决方案

在导入其它文件夹中py文件的时候,即使在代码中添加了指定路径,由于Pylint 无法检测到该文件,会给出Unable to import 'xxx'的错误提示

需要在项目目录下添加.pylintrc文件指定要引用文件所在的目录

# .pylintrc 文件用于为pllint进行自定义配置

[MASTER]
# XXX 应被替换为你指定的文件夹如(./custom_lib)
init-hook='base_dir="XXX"; import sys,os,re; _re=re.search(r".+\/" + base_dir, os.getcwd()); project_dir = _re.group() if _re else os.path.join(os.getcwd(), base_dir); sys.path.append(project_dir)'

[MESSAGES CONTROL]
# Find available symbolic names in:
# https://docs.pylint.org/features.html
disable=locally-disabled,trailing-whitespace,fixme,missing-docstring,protected-access,invalid-name,super-init-not-called,star-args,no-self-argument,inherit-non-class,no-method-argument,no-self-use,unused-argument,too-many-return-statements,too-many-branches,too-many-function-args,too-many-instance-attributes,too-many-locals,bad-continuation,unnecessary-lambda,redefined-variable-type,global-statement,line-too-long,mixed-indentation,bad-whitespace,missing-final-newline

猜你喜欢

转载自www.cnblogs.com/wangyunjie/p/8855943.html
今日推荐