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

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

PYTHONPATH

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:

https://github.com/infiniteloopltd/HelloWorldFlask

Categories: Uncategorized
  1. No comments yet.
  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 )

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

%d bloggers like this: