英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论