0

I'm making a discord bot for me and my friends and whenever I run the code, I get this missing pycache module error, I have no idea why and I can't find anything googling python no module named __pycache__ or anything similar

this is the folder layout down to the music pycache, running the code with python bot from the directory above bot

folder layout

Full traceback:

Traceback (most recent call last):
  File "C:\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\zemo\bot\__main__.py", line 29, in <module>
    load_extensions(bot, './bot/cogs')
  File "D:\zemo\bot\__main__.py", line 16, in load_extensions
    load_extensions(client, entry_path)
  File "D:\zemo\bot\__main__.py", line 16, in load_extensions
    load_extensions(client, entry_path)
  File "D:\zemo\bot\__main__.py", line 21, in load_extensions
    client.load_extension(ext)
  File "C:\Python39\lib\site-packages\discord\ext\commands\bot.py", line 674, in load_extension    
    spec = importlib.util.find_spec(name)
  File "C:\Python39\lib\importlib\util.py", line 94, in find_spec
    parent = __import__(parent_name, fromlist=['__path__'])
ModuleNotFoundError: No module named 'cogs.music.__pycache__.music'
ontley
  • 91
  • 2
  • 8
  • just delete all __pycache__ folder and run again [how to delete Pycache folder](https://stackoverflow.com/questions/28991015/python3-project-remove-pycache-folders-and-pyc-files) – sahasrara62 Dec 27 '21 at 12:36
  • I'd have to do that each time I want to run the code though and I'd rather not – ontley Dec 27 '21 at 12:55

2 Answers2

0

You're trying to import from the __pycache__ folder when the music.py file isn't in it.
Try import cogs.music.music instead.

Adid
  • 1,504
  • 3
  • 13
  • I'm not importing it myself, __pycache__ folders are the interpreter's job, not mine yet it's breaking, it works when the pycache is deleted but it restores itself because the interpreter recompiles to pycache and then it doesn't work again – ontley Dec 27 '21 at 12:54
0

Turns out I needed a __init__.py file in the cogs directory

ontley
  • 91
  • 2
  • 8