Skip to content

"Module 'numpy' has no ... member" error even with extension-pkg-whitelist=numpy set in pylint.rc #779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mpconte opened this issue Jan 12, 2016 · 60 comments
Assignees
Labels
Milestone

Comments

@mpconte
Copy link

mpconte commented Jan 12, 2016

I'm always receiving "Module 'numpy' has no member" error when I run pylint on my code, even though I have set

extension-pkg-whitelist=numpy
in my pylint.rc file

Numpy version = 1.5.2
Astroid version = 1.4.3

@PCManticore
Copy link
Contributor

Can you post an example for which you get the error?

@mpconte
Copy link
Author

mpconte commented Jan 12, 2016

import numpy as np
dtype = np.float64

Pylint says:
Module 'numpy' has no 'float64' member

It does this for every other numpy dtype that has a byte number following the dtype name or np.str_
i.e. np.float and np.int are ok to pylint, but not np.float64 or np.int32

@mpconte
Copy link
Author

mpconte commented Jan 26, 2016

I'm also getting the same issue with pylint versions
1.5.3 and 1.5.4

@PCManticore
Copy link
Contributor

I didn't have time to look into this just yet, but I presume that astroid.brain can't find the place where float64 is created (https://github.com/PyCQA/astroid/blob/master/astroid/brain/brain_numpy.py). What could move this forward would be to see where exactly np.float64 is defined and what's different about in in brain_numpy.py. With this information, we might modify brain_numpy accordingly.

@PCManticore PCManticore added this to the 1.6.0 milestone May 9, 2016
@Titan-C
Copy link

Titan-C commented Jun 14, 2016

I have this issue for all numpy functions as if 'extension-pkg-whitelist=numpy' would have no influence. pylint version, astroid 1.4.4

@PCManticore
Copy link
Contributor

I'm not sure if all of them are like that, but there are some of them which are generated dynamically somewhere around in this file https://github.com/numpy/numpy/blob/master/numpy/core/numerictypes.py. extension-pkg-whitelist does not help in this case, but providing some hints would lead to a better result.

@pgdr
Copy link

pgdr commented Mar 2, 2017

Also affects pylint 1.6.5, even with --extension-pkg-whitelist=numpy On file

import numpy
numpy.float64

the output (incorrectly) is:

$ python -m pylint -E --extension-pkg-whitelist=numpy ex.py
************* Module ex
E:  2, 0: Module 'numpy' has no 'float64' member (no-member)

@leftrk
Copy link

leftrk commented Mar 29, 2017

me too

pylint 1.6.4, 
astroid 1.4.9

and in vim with w0rp/ale.
It shows E1101: (no-member) Module 'numpy.random' has no 'randint' member.

@pgdr
Copy link

pgdr commented Apr 19, 2017

@PCManticore is this anything that will be prioritized? Do you have any idea what can be done to fix this issue?

I'm thinking especially getting extension-pkg-whitelist to be respected, not fixing the issue with mislabeling the numpy members as non-members.

@PCManticore
Copy link
Contributor

extension-pkg-whitelist does something different than what it would suggest. Since there are some bits of numpy written in C, pylint tries to import them in order to built an AST from a live object. This, of course, has some security implications and might not be desired at all, which is why these modules are exempted through a flag, e.g extension-pkg-whitelist. The problem is that those members are added in pure Python code, using dynamic features of Python, such as globals modifications and whatnot, which don't fall in the scope of extension-pkg-whitelist. And it is also pretty hard to understand by a static analysis tool nevertheless.
This issue will probably get some priority at some point, as you can see it is scheduled for 2.0 milestone, but I can't promise anything until that point.
The problem can be solved, most probably, by a brain tip in astroid, but it requires someone that knows numpy internals well enough and it also requires a good enough solution (e.g only adding the correct members to numpy's module that patches itself with these dynamically generated members). As such, I didn't have enough time to work on this.

@gergelypolonkai
Copy link

As a workaround, I have created a small PyLint plugin, which will silence such warnings:

from astroid import MANAGER
from astroid import scoped_nodes

import numpy

def register(linter):
    pass

def transform(modu):
    if modu.name == 'numpy':
        for f in numpy.__dict__.keys():
            modu.locals[f] = [scoped_nodes.Class(f, None)]

MANAGER.register_transform(scoped_nodes.Module, transform)

@sam-s
Copy link

sam-s commented Jun 21, 2017

still present with

pylint 1.7.1, 
astroid 1.5.3

@Cartucho
Copy link

Cartucho commented Jul 1, 2017

@PCManticore it's still not working with:

pylint 1.7.2, 
astroid 1.5.3
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609]

marmistrz added a commit to marmistrz/golem that referenced this issue Aug 16, 2017
@marmistrz
Copy link

The same happens with twisted.internet.reactor:

from twisted.internet.reactor import run

causes an error:

E:  1, 0: No name 'run' in module 'twisted.internet.reactor' (no-name-in-module)

Pylint:

pylint 1.7.2, 
astroid 1.5.3
Python 3.6.2 (default, Jul 20 2017, 03:52:27) 
[GCC 7.1.1 20170630]

marmistrz added a commit to marmistrz/golem that referenced this issue Aug 16, 2017
We use a generated .pylintrc. Important notices:
* Linting members of numpy and twisted.internet.reactor is disabled due
to a bug in pylint. See pylint-dev/pylint#779
* We ignore minilight since it's a forked third-party codebase
* For the configuration ease we enabled `unsafe-load-any-extension`.
This makes it trivial to lint C modules. Alternatively, we could simply
whitelist them with `extension-pkg-whitelist` but this would be tedious.
* Only changed files will be linted in CircleCI.
marmistrz added a commit to marmistrz/golem that referenced this issue Aug 16, 2017
We use a generated .pylintrc. Important notices:
* Linting members of numpy and twisted.internet.reactor is disabled due
to a bug in pylint. See pylint-dev/pylint#779
* We ignore minilight since it's a forked third-party codebase
* For the configuration ease we enabled `unsafe-load-any-extension`.
This makes it trivial to lint C modules. Alternatively, we could simply
whitelist them with `extension-pkg-whitelist` but this would be tedious.
* Only changed files will be linted in CircleCI.
marmistrz added a commit to marmistrz/golem that referenced this issue Aug 16, 2017
We use a generated .pylintrc. Important notices:
* Linting members of numpy and twisted.internet.reactor is disabled due
to a bug in pylint. See pylint-dev/pylint#779
* We ignore minilight since it's a forked third-party codebase
* For the configuration ease we enabled `unsafe-load-any-extension`.
This makes it trivial to lint C modules. Alternatively, we could simply
whitelist them with `extension-pkg-whitelist` but this would be tedious.
* Only changed files will be linted in CircleCI.
* The list of disabled checks is intented to be small. We will disable
the check we find useless/inappropriate/overzealous as we encounter
them in the code.
marmistrz added a commit to marmistrz/golem that referenced this issue Aug 16, 2017
We use a generated .pylintrc. Important notices:
* Linting members of numpy and twisted.internet.reactor is disabled due
to a bug in pylint. See pylint-dev/pylint#779
* We ignore minilight since it's a forked third-party codebase
* For the configuration ease we enabled `unsafe-load-any-extension`.
This makes it trivial to lint C modules. Alternatively, we could simply
whitelist them with `extension-pkg-whitelist` but this would be tedious.
* Only changed files will be linted in CircleCI.
* The list of disabled checks is intented to be small. We will disable
the check we find useless/inappropriate/overzealous as we encounter
them in the code.
marmistrz added a commit to marmistrz/golem that referenced this issue Aug 16, 2017
We use a generated .pylintrc. Important notices:
* Linting members of numpy and twisted.internet.reactor is disabled due
to a bug in pylint. See pylint-dev/pylint#779
* We ignore minilight since it's a forked third-party codebase
* For the configuration ease we enabled `unsafe-load-any-extension`.
This makes it trivial to lint C modules. Alternatively, we could simply
whitelist them with `extension-pkg-whitelist` but this would be tedious.
* Only changed files will be linted in CircleCI.
* The list of disabled checks is intented to be small. We will disable
the check we find useless/inappropriate/overzealous as we encounter
them in the code.
marmistrz added a commit to marmistrz/golem that referenced this issue Aug 17, 2017
We use a generated .pylintrc. Important notices:
* Linting members of numpy and twisted.internet.reactor is disabled due
to a bug in pylint. See pylint-dev/pylint#779
* We ignore minilight since it's a forked third-party codebase
* For the configuration ease we enabled `unsafe-load-any-extension`.
This makes it trivial to lint C modules. Alternatively, we could simply
whitelist them with `extension-pkg-whitelist` but this would be tedious.
* Only changed files will be linted in CircleCI.
* The list of disabled checks is intented to be small. We will disable
the check we find useless/inappropriate/overzealous as we encounter
them in the code.
marmistrz added a commit to marmistrz/golem that referenced this issue Aug 17, 2017
We use a generated .pylintrc. Important notices:
* Linting members of numpy and twisted.internet.reactor is disabled due
to a bug in pylint. See pylint-dev/pylint#779
* We ignore minilight since it's a forked third-party codebase
* For the configuration ease we enabled `unsafe-load-any-extension`.
This makes it trivial to lint C modules. Alternatively, we could simply
whitelist them with `extension-pkg-whitelist` but this would be tedious.
* Only changed files will be linted in CircleCI.
* The list of disabled checks is intented to be small. We will disable
the check we find useless/inappropriate/overzealous as we encounter
them in the code.
marmistrz added a commit to marmistrz/golem that referenced this issue Aug 17, 2017
We use a generated .pylintrc. Important notices:
* Linting members of numpy and twisted.internet.reactor is disabled due
to a bug in pylint. See pylint-dev/pylint#779
* We ignore minilight since it's a forked third-party codebase
* For the configuration ease we enabled `unsafe-load-any-extension`.
This makes it trivial to lint C modules. Alternatively, we could simply
whitelist them with `extension-pkg-whitelist` but this would be tedious.
* Only changed files will be linted in CircleCI.
* The list of disabled checks is intented to be small. We will disable
the check we find useless/inappropriate/overzealous as we encounter
them in the code.
marmistrz added a commit to marmistrz/golem that referenced this issue Aug 17, 2017
We use a generated .pylintrc. Important notices:
* Linting members of numpy and twisted.internet.reactor is disabled due
to a bug in pylint. See pylint-dev/pylint#779
* We ignore minilight since it's a forked third-party codebase
* For the configuration ease we enabled `unsafe-load-any-extension`.
This makes it trivial to lint C modules. Alternatively, we could simply
whitelist them with `extension-pkg-whitelist` but this would be tedious.
* Only changed files will be linted in CircleCI.
* The list of disabled checks is intented to be small. We will disable
the check we find useless/inappropriate/overzealous as we encounter
them in the code.
marmistrz added a commit to marmistrz/golem that referenced this issue Aug 17, 2017
We use a generated .pylintrc. Important notices:
* Linting members of numpy and twisted.internet.reactor is disabled due
to a bug in pylint. See pylint-dev/pylint#779
* We ignore minilight since it's a forked third-party codebase
* For the configuration ease we enabled `unsafe-load-any-extension`.
This makes it trivial to lint C modules. Alternatively, we could simply
whitelist them with `extension-pkg-whitelist` but this would be tedious.
* Only changed files will be linted in CircleCI.
* The list of disabled checks is intented to be small. We will disable
the check we find useless/inappropriate/overzealous as we encounter
them in the code.
marmistrz added a commit to marmistrz/golem that referenced this issue Aug 17, 2017
We use a generated .pylintrc. Important notices:
* Linting members of numpy and twisted.internet.reactor is disabled due
to a bug in pylint. See pylint-dev/pylint#779
* We ignore minilight since it's a forked third-party codebase
* For the configuration ease we enabled `unsafe-load-any-extension`.
This makes it trivial to lint C modules. Alternatively, we could simply
whitelist them with `extension-pkg-whitelist` but this would be tedious.
* Only changed files will be linted in CircleCI.
* The list of disabled checks is intented to be small. We will disable
the check we find useless/inappropriate/overzealous as we encounter
them in the code.
marmistrz added a commit to marmistrz/golem that referenced this issue Aug 17, 2017
We use a generated .pylintrc. Important notices:
* Linting members of numpy and twisted.internet.reactor is disabled due
to a bug in pylint. See pylint-dev/pylint#779
* We ignore minilight since it's a forked third-party codebase
* For the configuration ease we enabled `unsafe-load-any-extension`.
This makes it trivial to lint C modules. Alternatively, we could simply
whitelist them with `extension-pkg-whitelist` but this would be tedious.
* Only changed files will be linted in CircleCI.
* The list of disabled checks is intented to be small. We will disable
the check we find useless/inappropriate/overzealous as we encounter
them in the code.
@Marriaga
Copy link

Marriaga commented Feb 17, 2018

astroid (1.6.1)
pylint (1.8.2)
numpy (1.14.0)
"E1101:Module 'numpy' has no 'float32' member"

@repentsinner
Copy link

@hippo91 I don't think the fix is in 1.6.1; it's on 1.6.x but by my reading of pylint-dev/astroid#486 we're not going to see it until 1.6.2 which hasn't been released by @PCManticore yet?

@PCManticore
Copy link
Contributor

Yes, 1.6.2 is not yet released, I'll do it today. Also folks please take some time to appreciate the tremendous work that @hippo91 is doing with this issue, this one wasn't easy and as a result of his work, numpy's support is getting top notch.

@wanghran
Copy link

astroid (1.6.1)
isort (4.3.4)
pylint (1.8.2)
numpy (1.14.2 )
E1101:Module 'numpy' has no 'float64' member

@PCManticore
Copy link
Contributor

I just released pylint 1.8.3 and astroid 1.6.2, which includes all the fixes to numpy that @hippo91 worked on. I'm closing this issue, thank you so much @hippo91 for the hard work!

@dinio31
Copy link

dinio31 commented Mar 21, 2018

I just tested these latest versions with the example I gave above and on my python projects.

No more need to declare numpy in the extension-pkg-whitelist and generated-members fields of .pylintrc! pylint now works like a charm with numpy!
And pylint immediately exhibited a bug in my code that was previously hidden by these .pylintrc settings!

Many thanks @hippo91 for the great work!
Thanks a lot @PCManticore for the releases!

Tested with versions:

python==2.7.13
numpy==1.12.1
pylint==1.8.3
astroid==1.6.2

@hippo91
Copy link
Contributor

hippo91 commented Mar 24, 2018

@dinio31 thank you for your reply!
It is always pleasant to know this work is useful.

@sam-s
Copy link

sam-s commented May 23, 2018

I still see E1101, no-member: Module 'numpy' has no 'floating' member with

pylint 1.9.1, 
astroid 1.6.4
Python 3.6.5 (default, Mar 30 2018, 06:41:53) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]

