简体   繁体   English

即使python执行程序成功导入它,vscode中的pylint导入错误

[英]pylint import error in vscode even though python executer successfully imports it

I am using vscode for coding my python code.我正在使用 vscode 来编码我的 python 代码。 I use pandas, numpy and requests library in my code.我在我的代码中使用了 pandas、numpy 和 requests 库。 If I run the code, It works fine.如果我运行代码,它工作正常。 But in VScode editor, in the problems section, always Its says the message as但是在 VScode 编辑器中,在问题部分,它总是说消息为

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 .我在 StackOverflow 问题中搜索了这个问题的答案,它说使用pip安装pandas I did that also.我也是这样做的。 But still I am facing the same problem.但我仍然面临同样的问题。 How to fix this problem in vs code editor如何在 vs 代码编辑器中解决此问题

This is not telling you that numpy or pandas is not installed.这并不是告诉您未安装numpypandas It is telling you that pylint can't verify your numpy and pandas calls.它告诉您pylint无法验证您的numpypandas调用。 Most of numpy and pandas is written in C, not Python.大多数numpypandas是用 C 编写的,而不是 Python。

The pylint documentation says pylint 文档

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. Linting C 扩展模块不支持开箱即用,特别是因为 pylint 无法从扩展模块中获取 AST 对象。

So there is no problem with your code, even if VSCode says it is a problem.所以你的代码没有问题,即使 VSCode 说这是一个问题。 It is a technical limitation of pylint .这是pylint的技术限制。 If it worries you, disable pylint message E401 for these import statements.如果您担心,请为这些import语句禁用pylint消息 E401。 Put #pylint: disable=E401 on the same line as your import statement.#pylint: disable=E401import语句放在同一行。

Check if you have pylint installed.检查您是否安装了pylint。 To install pylint, type in the terminal:要安装 pylint,请在终端中输入:

$ pip install pylint

(This worked for me) (这对我有用)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM