Search code examples
pythonpython-3.xpython-importimporterror

Getting an error for a module that I definitely imported


import pyinputplus as pyip

while True:
    prompt='Want to know how to keep an idiot busy for hours?\n'
    response=pyip.inputYesNo(prompt)
    if response=='no':
        break
    print('Thank you. Have a nice day.')

When I run my above code , I get this error:

Traceback (most recent call last):
  File "c:\users\XXXXXX\mu_code\idiot.py", line 1, in <module>
    import pyinputplus as pyip
  File "c:\users\XXXXXX\mu_code\pyinputplus\__init__.py", line 15, in <module>
    import pysimplevalidate as pysv # type: ignore
ModuleNotFoundError: No module named 'pysimplevalidate'

I cannot figure it out. The module is definitely installed. I've even moved it from the folder it was originally installed in to the mu folder where the py file is saved. Any help would be appreciated.


Solution

  • The ModuleError says that you do not have pysimplevalidate installed.

    Using the same python executable as you are using to run your script (idiot.py), run

    python -m pip install pysimplevalidate
    

    or, even more bullet-proof:

    <path_to_python.exe> -m pip install pysimplevalidate
    

    If you are not sure what python executable the script is using, you can check it with
    # put this on top of your script
    import sys
    print(sys.executable) # will print C:\path\to\python.exe