VS Code显示’random’模块被覆盖,如何解决?

huangapple go评论76阅读模式
英文:

VS Code showing 'random' module overriding, how to solve it?

问题

我导入了Python中的random模块并尝试运行它。它已被导入并且也正常运行,但是VSCode正在显示一个黄色警告线,并显示它正在与venv\Lib中的模块覆盖。它要求我将random.py的名称更改为其他内容,但我不能更改它,因为这将在其他库(如pandas、numpy、matplotlib和OpenCV)中引发错误。我该如何去除这个不必要的警告?

这是我遇到的错误:

"c:\Users\Syed M Tayyab\Desktop\VS Code ML\venv\Lib\random.py" 正在覆盖标准库模块 "random" PylancereportShadowedImports

我尝试将random.py更改为其他名称,但正如我之前提到的,更改random.py的名称可能会解决这个问题,但会在其他库中引发更多问题,因为random.py也在它们中导入了。

英文:

Check This Problem Image I imported the random module in Python and tried running it. It is imported and it is running good as well, but VSCode is giving a yellow line warning and showing that it is overriding with the module in venv\Lib. It is asking me to change the name of random.py to something else, which I can't change because it will give me errors in other libraries like pandas, numpy, matplotlib, and OpenCV. How can I remove this unwanted warning?

This is the error I'm getting:

"c:\Users\Syed M Tayyab\Desktop\VS Code ML\venv\Lib\random.py" is overriding the stdlib module "random"PylancereportShadowedImports

I tried changing random.py To something else but as I mentioned earlier that changing randon.py to something else may solve this problem but will generate more problems in other libraries as random.py is also imported in them.

答案1

得分: 0

这个错误可能是由于位于工作空间文件夹中的由venv创建的Python引起的识别错误引起的。您可以尝试将"python.analysis.exclude": ["venv"],添加到您的settings.json以解决它。

英文:

This error may be due to a recognition error caused by python created by venv being located in the workspace folder. You can try adding "python.analysis.exclude": ["venv"], to your settings.json to solve it.

huangapple
  • 本文由 发表于 2023年5月29日 03:56:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76353356.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定