ModuleNotFoundError: No module named 'flask_wtf' in python - python-3.x

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 ?

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)?

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.

Related

Problems with python3 and virtualenvwrapper on Mac Big Sur

I am following [these][1] instructions on setting up a macOS virtual environment. I have followed all the instructions but when I get to the last part where I have to reload the startup file by making the following call in the terminal:
source ~/.bash_profile
I get the error message:
/Applications/Xcode.app/Contents/Developer/usr/bin/python3: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper')
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 and that PATH is
set properly.
I have tried different solutions from the internet but I am unable to get a fix.
Running which python3 and which virtualenvwrapper.sh returns:
/opt/anaconda3/bin/python3
/usr/local/bin/virtualenvwrapper.sh
My initial thoughts are that this may be due to the fact that I am running both anaconda python and regular python on the same computer.
[1]: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/development_environment

Why am I getting ModuleNotFoundError: No module named 'dpkt'?

When I run
import dpkt
It gives
ModuleNotFoundError: No module named 'dpkt'
But I already installed dpkt.
install dpkt cmd
Does anyone know how I can fix this?
I am using window10, python3.
I had the same issue today. I found out that when I installing the dpkt module, it was getting installed onto an environment different than the one I was using in pyCharm.
I found the answer to this post very helpful to explain my issue: https://stackoverflow.com/a/52608375/2411380
I fixed my issue by using the terminal inside pyCharm to install dpkt, then it worked.
I also found a suggestion to use all packages installed in conda inside pyCharm: https://stackoverflow.com/a/49097897/2411380

ModuleNotFoundError: No module named 'zope.deprecation'

Okay, I have lost a day in debugging the script and now I don't have any other option to post a question on StackOverflow. I have a python script which installs Apache Airflow on the machine using a requirement.txt file nothing rocket science simply
sudo pip3 install -r requirement.txt
The problem is during installation I am getting an exception
ModuleNotFoundError: No module named 'zope.deprecation'
at a line which is trying to execute following statement
from airflow.models.variable import Variable
The script has three stages
First: It updates the OS using somewhat apt-get update and also installs some system libraries
Second: It invokes airflow initdb etc
Third: It actually tries to create some specific entries in airflow meta-database, and Its here in this stage I am invoking the statement from airflow.models.variable import Variable which throws an exception
I install all dependencies in stage First so the Module zope.deprecation is also installed via requirement.txt file. The module is there in site-packages folder but It doesn't get imported and throws an exception
I know there are already 7700+ question with title ModuleNotFoundError on StackOverflow and I don't declare that I checked out them all but I did my homework and tried various solutions but none are working for me, Few links I checked out are below
adding directory to sys.path /PYTHONPATH
Unable to import a module that is definitely installed
Python: Installed a local package with pip3, but got module not found error
I can't share the code because of policy issues, but I hope you guys understand.
Any help would be appreciated!
there is a error by zope and zope.deprecation.
you can do this:
pip uninstall zope
pip uninstall zope.deprecation
and then:
pip install zope.deprecation

Unable to use gitpython ImportError

Tried to run a script I wrote yesterday again today and ran into this:
ImportError: cannot import name 'Repo' from 'git' (/usr/local/lib/python3.7/site-packages/git/__init__.py)
I am at a complete loss. On a new computer so the only thing different install wise would have been that I installed pycharm. I am currently trying to run through bash shell on a mac. The exact code was running as excepted earlier, no code changes.
Things I have tried:
uninstalling/reinstalling python
uninstalling/reinstalling pip
uninstalling/reinstalling gitpython
Running on:
mac catalina
python version 3.7.6
pip version 20.0.1
As a side note, the script works as intended until the automated git push. Wondering if I should just make the os calls myself and not worry about this?
I really dont understand what I did/am doing wrong here.
EDIT:
Again, sorry as this is my first mac computer. I did a brew uninstall of python3 and reinstalled through the app store to 3.8.
ImportError: cannot import name 'is_cygwin_git' from partially initialized module 'git.util' (most likely due to a circular import) (/Library/Frameworks/Python.framework/
I know cygwin is for windows, but I figured I'd play along and trying a pip install pycygwin.
Install threw an error asking for cython, so I did another pip install and tried again. The pycygwin then complained gcc was missing so I did a brew install of gcc. With gcc installed and correctly on path, it still says it cant find it and exits with
build/cygwin/_cygwin.c:611:10: fatal error: 'sys/cygwin.h' file not found
#include <sys/cygwin.h>
^~~~~~~~~~~~~~
1 error generated.
error: command 'gcc' failed with exit status 1
Thinking I might just try a different package manager? Currently, an attempt to rerun the script yeilds
ImportError: cannot import name 'Repo' from partially initialized module 'git' (most likely due to a circular import)
To which I investigated but I shouldn't have any overlapping dependancies.
On the script throwing the error I'm using:
import csv
import yaml
import os
from git import Repo
and on the wrapper I made and imported, I'm using:
import subprocess
import re
Will update if I get any further on this, would love some suggestions.
EDIT:
Importing using just import git works throws a different error, like the python is trying to get itself?
ImportError: cannot import name '<file name>' from '<file name>'
If I change the file name and try to run it, it comes backs with:
ImportError: cannot import name '<old file name>' from '<old file name>'
***FIXED****
Uninstall of python through homebrew
Reinstall of python through mac app store
Uninstall/Reinstall of modules through pip
Saving the file under a new name and deleting the old one
Still have absolutely no idea why/how this happened but the above worked for me. If anyone knows why something like this can happen, I would love to know. Cheers.

virtualenv can't find modules

So I had been working with virtualenvs a couple months ago but had to stop for a while and now I don't seem to be able to get it working again.
Here is what I did
D:\CS\Python_Projects\HomeCenter>venv\Scripts\activate
(venv) D:\CS\Python_Projects\HomeCenter>pip freeze
You are using pip version 6.0.8, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Flask==0.10.1
Flask-SQLAlchemy==2.0
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
SQLAlchemy==1.0.8
waitress==0.8.9
Werkzeug==0.10.4
(venv) D:\CS\Python_Projects\HomeCenter>server.py
Traceback (most recent call last):
File "D:\CS\Python_Projects\HomeCenter\server.py", line 3, in <module>
from waitress import serve
ImportError: No module named 'waitress'
(venv) D:\CS\Python_Projects\HomeCenter>
Same happens if I were to run app.py, it won't find flask. I have been using PyCharm and when I check there it tells me the interpreter is pointing towards 3.4.2 virtualenv at D:\CS\Python_Projects\HomeCenter\venv
So why can't it find the modules?
Oh contents of server.py in case it's relevant
from waitress import serve
import os
from app import app
port = int(os.environ.get('PORT', 9999))
serve(app, host='0.0.0.0', port=port)
Hello I am korean student so I can't English not well. Please understand.
In my case, I have a well operated program but suddenly occured "not found" error like you after update mac os to BigSur.
but I finally found solution.
when before update I compiled by "source venv/fileName.py" but after update I compile by "python3 venv/fileName.py" then well operate
You try it too.
A couple of things could have happened here:
Use which python and which pip to check if both are from the virtual env itself.
As dirn suggested in the comments, it might be a PATH mixup. The packages were installed in the virtual environment but the script was executed from outside the environment interpreter. (Use venv\Scripts\python.exe <filename.py> instead of just filename to execute).

Resources