When running PyLint from the Wing IDE on Windows, users may encounter an error stating "Unable to import 'module'" when importing modules from a sub-directory (package). This occurs despite the fact that the import works correctly at runtime due to the top-level directory being included in the Python path.
To resolve this issue, two options are available:
Modify the PYTHONPATH environment variable to include the directory above the module. This ensures that PyLint can locate the module during its analysis.
Alternatively, users can edit their PyLint configuration file (~/.pylintrc) to include the path to the module manually. This involves adding the following line to the configuration file:
[MASTER] init-hook='import sys; sys.path.append("/path/to/root")'
(Note that for different versions of PyLint, the [MASTER] section may need to be changed to [General]).
By following these steps, users can configure PyLint to successfully import modules from sub-directories, resolving the "Unable to import" error and ensuring accurate code analysis.
The above is the detailed content of How to Resolve PyLint \'Unable to Import\' Error for Module Imports in Sub-Directories?. For more information, please follow other related articles on the PHP Chinese website!