13

I am using vscode for coding my python code. I use pandas, numpy and requests library in my code. If I run the code, It works fine. But in VScode editor, in the problems section, always Its says the message as

Unable to import 'numpy' (pylint import error)
Unable to import 'pandas' (pylint import error)
Unable to import 'requests' (pylint import error)

I searched in StackOverflow questions to find the answer to this problem, It says to install pandas using pip. I did that also. But still I am facing the same problem. How to fix this problem in vs code editor

1

1 Answer 1

14

This is not telling you that numpy or pandas is not installed. It is telling you that pylint can't verify your numpy and pandas calls. Most of numpy and pandas is written in C, not Python.

The pylint documentation says

Linting C extension modules is not supported out of the box, especially since pylint has no way to get an AST object out of the extension module.

So there is no problem with your code, even if VSCode says it is a problem. It is a technical limitation of pylint. If it worries you, disable pylint message E401 for these import statements. Put #pylint: disable=E401 on the same line as your import statement.

5
  • 1
    ... or if you want to disable it permanently, you can add "python.linting.pylintArgs": ["--disable=E401"] to your settings.json.
    – Joey
    Commented Mar 14, 2019 at 14:29
  • This answers does not seem correct. A correct answer is stackoverflow.com/questions/1899436/…
    – N. Gast
    Commented Oct 22, 2019 at 8:22
  • 1
    In my case what worked was to define a new interpreter for python as suggested by code.visualstudio.com/docs/python/environments
    – N. Gast
    Commented Oct 22, 2019 at 9:03
  • 8
    Please note the error code is E0401 not E401 (github.com/Microsoft/vscode-python/issues/1185)
    – Mahm00d
    Commented Aug 17, 2020 at 10:14
  • 2
    I think this answer is correct in the cause, though you may need to use a different code, either E0401 (as just mentioned) or in my case E0611, since I was doing from foo import bar vs. just import bar.
    – S'pht'Kr
    Commented Dec 8, 2020 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.