I'm using virtualenv to set up a new project. I installed a lot of things using virtualenv pip from the script folder like below:
flask\scripts\pip install Flask-WTF
I have no other packages installed in the global python folder. My code looks like this:
# Importing TextField and BooleanField is not working...
from flask.ext.wtf import Form, TextField, BooleanField
from flask.ext.wtf import Required
class LoginForm(Form):
openid = TextField('openid', validators=[Required()])
remember_me = BooleanField('remember_me', default=False)
and other packages are found like sqlalchemy also installed only in the virtual environment.
The error I get is:
(flask) D:\Development\grading>flask\Scripts\python.exe restserver.py Traceback (most recent call last):
File "restserver.py", line 1, in <module> from app import app
File "D:\Development\grading\app\__init__.py", line 12, in <module> from forms import LoginForm
File "D:\Development\grading\app\forms.py", line 1, in <module> from flask.ext.wtf import Form, TextField, BooleanField
File "D:\Development\grading\flask\lib\site-packages\flask\exthook.py", line 87, in load_module
raise ImportError('No module named %s' % fullname) ImportError: No module named flask.ext.wtf.TextField
Form is found but not TextField and BooleanField. What is the problem here?
Update I just looked through some of the Flask-WTF code and found this:
from flask.ext.wtf import Form
from wtforms.fields import TextField, BooleanField
from wtforms.validators import Required
Am I using examples from an older version or something?
activate.bat
script is setting up your shell variables to point to the virtualized versions of things like python.exe and pip.exe. Also, you shouldn't put the virtual environment inside your source code directory (as it appears you are doing). The best practice is to put all virtualenvironments in their own separate directory and use the activate scripts to adjust your shell. – Selfregulatingapp
folder. I'm actually not using the scripts to install but running pycharm so I don't have to activate anything while changing project. It's handling all that automagically for me. Thanks anyway though! – Slab