and

>>> np.version.version
'1.14.3'
>>> np.floating
<class 'numpy.floating'>

should I open a new issue?

@PCManticore
Copy link
Contributor

@sam-s yes, please.

@burakcank
Copy link

burakcank commented May 25, 2018

The problem still persists with the 'cv2' module in vscode, even if I added extension-pkg-whitelist=cv2 to the .pylintrc.

Versions:

astroid           1.6.4
opencv-python     3.4.1.15
pylint            1.9.1

image

@PCManticore
Copy link
Contributor

The numpy support has nothing to do with cv2. Please open a separate issue.

@burakcank
Copy link

@PCManticore Sorry, it was mentioned here once by @akorp, that's why I brought it up again.

@mogocat
Copy link

mogocat commented Jun 15, 2018

Same issues here with cv2

pylint 1.9.2,
astroid 1.6.5
Python 3.6.5

fepegar added a commit to fepegar/optimally-oriented-flux that referenced this issue Aug 1, 2018
@PaulStubbs
Copy link

Still broken with OpenCV v4:
OpenCV 4.0.0
VSCode 1.30.0
pylint 2.2.2
astroid 2.1.0
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609]

@hippo91
Copy link
Contributor

hippo91 commented Dec 21, 2018

@PaulStubbs thanks for the report.
What is exactly the problem please?
I'm not sure it deals with numpy.
If it is directly related to the OpenCV module, please open another issue.
Thank you again.

@hippo91
Copy link
Contributor

hippo91 commented Dec 21, 2018

@PaulStubbs
Is your issue related to #2426 ?

@lai-bluejay
Copy link

If you don't want to add more config, please add this code to your config file, instead of 'whitelist'.

{
"python.linting.pylintArgs": ["--generate-members"],
}

relevent question: how-do-i-get-pylint-to-recognize-numpy-member

@aafshinfard
Copy link

I am facing the same problem with updated pylint (2.148.0) for numpy.linalg.
Actually, I import numpy and scipy and use scipy.linalg in my code; and when I run pylint I get an error stating that E1101: Module 'numpy.linalg' has no 'blas' member (no-member).

@sam-s
Copy link

sam-s commented Jun 17, 2019

I see Module 'numpy' has no 'float128' member with

pylint 2.3.1
astroid 2.2.5
Python 3.7.3 (default, Mar 27 2019, 09:23:15) 
[Clang 10.0.1 (clang-1001.0.46.3)]

(despite extension-pkg-whitelist=numpy which does take care of float64 et al)

Should I open a new issue?

@hippo91
Copy link
Contributor

hippo91 commented Jun 17, 2019

@sam-s, if i remember correctly, float128 is not necessarily present on all platforms. Instead of trying to detect what kind of platform numpy is running on, pylint's default is to emit such message.
I think it would need work that is not absolutely necessarily to handle such case.
What do you think about it?

