Flask-Web-App-Tutorial icon indicating copy to clipboard operation
Flask-Web-App-Tutorial copied to clipboard

init.py flask-sqlalchemy

Open yasmine-pog opened this issue 3 years ago • 6 comments

image i don't know how to fix this issue

yasmine-pog avatar Feb 17 '22 15:02 yasmine-pog

(Capitals don't matter btw) Try: pip uninstall Flask-SQLAlchemy pip install -U Flask-SQLAlchemy

Then it should work, worked for me both on Ubuntu 20.04 and Windows 10

ghost avatar Feb 26 '22 00:02 ghost

thank you so much it finally worked , I struggled to find the solution, can't thank you enough!

yasmine-pog avatar Feb 28 '22 07:02 yasmine-pog

No problem!

ghost avatar Mar 05 '22 09:03 ghost

Hi Guys I am trying to access the app.config from init.py in views.py but it is not recognising app.config I just want to access the app.config in views.py. Do i need to import something?

in init.py def create_app(): app = Flask(name) app.config['SECRET_KEY'] = 'xftry' app.config['UPLOAD_FOLDER'] = myfolder

In views.py: (not recognising app) f.save(os.path.join(app.config['UPLOAD_FOLDER'], f.filename))

Thank you

gemin55 avatar Apr 05 '22 05:04 gemin55

Hi,

Could someone help with this error please?

ModuleNotFoundError: No module named 'flask_sqlalchemy'

I've uninstalled and then re-installed as per Bludenz recommendations.

nadeem@nadeem-VirtualBox:~/VSCode_projects/Flask_Web_App$ pip freeze | grep -i flask Flask==2.2.2 Flask-Login==0.6.2 Flask-SQLAlchemy==3.0.2

pip uninstall Flask-SQLAlchemy Found existing installation: Flask-SQLAlchemy 3.0.2 Uninstalling Flask-SQLAlchemy-3.0.2: Would remove: /home/nadeem/.local/lib/python3.8/site-packages/Flask_SQLAlchemy-3.0.2.dist-info/* /home/nadeem/.local/lib/python3.8/site-packages/flask_sqlalchemy/* Proceed (Y/n)? y Successfully uninstalled Flask-SQLAlchemy-3.0.2

Re-installed pip install -U Flask-SQLAlchemy

Defaulting to user installation because normal site-packages is not writeable Collecting Flask-SQLAlchemy Using cached Flask_SQLAlchemy-3.0.2-py3-none-any.whl (24 kB) Requirement already satisfied: Flask>=2.2 in /home/nadeem/.local/lib/python3.8/site-packages (from Flask-SQLAlchemy) (2.2.2) Requirement already satisfied: SQLAlchemy>=1.4.18 in /home/nadeem/.local/lib/python3.8/site-packages (from Flask-SQLAlchemy) (1.4.42) Requirement already satisfied: Werkzeug>=2.2.2 in /home/nadeem/.local/lib/python3.8/site-packages (from Flask>=2.2->Flask-SQLAlchemy) (2.2.2) Requirement already satisfied: click>=8.0 in /home/nadeem/.local/lib/python3.8/site-packages (from Flask>=2.2->Flask-SQLAlchemy) (8.1.3) Requirement already satisfied: importlib-metadata>=3.6.0 in /home/nadeem/.local/lib/python3.8/site-packages (from Flask>=2.2->Flask-SQLAlchemy) (5.0.0) Requirement already satisfied: Jinja2>=3.0 in /home/nadeem/.local/lib/python3.8/site-packages (from Flask>=2.2->Flask-SQLAlchemy) (3.1.2) Requirement already satisfied: itsdangerous>=2.0 in /home/nadeem/.local/lib/python3.8/site-packages (from Flask>=2.2->Flask-SQLAlchemy) (2.1.2) Requirement already satisfied: greenlet!=0.4.17 in /home/nadeem/.local/lib/python3.8/site-packages (from SQLAlchemy>=1.4.18->Flask-SQLAlchemy) (1.1.3.post0) Requirement already satisfied: zipp>=0.5 in /usr/lib/python3/dist-packages (from importlib-metadata>=3.6.0->Flask>=2.2->Flask-SQLAlchemy) (1.0.0) Requirement already satisfied: MarkupSafe>=2.0 in /home/nadeem/.local/lib/python3.8/site-packages (from Jinja2>=3.0->Flask>=2.2->Flask-SQLAlchemy) (2.1.1) Installing collected packages: Flask-SQLAlchemy Successfully installed Flask-SQLAlchemy-3.0.2 nadeem@nadeem-VirtualBox:~/VSCode_projects/Flask_Web_App$

Run main.py and still get the following error.

/bin/python3.9 /home/nadeem/VSCode_projects/Flask_Web_App/main.py nadeem@nadeem-VirtualBox:~/VSCode_projects/Flask_Web_App$ /bin/python3.9 /home/nadeem/VSCode_projects/Flask_Web_App/main.py Traceback (most recent call last): File "/home/nadeem/VSCode_projects/Flask_Web_App/main.py", line 2, in from website import create_app File "/home/nadeem/VSCode_projects/Flask_Web_App/website/init.py", line 2, in from flask_sqlalchemy import SQLAlchemy ModuleNotFoundError: No module named 'flask_sqlalchemy' nadeem@nadeem-VirtualBox:~/VSCode_projects/Flask_Web_App$

nadeembu avatar Oct 26 '22 04:10 nadeembu

I just fixed it. :)

My default Python version is Python 3.8.10.

I've updated the Python interpreter in VSCode to match the version I'm running and it's cleared that error.

cntrl + shift + p python: select interpreter Choose correct version.

nadeembu avatar Oct 26 '22 04:10 nadeembu