简体   繁体   中英

VSCode/pylint reports module win32event as unresolved import when module is installed

It's a small annoyance, but, pywin32 modules get reported as unresolved imports by the python linter in VSCode.

I've got pywin32 installed, and I'm able to import the module(s) in a terminal session, and when the script runs.

My python.pythonPath is set correctly in my settings.json.

The linter just can't seem to find the modules.

But if I use the following syntax the linter works, but the import obviously fails at run time.

import win32.lib.win32event

Any ideas on how I can "make" VSCode or the linter match the correct import?

Pylint has a configuration file, loaded by the command-line switch --rcfile. One of the entries in the configuration file is ignored-modules= . A comment line describes this option as a "list of module names for which member attributes should not be checked". There are several other options that are similar.

These options are needed because pylint is a static type checker, meaning that it doesn't load the module but merely inspects its source code. In the case of a module like the win32 collection, it uses .dll files that pylint cannot inspect. Therefore there is no way that pylint can figure out what names are exposed by win32. So the best you can do is tell pylint to suppress error messages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM