I’m setting up a Flask application on Digitalocean and have Python 3.7 installed and the latest version of Flask. When running the app inside a virtualenv and trying to run the application using python3.7 application.py I get the following error message:

Traceback (most recent call last):
    File "application.py", line 11, in <module>
        from config import *
ModuleNotFoundError: No module named 'config'

What puzzles me is that config.py is located in the same folder as application.py, and not in a subfolder. I have duplicated the setup on my local machine, also running Python 3.7 and inside a virtualenv, and the importing (and the app) works flawlessly.

I’ve tried importing “config.py” instead of just “config” but didn’t make a difference. I also tried specifying exactly what it should import (instead of using ’*’) but that didn’t make a difference either.

Your thoughts on why it can’t find config?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

If your config.py file and init.py file on the same path, move config.py file outside of the path and place the same in root.

for example if both are in “APP” directory, move the config.py and place it inside the root director of “APP” directory

Hello,

What I could suggest here is trying to install the module first:

pip3 install config

Then run it again and see how it goes.

Hope that this helps!
Regards,
Bobby

  • Bobby,

    Not sure you had a chance to read my original message, but config is not an installable module - it’s a local .py file located in the same folder

    • Hi @productionmanager,

      Thank you for the clarification.

      In this case, what I could suggest is to add the config module directory path to the environment variable, so it would look something like this:

      import sys
      sys.path.append("/path/to/your/config/module/")
      import config
      

      Hope that this helps!
      Regards,
      Bobby

    • If your config.py and init.py is on the same path (Inside “app”), then move the config.py outside “app”. Once done, do run the application again using the following command.
      $ python run.py
      OR
      $ flask run

Submit an Answer