Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No name in module" error from Pylint

Tags:

python

pylint

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.

like image 891
Elias Zamaria Avatar asked Oct 30 '16 23:10

Elias Zamaria


People also ask

Does Pylint have no member?

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.

How do I fix Pylint import error in VSCode?

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.

How do I ignore Pylint errors?

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.


2 Answers

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.

like image 193
Jacob Tomlinson Avatar answered Oct 06 '22 15:10

Jacob Tomlinson


I got this error when my function was named start:

from views import start

It worked when I changed the name of the function.

like image 28
user984003 Avatar answered Oct 06 '22 14:10

user984003