Search code examples
pythonherokuslack-apislack

Getting error "ImportError: No module named" on Heroku but not locally


I'm getting ImportError: No module named when I try to deploy my app to heroku but the app builds fine locally. Here are the logs from Heroku

Traceback (most recent call last):
File "mr_meeseeks.py", line 4, in <module>
    import Helpers.Plugin_Handler as Plugin_Handler
File "/app/Helpers/Plugin_Handler.py", line 5, in <module>
    from Utils.constants import Plugin_Type
ImportError: No module named 'Utils.constants'

Here is my file structure: File Structure

As far as I can tell, Utils/constants.py exists. In case it's relevant, this is a SlackBot. The rest of the code can be found here.


Solution

  • The Python Interpreter looks for modules under the $PYTHONPATH environment variable. It looks like you or your editor (my editor does this when I mark a directory as sources) root has added SlackBot/ to $PYTHONPATH.

    I myself encountered this error when I marked a directory as sources root.

    You have a few options:

    Also, a note on style: python classes should be CamelCase and python modules should be lowercase_with_underscores. If you have an editor like PyCharm, your editor can fix these issues automatically, and more.

    PEP 8 is the official python style guide, although I recommend using a linter so these issues can be automatically detected and fixed.