Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot import name '_endpoint_from_view_func' from 'flask.helpers' in python

Tags:

python

flask

I ran the same code on Ubuntu with no problem, but ran it on Windows10 with problems. I also installed Flask. My windows environment is configured as follows:

$ pip --version
pip 21.1.1 from c:\users\min\appdata\local\programs\python\python37\lib\site-packages\pip (python 3.7)

$ pip show flask
Name: Flask
Version: 2.0.0
Summary: A simple framework for building complex web applications.
Home-page: https://palletsprojects.com/p/flask
Author: Armin Ronacher
Author-email: [email protected]
License: BSD-3-Clause
Location: c:\users\min\appdata\local\programs\python\python37\lib\site-packages
Requires: Werkzeug, itsdangerous, Jinja2, click
Required-by: Flask-RESTful, Flask-API

$ pip show flask-restful
Name: Flask-RESTful
Version: 0.3.8
Summary: Simple framework for creating REST APIs
Home-page: https://www.github.com/flask-restful/flask-restful/
Author: Twilio API Team
Author-email: [email protected]
License: BSD
Location: c:\users\min\appdata\local\programs\python\python37\lib\site-packages
Requires: Flask, aniso8601, six, pytz
Required-by:

When I run the code, there is wrong in

from flask_restful import reqparse, Api, Resource

and error is

Exception has occurred: ImportError
cannot import name '_endpoint_from_view_func' from 'flask.helpers' (C:\Users\Min\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\helpers.py)
  File "E:\yulin\python_project\image_text_project_-api\chuanxian_api_module_time_native2.py", line 24, in <module>
    from flask_restful import reqparse, Api, Resource

I don't know why, please help me, thank you very much.

like image 929
Min Guo Avatar asked May 12 '21 03:05

Min Guo


2 Answers

That's a known issue that awaits to be solved here.

In the meantime, I suggest a monkey patching:

import flask.scaffold
flask.helpers._endpoint_from_view_func = flask.scaffold._endpoint_from_view_func
import flask_restful
...

For reference, the current version of my Flask-RESTful package is 0.3.8.


Edit:

Since the issue has then been fixed in release 0.3.9, just upgrade the package version:

Flask-RESTful>0.3.8
like image 82
renatodamas Avatar answered Nov 10 '22 10:11

renatodamas


Like Renato mentioned, this is a known issue. The team has fixed it. Using a recent version of Flask-RESTful fixed the issue for me. For example:

Flask-RESTful==0.3.9
like image 11
Iching Chang Avatar answered Nov 10 '22 11:11

Iching Chang