Home > Uncategorized > ModuleNotFoundError: No module named ‘flask’ #IIS #Windows

ModuleNotFoundError: No module named ‘flask’ #IIS #Windows


If you’re trying to run a Flask based Python Web app in IIS, and you get the following error,

Traceback (most recent call last):
File “C:\Python37\wfastcgi.py”, line 790, in main
env, handler = read_wsgi_handler(response.physical_path)
File “C:\Python37\wfastcgi.py”, line 630, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv(“WSGI_HANDLER”))
File “C:\Python37\wfastcgi.py”, line 613, in get_wsgi_handler
raise ValueError(‘”%s” could not be imported%s’ % (handler_name, last_tb))
ValueError: “index.app” could not be imported: Traceback (most recent call last):
File “C:\Python37\wfastcgi.py”, line 597, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File “.\index.py”, line 1, in <module>
from flask import Flask
ModuleNotFoundError: No module named ‘flask’

Then, here was my solution.

  1. Activate the virtualenv by typing myApp\Flask\Scripts>activate
  2. open a Python terminal, by typing python
  3. type import sys
  4. type print(sys.path)
  5. Copy all the paths (remove the escaping, and put ;’s instead of commas)
  6. Go to IIS > FastCGI Settings > Edit > Environment variables
  7. Then enter all the paths into the PYTHONPATH variable.

For reference, here is the github repo:


Categories: Uncategorized
  1. Randy
    May 6, 2020 at 7:45 pm

    I just wanted to say thank you for posting this. I have been battling this for days (I’m not a developer but I play one at work a little bit) with no success. This is the ONLY post that shows how to fix this as far as I am concerned. Thanks for taking the time to help someone out because it helped me immensely!


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: