Flask Deployment on Ubuntu 12.04 - 500 Error, logs: ImportError cannot import name Flask

I’ve followed this tutorial pretty much to the letter:

When I’m in the virtualenv, and running the Flask app on the localhost, I am able to:

curl localhost:5000

and receive a 200 http response “hello world”

But when I try to access the site from my browser, I get the following error log.

root@barchief:/var/www/flask# tail /var/log/apache2/error.log 
[Wed Jul 09 09:34:57 2014] [notice] caught SIGTERM, shutting down 
[Wed Jul 09 09:34:58 2014] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations 
[Wed Jul 09 09:35:02 2014] [error] [client] mod_wsgi (pid=10918): Target WSGI script '/var/www/flask/flask.wsgi' cannot be loaded as Python module. 
[Wed Jul 09 09:35:02 2014] [error] [client] mod_wsgi (pid=10918): Exception occurred processing WSGI script '/var/www/flask/flask.wsgi'. 
[Wed Jul 09 09:35:02 2014] [error] [client] Traceback (most recent call last): 
[Wed Jul 09 09:35:02 2014] [error] [client] File "/var/www/flask/flask.wsgi", line 10, in <module> 
[Wed Jul 09 09:35:02 2014] [error] [client] from flask import app as application 
[Wed Jul 09 09:35:02 2014] [error] [client] File "/var/www/flask/flask/", line 1, in <module> 
[Wed Jul 09 09:35:02 2014] [error] [client] from flask import Flask 
[Wed Jul 09 09:35:02 2014] [error] [client] ImportError: cannot import name Flask

I’m getting an ImportError for Flask, but flask has to be installed because I’m able to access it from localhost. What should I do?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Did you install Flask inside a virualenv? If so, you need to activate it in your .wsgi file At the top, before Flask is imported, add something like:

activate_this = '/path/to/env/bin/'
execfile(activate_this, dict(__file__=activate_this))

Check out the the Flask documentation on the topic.