Why can’t the module be found anymore? My app has been running for 2 years and it always worked like this?
Repl link/Link to where the bug appears:
Screenshots, links, or other helpful context:
The error i suddenly start getting which i never got before (i didn’t change the code at all)
Traceback (most recent call last):
File "main.py", line 4, in <module>
from modules.keep_alive import keep_alive
ModuleNotFoundError: No module named 'modules.keep_alive'; 'modules' is not a package
Hi @KaanGogcay , welcome tk the forma!
Can you rename the folder name to something else?
Or try this:
with open('/modules/keep_alive.py','r') as file:
Hope this helps!
Hey @KaanGogcay Welcome to the forums!
With your file structure, there is no module named modules, or did you mean a package that is named module? If so, please run in shell
pip install modules
poetry add modules
Hope this helps resolve your problem
OP has a folder called modules, and wants to take a function from a file in the folder.
Could probably rename the
modules folder to
mods or something else.
That was what I said above ^^
Try simply adding a
__init__.py file to
modules, you don’t even need anything in it.
you have created a library called modules. But every Python library should have a file
__init__.py in the library folder. In your case, to the file
__init__.py you don’t need to put anything.
__init__.py inside the folder tells the Python interpreter that it is not just a folder with files, but a module whose files can be accessed via
Addition to this post:
I wrote from modules.keep_alive import keep_alive
Because this was for me the way to import the function keep_alive() from the file keep_alive.py located in the folder modules.
Is there somethint wrong in the way i did it? Because it used to work for 2 years straight but randomly decided not to work anymore.