简体   繁体   English

如何解决 Flask 中的版本冲突错误(PyJWT 和 Flask-JWT-Extended)

[英]How to resolve versionConflict error in Flask (PyJWT and Flask-JWT-Extended)

I want to run a very simple application using Flask framework.我想使用Flask框架运行一个非常简单的应用程序。 I have also run and developed flask app before.我之前也运行和开发过 flask 应用程序。 After a while I need to develop a new simple app using it.一段时间后,我需要使用它开发一个新的简单应用程序。

So I have created a virtual environment and activated it:所以我创建了一个虚拟环境并激活它:

virtualenv venv
source venv/bin/activate
python --version # prints 3.8.6
pip --version # prints pip 20.3.1

Then installed Flask :然后安装Flask

(venv) pip install -U Flask

Here is my hello world code:这是我的hello world代码:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello, World!"

Whenever I run flask run command I face to the following error:每当我运行flask run命令时,我都会遇到以下错误:

raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (PyJWT 2.0.0 (/home/user/.local/lib/python3.8/site-packages), Requirement.parse('PyJWT<2.0,>=1.6.4'), {'Flask-JWT-Extended'})

I have also seen the similar links which I refer them below but I didn't get any clue about how resolving it.我也看到了类似的链接,我在下面引用它们,但我没有得到任何关于如何解决它的线索。

link1 |链接1 | link2 |链接2 | link3 链接3

PS It is notable that I have tried installing different version of PyJWT like 1.7.1 , 2.0.0 , etc. but none of them worked properly. PS值得注意的是,我尝试安装不同版本的 PyJWT,如1.7.12.0.0等,但它们都不能正常工作。

Make sure to pip install --upgrade flask-jwt-extended as well.确保pip install --upgrade flask-jwt-extended也是如此。 The newest version of that should work fine with flask 2.xx and PyJWT 2.xx .最新版本的flask 2.xxPyJWT 2.xx应该可以正常工作。

Versions:版本:

Flask==2.0.1
PyJWT==2.1.0
Flask_JWT_Extended==4.2.1

For more details you can checkout the following links: link1 |有关更多详细信息,您可以查看以下链接: link1 | link2 链接2

It seems that the newest version of Flask (currently 2.0.1) has problem with dependencies. Flask (当前为 2.0.1)的最新版本似乎存在依赖问题。

The problem was resolved after downgrading it to 1.1.2 via the following command:通过以下命令将其降级到1.1.2后问题得到解决:

pip install Flask==1.1.2

Hope it will be fixed in near future!希望它会在不久的将来得到修复!

This solved my issue without having to make a new Venv/Environment from scratch:这解决了我的问题,而无需从头开始制作新的 Venv/Environment:
try uninstalling Flask and all Flask Related modules and then just run pip install flask-jwt-extended which will install flask properly again. try uninstalling Flask and all Flask Related modules and then just run pip install flask-jwt-extended which will install flask properly again.

works with flask-jwt-extended==4.3.1 and will setup flask==2.0.2flask-jwt-extended==4.3.1一起使用,并将设置flask==2.0.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM