Home > other >  ModuleNotFoundError even though __init.py__ exists
ModuleNotFoundError even though __init.py__ exists

Time:02-01

I have a discord bot written with python. But the catch is, it only works when deployed on heroku but doesnot run locally at all.

This is the folder structure

- feed 
  - __init__.py
  - token.py
  - main.py
-requirements.txt

When I run the command python3.9 feed/main.py, it gives the following error:

    from feed import token
    ModuleNotFoundError: No module named 'feed'

What is the issue here? Mind you that the code runs without any errors on heroku with the same command. I am on Ubuntu 21.04.

If I change feed to .feed, I get other errors regarding absolute imports.

Please don't redirect me to other answers, I have tried it all.

CodePudding user response:

I don't know how Heroku works, but to get it running locally, try changing your import to:

import token

If you want to use feed as the parent directory, you can create a setup.py file and run pip install -e . in the folder. Then doing

from feed import token

should work as part of your development environment.

  •  Tags:  
  • Related