常见python中各种安装包报错修复

一、

ModuleNotFoundError: No module named ‘flask._compat’

是因为flask版本过高了
降低版本

pip install flask_script==2.0.6

二、

ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. flask-sqlalchemy 3.0.5 requires flask>=2.2.5, but you have flask 1.1.2 which is incompatible.

由于flask-sqlalchemy版本过高了

pip3 install flask-script==2.0.6

三、

ImportError: cannot import name ‘json’ from ‘itsdangerous’

ImportError: cannot import name ‘app_ctx’ from ‘flask.globals’

一般是flask版本过低导致:

pip install flask==2.0.2

四、

ModuleNotFoundError: No module named ‘flask._compat’

解决方法1:降低flask版本,1.1.2即可

pip3 install flask==1.1.2

解决方法2:

使用高版本的flask,在flask_script/init.py 里面的

from ._compat import text_type
改成
from flask_script._compat import text_type

五、

AttributeError: module ‘sqlalchemy.orm’ has no attribute ‘DeclarativeBase’

降级了 sqlalchemy

pip install Flask-SQLAlchemy==2.5.0

六、

ImportError: cannot import name ‘_endpoint_from_view_func’ from ‘flask.helpers’

第一种

pip install Flask-RESTful==0.3.9

第二种

您可以定义自己的_endpoint_from_view_func或使用flask.scaffold._endpoint_from_view_func

monkey.py

def _endpoint_from_view_func(view_func):
    """Internal helper that returns the default endpoint for a given
    function.  This always is the function name.
    """
    assert view_func is not None, "expected view func if endpoint is not provided."
    return view_func.__name__


# noinspection SpellCheckingInspection


def patch_restx(endpoint_from_view_func: bool = True) -> None:
    """
    Nasty hacks are here

    :param endpoint_from_view_func: Add missing function into flask for backward compatibility with `flask-restx`
    """
    if endpoint_from_view_func:
        func_name = "_endpoint_from_view_func"
        try:
            import pkg_resources
            packages = pkg_resources.working_set.by_key
            if "flask" in packages and "flask-restx" in packages:
                flask_version = tuple(map(int, packages["flask"].version.split(".")))
                flask_restx_version = tuple(map(int, packages["flask-restx"].version.split(".")))
                if (2, 0, 0) <= flask_version and (1, 0, 0) > flask_restx_version:
                    import flask
                    if not hasattr(flask.helpers, func_name):
                        setattr(flask.helpers, func_name, _endpoint_from_view_func)
        except ImportError:
            print(f"skipping monkey patch of {func_name}")
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值