Error: ImportError: No module named flask while installing flask application on ubuntu with apache2 server

Posted January 3, 2017 14.5k views
ApachePythonUbuntu 16.04

I am trying to launch a simple flask application. I get the following error when I open the website:

[Tue Jan 03 05:06:43.521815 2017] [wsgi:error] [pid 16996] [remote] modwsgi (pid=16996): Exception occurred processing WSGI script ’/var/www/myyu/myyu.wsgi’.
[Tue Jan 03 05:06:43.521868 2017] [wsgi:error] [pid 16996] [remote] Traceback (most recent call last):
[Tue Jan 03 05:06:43.521920 2017] [wsgi:error] [pid 16996] [remote] File “/var/www/myyu/myyu.wsgi”, line 9, in <module>
[Tue Jan 03 05:06:43.521993 2017] [wsgi:error] [pid 16996] [remote] from _
init__ import app
[Tue Jan 03 05:06:43.522019 2017] [wsgi:error] [pid 16996] [remote] File “/var/www/myyu/”, line 1, in <module>
[Tue Jan 03 05:06:43.522059 2017] [wsgi:error] [pid 16996] [remote] from flask import Flask, render_template
[Tue Jan 03 05:06:43.522103 2017] [wsgi:error] [pid 16996] [remote] ImportError: No module named flask

I tried disabling virtualenv using the following command: a2dissite 000-default
I also enable the myyu.conf file I created.
My wsgi file looks like:
import sys

sys.path.insert(0, “/var/www/myyu”)

from init import app

Put logging code (and imports) here …

application = app

Here’s the directory structure:

I have also verified that is under if name == “main”: condition.

Can somebody please help?

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.

Submit an Answer
1 answer

add this code on yout myyu.wsgi file and
restart apache
activate_this = '/path/to/env/bin/'
execfile(activate_this, dict(__file__=activate_this))

find more here

  • That solution works with Python 2.x versions however with Python 3 there is no “” file. I am running into a problem where Flask starts the app but cannot import my own modules that are in the same directory as my “” file.