Search code examples
pythonpython-3.xpython-idle

ModuleNotFoundError on Python IDLE


enter image description here

The first one is that I've been having these errors since months ago. Every time I try to run these in python IDLE, it shows these kinds of errors. But it runs just fine when using terminal(python3 file-name.py). I've been anchoring interests in so many things and maybe I might have installed something unnecessary and that's bugging me.


Solution

  • Check the python path from IDLE:

    Example:

    import sys
    for path in sys.path:
        print(path)
    

    C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Lib\idlelib

    C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python37.zip

    C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\DLLs

    C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib

    C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64

    C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages

    List the python path where IDLE is referring

    Referring IDLE outputs, Go to Scripts path in CMD (Run as Administartor):

    example: cd C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts

    Here, you can do pip install <module_name> Then IDLE will refer this module