Import flask_wtf works fine with jupyter notebook but command prompt rises error
jupyter notebook runs the code: from flask_wtf import FlaskForm
with no problem
but command prompt rises error: ModuleNotFoundError:no module named flask_wtf
maybe has to do with anaconda?
I have tried to run the solution from the instructor so there would be no typo, but flask_wtf still can not be found.
I only have one version of python,
I am not using a virtual environment
I have installed Flask-WTF with pip and conda
pip install flask_wtf shows satisfied already
conda install flask_wtf shows not found in the channels.
I’m not totally sure what is going wrong but I can offer at least a temporary fix. If you run pip show Flask-WTF
it will show the location (folder) where the package is installed (bolded in below output)
~ % python3 -m pip show Flask-WTF Name: Flask-WTF Version: 0.14.3 Summary: Simple integration of Flask and WTForms. Home-page: https://github.com/lepture/flask-wtf Author: Dan Jacob Author-email: [email protected] License: BSD Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages Requires: WTForms, Flask, itsdangerous Required-by:
In order to import the module this folder must be in the sys.path
list, you can check if it is by doing "path" in sys.path
from an interpreter:
>>> import sys >>> "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages" in sys.path True
If this gives you True
and you are unable to import the module I have no idea what is wrong and I would blame anaconda and install python from the official site.
If this gives False
I would still blame anaconda for having pip install to a location that isn’t even used by python, but at least in that case I can offer a fix, you can simply add the folder to sys.path
at the start of your program:
import sys # this path would be different for you, what ever is shown under `Location:` in `pip show Flask-WTF` sys.path.append("/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages") import flask_wtf
I hope this is at least enough to unblock you so you can keep programming. I’m not sure how to even determine what is actually going wrong.