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

Smith Dwayne
  • 2,675
  • 8
  • 46
  • 75
  • This question is I believe very related to https://stackoverflow.com/questions/1899436/pylint-unable-to-import-error-how-to-set-pythonpath – N. Gast Oct 22 '19 at 08:23

1 Answers1

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.

BoarGules
  • 16,440
  • 2
  • 27
  • 44
  • 1
    ... or if you want to disable it permanently, you can add `"python.linting.pylintArgs": ["--disable=E401"]` to your `settings.json`. – Joey Mar 14 '19 at 14:29
  • This answers does not seem correct. A correct answer is https://stackoverflow.com/questions/1899436/pylint-unable-to-import-error-how-to-set-pythonpath – N. Gast Oct 22 '19 at 08:22
  • 1
    In my case what worked was to define a new interpreter for python as suggested by https://code.visualstudio.com/docs/python/environments – N. Gast Oct 22 '19 at 09:03
  • 8
    Please note the error code is `E0401` not E401 (https://github.com/Microsoft/vscode-python/issues/1185) – Mahm00d Aug 17 '20 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 Dec 08 '20 at 18:52