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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM