Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'flask.scaffold' #567

Closed
tumluliu opened this issue Oct 1, 2023 · 11 comments
Closed

ModuleNotFoundError: No module named 'flask.scaffold' #567

tumluliu opened this issue Oct 1, 2023 · 11 comments
Labels
bug Something isn't working

Comments

@tumluliu
Copy link

tumluliu commented Oct 1, 2023

Code

as from the official doc

from flask import Flask
from flask_restx import Resource, Api

app = Flask(__name__)
api = Api(app)

@api.route('/hello')
class HelloWorld(Resource):
    def get(self):
        return {'hello': 'world'}

if __name__ == '__main__':
    app.run(debug=True)

Repro Steps (if applicable)

  1. init a new python project with poetry with poetry new flask-restx-test
  2. enter the dir and poetry add flask-restx
  3. copy and paste the minimal API sample code into app.py
  4. enter the venv with poetry shell
  5. launch the app.py with python app.py

Expected Behavior

the app should be up and running

Actual Behavior

error

Error Messages/Stack Trace

error with:

Traceback (most recent call last):
  File "$HOME/.cache/pypoetry/virtualenvs/flask-restx-test-gvqPH5Xl-py3.10/lib/python3.10/site-packages/flask_restx/api.py", line 18, in <module>
    from flask.helpers import _endpoint_from_view_func
ImportError: cannot import name '_endpoint_from_view_func' from 'flask.helpers' ($HOME/.cache/pypoetry/virtualenvs/flask-restx-test-gvqPH5Xl-py3.10/lib/python3.10/site-packages/flask/helpers.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "$HOME/projects/flask-restx-test/app.py", line 2, in <module>
    from flask_restx import Resource, Api
  File "$HOME/.cache/pypoetry/virtualenvs/flask-restx-test-gvqPH5Xl-py3.10/lib/python3.10/site-packages/flask_restx/__init__.py", line 2, in <module>
    from .api import Api  # noqa
  File "$HOME/.cache/pypoetry/virtualenvs/flask-restx-test-gvqPH5Xl-py3.10/lib/python3.10/site-packages/flask_restx/api.py", line 20, in <module>
    from flask.scaffold import _endpoint_from_view_func
ModuleNotFoundError: No module named 'flask.scaffold'

Environment

  • Python version: 3.10.11
  • Flask version: 3.0.0
  • Flask-RESTX version: 1.1.0
  • Other installed Flask extensions: none

Additional Context

nothing else as this is the minimal sample. Could it be caused by some incompatibility?

@tumluliu tumluliu added the bug Something isn't working label Oct 1, 2023
@arunkhattri
Copy link

same here

@vkdnjznd
Copy link

vkdnjznd commented Oct 1, 2023

from flask 3.0.0, the scaffold module was moved to sansio.scaffold
This bug can be fixed by replacing flask.scaffold with flask.sansio.scaffold on the line between 17 and 20 in the flask_restx/api.py

try:
    from flask.helpers import _endpoint_from_view_func
except ImportError:
    from flask.sansio.scaffold import _endpoint_from_view_func

@binary1Ne
Copy link

binary1Ne commented Oct 1, 2023

Hi @tumluliu ,
in Scripts\Lib\site-packages\flask_restx\api.py
In line number 20 , I made following changes,
from flask.sansio.scaffold import _endpoint_from_view_func

@tumluliu
Copy link
Author

tumluliu commented Oct 1, 2023

from flask 3.0.0, the scaffold module was moved to sansio.scaffold This bug can be fixed by replacing flask.scaffold with flask.sansio.scaffold on the line between 17 and 20 in the flask_restx/api.py

try:
    from flask.helpers import _endpoint_from_view_func
except ImportError:
    from flask.sansio.scaffold import _endpoint_from_view_func

Thanks @vkdnjznd ! Worked like a charm. So I assume this would be included in 1.1.1 as a bugfix?

@peter-doggart
Copy link
Contributor

peter-doggart commented Oct 2, 2023 via email

@threeal
Copy link

threeal commented Oct 3, 2023

I just tested this project and found out that we may be blocked by pytest-dev/pytest-flask#167 before we could support Flask 3.0.0 in this project.

@Ryu-CZ
Copy link
Contributor

Ryu-CZ commented Oct 3, 2023

Confirmed. I am working on patch for missing import.

Ryu-CZ pushed a commit to Ryu-CZ/flask-restx that referenced this issue Oct 3, 2023
Ryu-CZ pushed a commit to Ryu-CZ/flask-restx that referenced this issue Oct 3, 2023
Ryu-CZ pushed a commit to Ryu-CZ/flask-restx that referenced this issue Oct 3, 2023
@Yoshi325 Yoshi325 mentioned this issue Oct 3, 2023
@dbybanez
Copy link

dbybanez commented Oct 5, 2023

also getting this error

Python version: 3.9
Flask version: 1.1.2
Flask-RESTX version: 1.1.0

b3n4kh added a commit to ait-cs-IaaS/Taranis-NG that referenced this issue Oct 6, 2023
With worker beeing incompatible with python 3.12:
pytorch/pytorch#110436

With core having an incompatible dependency with flask 3

python-restx/flask-restx#567
@Ryu-CZ
Copy link
Contributor

Ryu-CZ commented Oct 6, 2023

Note: If you really need hot-fix consider temporal use of restx-monkey. I put stuff there same as suggesting pull requests here in flask-restx. Hot patcher restx-monkey is in standard pipy repo.

@devopsnetworks
Copy link

Pyhton = 3.10.12
flask == 3.0.0
flask_restx == 0.5

Facing the similar issue.
File "/home/USERNAME/devnet/.venv/lib/python3.10/site-packages/flask_restx/api.py", line 23, in
from flask.scaffold import _endpoint_from_view_func
ModuleNotFoundError: No module named 'flask.scaffold'

@devopsnetworks
Copy link

devopsnetworks commented Oct 16, 2023

It's working after modifying the line No 23 on file:
/home/USER/venv/lib/python3.10/site-packages/flask_restx/api.py

Before
from flask.scaffold import _endpoint_from_view_func

Now
from flask.sansio.scaffold import _endpoint_from_view_func

b3n4kh added a commit to taranis-ai/taranis-ai that referenced this issue Oct 17, 2023
With worker beeing incompatible with python 3.12:
pytorch/pytorch#110436

With core having an incompatible dependency with flask 3

python-restx/flask-restx#567
Ryu-CZ pushed a commit to Ryu-CZ/flask-restx that referenced this issue Oct 25, 2023
qsantos added a commit to qsantos/mybelts that referenced this issue Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants