0

Im creating my own simple package that i will upload on pypi that generates jokes on my native language. While creating the package I'm bugged with this error : ModuleNotFoundError: No module named 'utils'

Here is my folder structure :

Myjokes/
    myjokes/
          
           data/
               jokes.json
           utils/
               helpers.py
           __init__.py
           jokes.py

when i am in the Myjokes/ directory and i run the python -c "from myjokes import jokes" it runs but when i run the functions inside the jokes file it displays a module not found error : from utils.helpers import get_jokes_by_count , get_joke_by_dialect , pinoy_jokes ModuleNotFoundError: No module named 'utils'

if i go inside myjokes/ directory which is the subdirectory of Myjokes i can run the jokes.py script via import jokes and everything is running. i dont know why this is happenin I'm fairly new to python.

IAN VINCENT
  • 49
  • 3
  • 9
  • https://stackoverflow.com/q/12172791/7976758 Found in https://stackoverflow.com/search?q=%5Bpython%5D+absolute+relative+import – phd Aug 21 '21 at 23:16

1 Answers1

0

Python doesn't know that your utils/ folder is supposed to be treated like a python package unless you include an __init__.py in that folder as well.

Try adding a blank __init__.py file inside utils/ and see if that works for you.

Zachary Cross
  • 2,298
  • 1
  • 15
  • 22