Reputation: 3340
I'm following @Miguel flask mega tutorial which is great. In chapter 3 he talks about web forms and flaskWTF extension, installing the extension like this sudo pip install Flask-WTF
resulted in
Successfully installed Flask-WTF Flask WTForms Werkzeug Jinja2 itsdangerous markupsafe
but when executing ./run.py
i get an error:
No module named flask.ext.wtf`
I've google the error and tried to run it like this: flask/bin/python run.py
but got the same error, also tried flask/bin/activate
Update: if you run into the same error this is what solved the issue for me I've installed the following, for sure they are not all needed but since i didn't go one by one to find out which one did the trick i'm listing them all
flask/bin/pip install flask-login
flask/bin/pip install flask-openid
flask/bin/pip install flask-mail
flask/bin/pip install sqlalchemy
flask/bin/pip install flask-sqlalchemy
flask/bin/pip install sqlalchemy-migrate
flask/bin/pip install flask-whooshalchemy==0.55a
flask/bin/pip install flask-wtf
flask/bin/pip install pytz
flask/bin/pip install flask-babel
flask/bin/pip install flup
Upvotes: 18
Views: 51906
Reputation: 1277
I had the same problem. I read steps 1 again to check where I slipped.
Remember to install the necessary modules for your project.
In this case the following:
flask/bin/pip install flask-login
flask/bin/pip install flask-openid
flask/bin/pip install flask-mail
flask/bin/pip install sqlalchemy
flask/bin/pip install flask-sqlalchemy
flask/bin/pip install sqlalchemy-migrate
flask/bin/pip install flask-whooshalchemy==0.55a
flask/bin/pip install flask-wtf
flask/bin/pip install pytz
flask/bin/pip install flask-babel
flask/bin/pip install flup
Since you've created this virtual environment, "flask", all the modules installed are available only in your virtual environment(flask).
Remember to run "flask/Scripts/python run.py" and not "python run.py"
Upvotes: 7
Reputation: 2266
The API has changed from:
from flask.ext.wtf import Form
to:
from flask_wtf import Form
Upvotes: 21
Reputation: 8449
Do this: . flask/bin/activate
Then it'll work properly.
Cheers.
Upvotes: 0
Reputation: 1
you can run the command:pip install -U Flask-WTF ,and change to from flask.ext.wtf import Form from wtforms import TextField, BooleanField from wtforms.validators import Required
Upvotes: -1
Reputation: 2359
Even after changing different import styles and re-installing flask, flask-wtf, if it still does not works : then in the config.py("config.py may be of different name eg app_config.py etc)
insert the line
sys.path.insert(0, os.path.join(os.path.dirname(__file__),
'venv/Lib/site-packages'))
set the lib path of your own app , in my case it was "venv/Lib/site-packages"
Upvotes: 1
Reputation: 2665
You are probably using the import style from the older versions:
from flask.ext.wtf import Form, TextField, BooleanField
from flask.ext.wtf import Required
The import style changed starting from 0.9.0 version. Be sure to update your imports:
from flask.ext.wtf import Form
from wtforms.fields import TextField, BooleanField
from wtforms.validators import Required
You can find the note about this change in the upgrade section of docs:
https://flask-wtf.readthedocs.org/en/latest/upgrade.html#version-0-9-0
Upvotes: 14
Reputation: 9440
jbub's right, but is addressing a problem you will run into, rather then the problem you're currently having-- the tutorial is dated, and doesn't mention what versions of the library the user should be using, so if you do as the tutorial says you are going to run into problems unless you change your import lines to match what jbub says.
But-- the problem you're currently having isn't that-- if it were, your error would be No module named flask.ext.wtf.Textfield
at the moment it can't see the library at all.
That means you haven't installed the Flask-WTF library to the correct location, in this case, it looks like it should be installed in your virtual environment, which you seem to have created under a directory called flask
, to make things a little clearer, I'm going to refer to that directory as venv
.
The virtual environment is a little room, you need to step into it, then put things on the shelf (install your libraries).
So, first you need to activate your virtual environment, so launch a terminal and navigate to the virtual environment you created (the venv
dir), and then activate it (walk into the room):
source bin/activate
Your console prompt will change to show you've activated it for this terminal-- now your terminal is standing in the room, so you can install your libraries as required, you don't even need sudo
any more, because your little room is safe for your user to play in, it doesn't effect the world outside it's door. So lets install flask-wtf (and any other libraries you may need by asking pip):
pip install flask-wtf
etc.
Now, because you're in the virutal environment, it will launch the version of python that exists there and see all the libraries you've set up, which is what you want. So while the terminal prompt shows your virtual environment is still active, you can launch your run.py
file by running python run.py
and it should solve your issue.
Upvotes: 5