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.
- Activate the virtualenv by typing myApp\Flask\Scripts>activate
- open a Python terminal, by typing python
- type import sys
- type print(sys.path)
- Copy all the paths (remove the escaping, and put ;’s instead of commas)
- Go to IIS > FastCGI Settings > Edit > Environment variables
- Then enter all the paths into the PYTHONPATH variable.
For reference, here is the github repo:
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!
LikeLike