Pip 包依赖项覆盖 requests.txt 中指定的版本
我得到了一个 Flask 应用程序并安装了requirements.txt 中的依赖项。 运行我的应用程序时出现以下错误:
ImportError: cannot import name 'soft_unicode' from 'markupsafe'
MarkupSafe 是 Jinja2 所需的包,而 Flask 又需要该包。
我很快发现将 MarkupSafe 从版本 2.1.1 降级到 2.0.1 可以解决该问题,并且我调整了我的requirements.txt:
MarkupSafe==2.0.1 # Newer version causes errors
rpi-ws281x==4.3.3
Flask==2.0.3
Flask-SocketIO==5.1.1
但是安装后,我发现 Jinja2 安装过程覆盖了我指定的 MarkupSafe 版本,我再次结束更新至2.1.1版本。我知道 pip 的 force reinstall
选项,但想知道是否有更好的方法。
提前致谢!
I got a Flask App and installed the dependencies out of the requirements.txt.
I got the following error when running my App:
ImportError: cannot import name 'soft_unicode' from 'markupsafe'
MarkupSafe is a package required by Jinja2 which in turn is required by Flask.
I soon found out that downgrading MarkupSafe from version 2.1.1 to 2.0.1 fixes the issue, and I adapted my requirements.txt:
MarkupSafe==2.0.1 # Newer version causes errors
rpi-ws281x==4.3.3
Flask==2.0.3
Flask-SocketIO==5.1.1
But after installing, I find out that the Jinja2 installing process overrides my specified version of MarkupSafe and I again end up with version 2.1.1. I know about the force reinstall
option of pip but wondered if there is a better approach.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Pipenv:https://pipenv.pypa.io/。
至少在前一段时间,Pip 在解决多个包依赖方面曾经存在一些缺陷。我现在看到他们文档上的更新说明似乎解决了这个问题;还没有测试过。 Pipenv 可以很好地解决依赖关系图。这是我开始使用 Pipenv 的原因之一。
请查看以下页面:
Use pipenv: https://pipenv.pypa.io/.
At least some time ago, Pip used to have some flaws in solving multiple packages dependencies. I now saw an update note on their documentation that seems to tackle the problem; haven't tested yet. Pipenv would solve the dependencies graph just fine. That was one of the reason I started using Pipenv.
Please, have a look at the following pages: