Search code examples
pythonvisual-studio-coderandomanacondaimporterror

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


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.


Solution

  • 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.