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

Posted nerocloud

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 

以上是关于vscode中PyLint报错Unable to import解决方案的主要内容,如果未能解决你的问题,请参考以下文章

vscode安装pylint报错如何解决

解决忽略VScode中Python插件pylint报错的问题

VSCODE 报错 Module ‘xx‘ has no ‘xx‘ member pylint(no-member)

VSCODE 报错 Module ‘xx‘ has no ‘xx‘ member pylint(no-member)

解决pylint报错tab缩进

vscode Unable to attach to CoreCLR. Access is denied