The basic structure of my program looks like this:
top_dir
__init__.py
readme.rst
sub_dir
__init__.py
sub_sub_dir
__init__.py
example_module.py
sub_sub_dir2
__init__.py
module_with_import.py
In Pycharm all imports just work fine. For example I use the following import in 'module_with_import.py':
from sub_dir.sub_sub_dir.example_module import function
However if I run pylint on module_with_import.py I will get the following error:
Unable to import 'sub_dir.sub_sub_dir.example_module' (import-error)
Does anybody see what's wrong here?
How do I fix pylint import error? Solution 1: (configure workspace settings to point to fully qualified python executable): Solution 2: (open VS Code from an activated virtual environment): Cause: The path to the python executable is incorrect.
ImportError is raised when a module, or member of a module, cannot be imported. There are a two conditions where an ImportError might be raised. If a module does not exist.
Press ctrl+shift+p then type pylint in search bar then click on enable/ON. After this run the code your issue is resolved.
Module (package) cannot have minus in name. Rename Sub-dir
to sub_dir
, Sub-sub-dir
to sub_sub_dir
and Sub-sub-dir2
to sub_sub_dir2
.
Next read PEP-8 The Python Style Guide
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With