How do I get Pylint to recognize NumPy members?

I am running Pylint on a Python project. Pylint makes many complaints about being unable to find NumPy members. How can I avoid this while avoiding skipping membership checks?

From the code:

import numpy as np

print np.zeros([1, 4])

Which, when ran, I get the expected:

[[ 0. 0. 0. 0.]]

However, Pylint gives me this error:

E: 3, 6: Module 'numpy' has no 'zeros' member (no-member)

For versions, I am using Pylint 1.0.0 (astroid 1.0.1, common 0.60.0) and trying to work with NumPy 1.8.0.


Solution 1:

If using Visual Studio Code with Don Jayamanne's excellent Python extension, add a user setting to whitelist NumPy:

{
    // Whitelist NumPy to remove lint errors
    "python.linting.pylintArgs": [
        "--extension-pkg-whitelist=numpy"
    ]
}

Solution 2:

I had the same issue here, even with the latest versions of all related packages (astroid 1.3.2, logilab_common 0.63.2, pylon 1.4.0).

The following solution worked like a charm: I added numpy to the list of ignored modules by modifying my pylintrc file, in the [TYPECHECK] section:

[TYPECHECK]

ignored-modules = numpy

Depending on the error, you might also need to add the following line (still in the [TYPECHECK] section):

ignored-classes = numpy

Solution 3:

I was getting the same error for a small NumPy project I was working on and decided that ignoring the NumPy modules would do just fine. I created a .pylintrc file with:

$ pylint --generate-rcfile > ~/.pylintrc

And following paduwan's and j_houg's advice I modified the following sectors:

[MASTER]

# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code
extension-pkg-whitelist=numpy

and

[TYPECHECK]

# List of module names for which member attributes should not be checked
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=numpy

# List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set). This supports can work
# with qualified names.
ignored-classes=numpy

and it "fixed" my issue.