@bthorsted
Copy link

If you don't want to add more config, please add this code to your config file, instead of 'whitelist'.

{
"python.linting.pylintArgs": ["--generate-members"],
}

relevent question: how-do-i-get-pylint-to-recognize-numpy-member

That pylint option is incorrect and actually makes pylint silently fail, thus making it look as though there are no errors, ever. The correct snippet is:

{
"python.linting.pylintArgs": ["--generated-members=numpy.*"],
}

However, this still does not work in VSCode. I am getting Function 'logical_and' has no 'reduce' member even though I am using

pylint 2.3.1
astroid 2.2.5
numpy 1.16.4

Should I open a new issue pertaining to this particular case of no-member?

@Alamnoor
Copy link

Alamnoor commented Mar 1, 2020

  1. On VScode: CTRL + Shift + P
  2. Choose "Preferences: Open Settings (JSON)"
  3. Add this line into JSON file: "python.linting.pylintArgs": ["--generate-members"]

Done, it works for me

Note: Make sure you choose "Preferences: Open Settings (JSON)", not "Preferences: Open Default Settings (JSON)"

Setting File would look like

{
"workbench.iconTheme": "vscode-icons",
"python.dataScience.sendSelectionToInteractiveWindow": true,
"kite.showWelcomeNotificationOnStartup": false,
"python.dataScience.askForKernelRestart": false,
"python.dataScience.jupyterServerURI": "local",
"python.pythonPath": "/usr/bin/python3",
"workbench.colorTheme": "Monokai",
"vsicons.dontShowNewVersionMessage": true,
"python.linting.pylintArgs": ["--generate-members"] }

@bthorsted
Copy link

  1. On VScode: CTRL + Shift + P
  2. Choose "Preferences: Open Settings (JSON)"
  3. Add this line into JSON file: "python.linting.pylintArgs": ["--generate-members"]

Done, it works for me

@Alamnoor I can assure you that it's not working. Try making a deliberate error and run pylint with that option. You will find out that you still get zero errors. The reason is that the option you added is not a real pylint option and it will cause pylint to fail silently when run through vscode. You can verify this by running pylint manually from the command line with that option and you will see the suppressed error. See my comment above for an explanation.

@kosyachniy
Copy link

kosyachniy commented Oct 8, 2021

.pylintrc

[MASTER]
extension-pkg-whitelist=pydantic

PyLint

main.py:7:0: [import-error] Unable to import 'pydantic'
main.py:8:0: [import-error] Unable to import 'pydantic.error_wrappers'

Versions

python 3.9
pylint 2.11.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests