ImportError: No module named config on Travis-CI build
import_string only takes absolute module imports. Since config
is not a top-level module, but part of webapp
, you need to specify webapp.config
. See http://flask.pocoo.org/docs/0.10/config/#configuring-from-files:
app = Flask(__name__)app.config.from_object('yourapplication.default_settings')app.config.from_envvar('YOURAPPLICATION_SETTINGS')
I came across this issue recently and could not figure it out until I had an epiphany after 2nd days by reading Markus's answer.
Just in-case someone out there is looking for a solution to load the configuration from config.py
and the flask app is using a package structure then ensure to provide the full classpath to the config class file in app.config.from_object()
.
For e.g., I had a configuration myproj/app/config.py
in my flask project myproj
and the class file with the configuration was DevelopmentConfig
. You need to provide it as follows:
app.config.from_object('app.config.DevelopmentConfig')
Another example would be if you put the same file under myproj/instance/config.py
then, you call it as:
app.config.from_object('instance.config.DevelopmentConfig')
During the development of your app, the easiest way to change your settings would be to put an environment variable in myapp/.env
file like so:
FLASK_APP=appAPP_SETTINGS="app.config.DevelopmentConfig"
and use the variable in your app.config.from_object()
call:
app.config.from_object(os.environ['APP_SETTINGS'])
But do remember that for the .env to take effect, you need to start your app with flask run
instead of running the app directly.