By niteshinath
I’ve followed this tutorial pretty much to the letter:
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps
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 166.147.104.146] 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 166.147.104.146] mod_wsgi (pid=10918): Exception occurred processing WSGI script '/var/www/flask/flask.wsgi'.
[Wed Jul 09 09:35:02 2014] [error] [client 166.147.104.146] Traceback (most recent call last):
[Wed Jul 09 09:35:02 2014] [error] [client 166.147.104.146] File "/var/www/flask/flask.wsgi", line 10, in <module>
[Wed Jul 09 09:35:02 2014] [error] [client 166.147.104.146] from flask import app as application
[Wed Jul 09 09:35:02 2014] [error] [client 166.147.104.146] File "/var/www/flask/flask/__init__.py", line 1, in <module>
[Wed Jul 09 09:35:02 2014] [error] [client 166.147.104.146] from flask import Flask
[Wed Jul 09 09:35:02 2014] [error] [client 166.147.104.146] 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?
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!
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/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
Check out the the Flask documentation on the topic.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.