This fixed my issue. According to the pypy.org , I used
pip install -U Flask-SQLAlchemy
Answer from SamithaP on Stack OverflowThis fixed my issue. According to the pypy.org , I used
pip install -U Flask-SQLAlchemy
OP follow up:
The only way I could get this import working was to manually copy the directories* from where they'd installed with pip3 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages to /usr/local/lib/python3.7/site-packages
I realise this isn't ideal but it works. Again, no virtual environment as currently new to python and following a tutorial.
After this I was getting two errors creating the database
sqlite3.OperationalError: unable to open database file
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file
This line needs 4 forward slashes after sqlite (and one L in sqlite)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////Users/username/IdeaPython/BookApp/booksdb.db"
*flask_sqlalchemy
*Flask_SQLAlchemy-2.4.0.dist-info (current at time)
*sqlalchemy
*SQLAlchemy-1.3.4.dist-info (current at time)
import "flask_sqlalchemy" could not be resolve
Apparently flask_sqlalchemy is not found, but it is installed : Forums : PythonAnywhere
python - E0401: "Unable to import 'flask_sqlalchemy'" - Stack Overflow
No module called flask_sqlalchemy : Forums : PythonAnywhere
Videos
I am using virtualenv and I install flask-sqlaclchemy using pip install Flask-SQLAlchemy but still the vscode give an error
» pip install Flask-SQLAlchemy
install flask-sqlalchemy out of the virtual environment first.
$ pip install Flask-SQLAlchemy
I had these 2 errors:
Unable to import 'flask_sqlalchemy'
Unable to import 'flask_migrate'
The problem was this line in my models.py file:
id = db.Column(db.Integer, primary_key=True)
I had a comma at end of the line and it caused me an hour of wasted time.
I think you have a mismatch between your pip and python versions.
check your pip version pip --version,
if it is pip3
you can try this,
sudo apt-get install python3-sqlalchemy
This should work.
~$ python3
>>import sqlalchemy
If you are on mac, try
pip install flask-sqlalchemy
instead of
pip3 install flask-sqlalchemy.
It works with some warnings, but was able to succesfully connect to the database and create the tables. "FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning."
I had the same error. Changed my system python by doing the following in VS Code: Under the view menu select 'show command pallet'. One of the commands you can then select from the command palette is 'Python: Select Interpreter'. Selecting this option will allow you to choose which version of python to use.
This post is pretty old but I found a different solution that might help others out. For me, the issue was my IDE/Python (venv). I am using Visual Studio ver. 1.57.1 as of now on Windows 10.
- Open Visual Code.
- Go to 'View' on the toolbar.
- Click on 'Command Palette...' (or press CTRL + SHIFT + P on Windows).
- Search for: 'Python Select Interpreter'.
- Click on: 'Enter interpreter path...' followed by 'Find...'.
- Go to your (venv) scripts folder:
project_folder/venv/Scripts. - Select
python.exeorpythonw.exeinside of yourproject_folder/venv/Scriptsfolder.
That's all.
The Flask-SQLAlchemy was installed in my virtual environment (venv). But my VSCode was using the system/PC Python interpreter to find the packages instead of the venv.
Hope this helps someone else out.
Did you install flask-sqlalchemy? It looks like you have SQLAlchemy installed but not the Flask extension. Try pip install Flask-SQLAlchemy in your project's virtualenv to install it from PyPI.
I just experienced the same problem. Apparently, there is a new distribution method, the extension code is no longer stored under flaskext.
Source: Flask CHANGELOG This worked for me:
from flask_sqlalchemy import SQLAlchemy
Try to install it with these commands , (it worked for me):
pip install flask-sqlalchemy
pip3 install flask-sqlalchemy
Refer this site for Example
or
Refer the official guide site for installation
if it doesnt worked then try above commands with --user at the end of both commands
another solution maybe to install an IDE (if you are not using one) like PyCharm ; rather than a some simple text editors
First command installs package to python v2.x Second one installs package to python 3.x
If you want to use 3.x to run your app ;then go to configuration and change it to python 3.x
Refer this for Getting Help / Development / Bug reporting
Try using this command:
pip install flask-sqlalchemy --user
If you are using PyCharm go to file and select Invalidate caches and restart.