flask_sqlalchemy module cant be found error - python-3.x

So I want to use the flask_sqlalchemy module in my web app. But when I run "flask run" it gives me the following error:
from flask_sqlalchemy import
SQLAlchemy
ModuleNotFoundError: No module
named 'flask_sqlalchemy'
I am running this in a virtual env with python3.7 and pip3. It says that all packages have been installed. Ive tried a whole bunch of things with no luck.

So after trying a whole bunch of stuff. Setting the environment variable FLASK_ENV=development and then to production somehow fixed.

Related

how to fix flask import eror (there is no Flask in flask)

i installed flask in the cmd using the pip install flask command and i also tested it in the cmd and it works.
But when i go to pycharm all the modules i download using pip are for some reason in lib/site_packages
instead of just being in site_packages.the lib folder
and then i do "from flask import Flask"
and it says that " cannot import name 'Flask' from 'flask' (C:\Users\User\PycharmProjects\pythonProject1\flask.py)"
the error
there is no Flask in flask
Change the py file name to anything else. naming your flask file as flask.py will create a namespace conflict.

Why is beautifulsoup4 not importing to my script?

Before I explain my problem I want to start by saying that I have looked all over this site for an answer and tried almost all of them, to no avail.
I am on a windows machine, in a virtual environment. I have a command prompt opened in the virtual environment. I have already pip installed over a dozen modules that are being imported into my script and working perfectly. When I run the line:
from bs4 import BeautifulSoup
I get this error:
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
In my command prompt I can do 'pip list' and see beautifulsoup4 version 4.9.0. As well as in my virtual environment folder I can go into Lib\site-packages and I see all of my other installed packages that work in my script, along with a folder called 'bs4' and one called 'beautifulsoup4-4.9.0.dist-info'. I have also tried pip uninstall beautifulsoup4 and then re installed it, confirming that it did not show up in pip list between running those.
I am completely at a loss for why I cannot access the bs4 module. Anyone have any ideas for me to try? Thanks in advance.
EDIT: I am currently using VS Code and have pip installed several other modules including pymysql and google-api packages. I have successfully connected to my gmail and Amazon RDS database, so i know the other modules are working properly. For some reason its only BeautifulSoup4 I am having issues with.
EDIT 2: I opened up ipython from my virtual environment, and I entered from bs4 import beautifulsoup and i get this error.
ImportError: cannot import name 'beautifulsoup' from 'bs4' (C:\Users\Brian\Desktop\Projects\VirtualENVs\test_venv\Lib\site-packages\bs4\__init__.py)
EDIT 3: I finally just opened a new command prompt and pip installed beautifulsoup4 onto my computer outside of the virtual environment and now it works fine.

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.

ImportError: No module named flask using MAC VSCODE

ScreenGrab of error when trying to import db I created
You either need to install Flask from pip, or something similar, or Python is not able to find the location of Flask if it is, in fact, installed.
At your Python prompt, try this to see where it is looking for libraries:
>> import sys
>> print (sys.path)

ModuleNotFoundError: No module named 'flask_wtf' in python

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.

Resources