I have a file named main.py
with the following code:
#!/usr/bin/env python3
import utils.stuff
if __name__ == "__main__":
print("hi from main.py")
utils.stuff.foo()
In the directory with main.py
, I have a subdirectory named utils
which has a file named stuff.py
with the following code:
print("hi from stuff.py")
def foo():
print("foo")
If I run ./main.py
from the command line, I get the following output:
hi from stuff.py
hi from main.py
foo
That is exactly what I expect. However, if I run pylint main.py
, I get the following output:
No config file found, using default configuration
************* Module main
C: 1, 0: Missing module docstring (missing-docstring)
E: 3, 0: No name 'stuff' in module 'utils' (no-name-in-module)
E: 3, 0: Unable to import 'utils.stuff' (import-error)
E: 7, 4: Module 'utils' has no 'stuff' member (no-member)
followed by some more detailed statistics that do not seem relevant to my question. Why is this happening? What can I do to make Pylint aware of utils/stuff.py
? I am running Python 3.5.2, Pylint 1.6.4 and OS X 10.11.6.
If you are getting the dreaded no-member error, there is a possibility that either: pylint found a bug in your code. You're launching pylint without the dependencies installed in its environment. pylint would need to lint a C extension module and is refraining to do so.
To solve unresolved import error in Python, set your Python path in your workspace settings. If you are working with Visual Studio Code and import any library, you will face this error: “unresolved import”. Then reload the VSCode, and it will fix that error.
you can ignore it by adding a comment in the format # pylint: disable=[problem-code] at the end of the line where [problem-code] is the value inside pylint(...) in the pylint message – for example, abstract-class-instantiated for the problem report listed above.
You need a create utils/__init__.py
. This will make python aware of the submodule and also allows you to run any code you want to happen on import. If you don't want anything to run then just include a docstring.
I got this error when my function was named start:
from views import start
It worked when I changed the name of the function.
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