pythonpippython-3.7

How can I fix ModuleNotFoundError: No module named 'pyjokes'?


I have installed pyjokes with pip3:

sudo pip3 install pyjokes

And have it in the terminal when I do pip3 list:

enter image description here

My script:

import pyjokes

joke = pyjokes.get_joke('english','neutral')
print(joke)

I get this error when I run the script:

enter image description here

How can I fix this error?


Solution

  • I searched on my own and saw this helped me You import sys to your file and use sys.path.append() for adding the file name to your file it worked strange with pyjokes.get_joke() though?

    import sys
    
    sys.path.append('/usr/local/lib/python3.7/dist-packages/')
    
    import pyjokes
    
    print(pyjokes.get_joke())