2

I am looking to remove this error from my project. I recently did an install of flask_sqlalchemy in my .venv file. I am using python3.11, insomnia, docker, flask, flask_smorest and flask_sqlalchemy.

After looking through documentation I see that this error usually occurs when the wrong version is installed. I am not sure how to troubleshoot this issue. Any help would be appreciated as I have removed and readded flask-sqlalchemy on my .venv which didn't fix the issue.

Here is my .venv libs enter image description here

I added sql-alchemy and flask-sqlalchemy into my requirements.txt file which looks like this: `

flask
flask-smorest
python-dotenv
sqlalchemy
flask-sqlalchemy

` I received this response when I installed my requirements.txt

`

pip install -r requirements.txt
Requirement already satisfied: flask in ./.venv/lib/python3.11/site-packages (from -r requirements.txt (line 1)) (2.2.2)
Requirement already satisfied: flask-smorest in ./.venv/lib/python3.11/site-packages (from -r requirements.txt (line 2)) (0.40.0)
Requirement already satisfied: python-dotenv in ./.venv/lib/python3.11/site-packages (from -r requirements.txt (line 3)) (0.21.0)
Requirement already satisfied: sqlalchemy in ./.venv/lib/python3.11/site-packages (from -r requirements.txt (line 4)) (1.4.44)
Collecting flask-sqlalchemy
  Using cached Flask_SQLAlchemy-3.0.2-py3-none-any.whl (24 kB)
Requirement already satisfied: Werkzeug>=2.2.2 in ./.venv/lib/python3.11/site-packages (from flask->-r requirements.txt (line 1)) (2.2.2)
Requirement already satisfied: Jinja2>=3.0 in ./.venv/lib/python3.11/site-packages (from flask->-r requirements.txt (line 1)) (3.1.2)
Requirement already satisfied: itsdangerous>=2.0 in ./.venv/lib/python3.11/site-packages (from flask->-r requirements.txt (line 1)) (2.1.2)
Requirement already satisfied: click>=8.0 in ./.venv/lib/python3.11/site-packages (from flask->-r requirements.txt (line 1)) (8.1.3)
Requirement already satisfied: marshmallow<4,>=3.18.0 in ./.venv/lib/python3.11/site-packages (from flask-smorest->-r requirements.txt (line 2)) (3.19.0)
Requirement already satisfied: webargs<9,>=8.0.0 in ./.venv/lib/python3.11/site-packages (from flask-smorest->-r requirements.txt (line 2)) (8.2.0)
Requirement already satisfied: apispec[marshmallow]<7,>=6.0.0 in ./.venv/lib/python3.11/site-packages (from flask-smorest->-r requirements.txt (line 2)) (6.0.2)
Requirement already satisfied: greenlet!=0.4.17 in ./.venv/lib/python3.11/site-packages (from sqlalchemy->-r requirements.txt (line 4)) (2.0.1)
Requirement already satisfied: packaging>=21.3 in ./.venv/lib/python3.11/site-packages (from apispec[marshmallow]<7,>=6.0.0->flask-smorest->-r requirements.txt (line 2)) (21.3)
Requirement already satisfied: MarkupSafe>=2.0 in ./.venv/lib/python3.11/site-packages (from Jinja2>=3.0->flask->-r requirements.txt (line 1)) (2.1.1)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in ./.venv/lib/python3.11/site-packages (from packaging>=21.3->apispec[marshmallow]<7,>=6.0.0->flask-smorest->-r requirements.txt (line 2)) (3.0.9)
Installing collected packages: flask-sqlalchemy
Successfully installed flask-sqlalchemy-3.0.2
(.venv)  valemich@Vals-iMac  ~/Desktop/code/src/courses/udemy REST APIs with FlaskPython  pip --version

pip 22.3.1 from /Users/valemich/Desktop/code/src/courses/udemy REST APIs with FlaskPython/.venv/lib/python3.11/site-packages/pip (python 3.11)
(.venv)  valemich@Vals-iMac  ~/Desktop/code/src/courses/udemy REST APIs with FlaskPython  pip uninstall flask-sqlalchemy
Found existing installation: Flask-SQLAlchemy 3.0.2
Uninstalling Flask-SQLAlchemy-3.0.2:
  Would remove:
    /Users/valemich/Desktop/code/src/courses/udemy REST APIs with FlaskPython/.venv/lib/python3.11/site-packages/Flask_SQLAlchemy-3.0.2.dist-info/*
    /Users/valemich/Desktop/code/src/courses/udemy REST APIs with FlaskPython/.venv/lib/python3.11/site-packages/flask_sqlalchemy/*
Proceed (Y/n)? y
  Successfully uninstalled Flask-SQLAlchemy-3.0.2
(.venv)  valemich@Vals-iMac  ~/Desktop/code/src/courses/udemy REST APIs with FlaskPython  pip3 install flask_sqlalchemy
Collecting flask_sqlalchemy
  Using cached Flask_SQLAlchemy-3.0.2-py3-none-any.whl (24 kB)
Requirement already satisfied: Flask>=2.2 in ./.venv/lib/python3.11/site-packages (from flask_sqlalchemy) (2.2.2)
Requirement already satisfied: SQLAlchemy>=1.4.18 in ./.venv/lib/python3.11/site-packages (from flask_sqlalchemy) (1.4.44)
Requirement already satisfied: Werkzeug>=2.2.2 in ./.venv/lib/python3.11/site-packages (from Flask>=2.2->flask_sqlalchemy) (2.2.2)
Requirement already satisfied: Jinja2>=3.0 in ./.venv/lib/python3.11/site-packages (from Flask>=2.2->flask_sqlalchemy) (3.1.2)
Requirement already satisfied: itsdangerous>=2.0 in ./.venv/lib/python3.11/site-packages (from Flask>=2.2->flask_sqlalchemy) (2.1.2)
Requirement already satisfied: click>=8.0 in ./.venv/lib/python3.11/site-packages (from Flask>=2.2->flask_sqlalchemy) (8.1.3)
Requirement already satisfied: greenlet!=0.4.17 in ./.venv/lib/python3.11/site-packages (from SQLAlchemy>=1.4.18->flask_sqlalchemy) (2.0.1)
Requirement already satisfied: MarkupSafe>=2.0 in ./.venv/lib/python3.11/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

`

I have docker connected to flask to auto update. Here is my docker file:

FROM python:3.11
EXPOSE 5000
WORKDIR /app
COPY ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
COPY . .
CMD ["flask", "run", "--host", "0.0.0.0"]

I removed flask-sqlalchemy and reinstalled but received the same error.

Do I need to do something outside of my .venv to get this to work?

Any help would be greatly appreciated

Val Kuikman
  • 61
  • 1
  • 7
  • https://pypi.org/project/flask-sqlalchemy/ `pip install -U Flask-SQLAlchemy` – Andrew Ryan Dec 11 '22 at 03:46
  • what does the -U do? @AndrewRyan I am very new to this and just want to understand what I did wrong or why this needs to be done. Thanks! – Val Kuikman Dec 11 '22 at 03:54
  • 1
    if you haven't activate the .venv (virtual environment), then this may help https://stackoverflow.com/questions/14604699/how-to-activate-virtualenv-in-linux – MZM Dec 11 '22 at 03:56
  • all those requirements were already satisfied. So it's not going to solve my issue. – Val Kuikman Dec 11 '22 at 03:57
  • I am using VS Code and my virtual environment is activated and being used. – Val Kuikman Dec 11 '22 at 03:59
  • 1
    Seems like you're starting your app inside of a Docker container aren't you? Cuz I see /app/... if so, then you probably need to run pip install -r requirements.txt inside of your container before starting the app. – Toan Quoc Ho Dec 11 '22 at 04:16
  • @ToanQuocHo I have docker and flask connected in VS Code. I have added my docker file into my original post. – Val Kuikman Dec 11 '22 at 04:27

0 Answers0