2

I'm new to python so please be patient if i ask a silly question. I am trying to use flask wtf class as seen in a tutorial. My first line of the program is from flask_wtf import FlaskForm

It gives me the error ModuleNotFoundError: No module named 'flask_wtf' I have followed the following steps to make sure i have activated the virtual environment and flask wtf was installed in the virtual environment and not global.

Step 1: Went to the virtual environment and activated the environment C:\Users\Shraddha\PycharmProjects\FlaskProject\venv\scripts activate

Step 2: Installed flask wtf C:\Users\Shraddha\PycharmProjects\FlaskProject\venv\scripts pip install flask-wtf

I see that flask-wtf is installed correctly in the folder C:\Users\Shraddha\PycharmProjects\FlaskProject\venv\Lib\site-packages

However when i try to run it using command prompt it does not give me anything and when i try to run it using sublime text it gives me ModuleNotFoundError: No module named 'flask_wtf' error.

I know this is a flask_wtf import error because other programs are executing as expected. Any help ? enter image description here

Anup
  • 107
  • 3
  • 11
  • I am guessing that sublime text is accessing global packages, not the packages you have installed in **venv.** From where are you running your sublime? – Justice_Lords Mar 08 '19 at 16:34
  • Im not sure , I installed sublime text editor, and opened the file located in the virtual env, so i am assuming sublime is pointing correctly because it ran another program correctly. I think sublime is not able to recognize flask-wtf packages for some reason – Anup Mar 08 '19 at 17:03
  • you have a native python installation on your drive somewhere and then you have virtual python installations in each of your virtual environment folders. When you execute a python script the software needs to be instructed which python installation to choose. Just because the executable file is in one directory does not mean the python installation in that folder will be used - that is a bad assumption and likely your error – Attack68 Mar 10 '19 at 06:49
  • try here https://stackoverflow.com/questions/24963030/sublime-text3-and-virtualenvs – Attack68 Mar 10 '19 at 06:52

2 Answers2

2

If you start your virtual environment in the same dir as the file you are running doesn't that give access to the libraries in the install (ie everything shown in 'pip freeze' for the env)?

Robert
  • 21
  • 2
1

I faced same issue and tried all the approaches given on stackoverflow ImportError: No module named flask_wtf but didn't work for me. I am using ubuntu 20.04 LTS operating system.

Note: To follow the given step you must activate your virtual environment.

I used:

pip3 freeze

which listed following directories libries in my virtual environment

Then i tried the below command in the same directory

git clone git://github.com/lepture/flask-wtf.git

cd flask-wtf/

python3 setup.py install

Through the above commands i successfully installed flask_wtf as show below installed flask_wtf

but then i faced the below error as i used email_validator in my forms.py file:

Exception: Install 'email_validator' for email validation support

Then I installed email_validator using following command

pip3 install email_validator

Then i successfully run my flask application. I am sure it will work for you too.

Artaghal
  • 21
  • 5