我已经使用 pip install pyjwt[crypto]
安装了 Python 包,并且 pip freeze
显示了该操作安装的不同包。
我需要在 requirements.txt
中放入什么内容才能正确卡住我正在开发的版本?我不想在 requirements.txt
中添加太多内容,只想添加稍后重建环境所需的内容。
输出 pip :
...
pyjwt[crypto] in ..\site-packages (2.8.0)
cryptography>=3.4.0 in ..\site-packages (from pyjwt[crypto]) (41.0.4)
cffi>=1.12 in ..\site-packages (from cryptography>=3.4.0->pyjwt[crypto]) (1.16.0)
pycparser in ..\site-packages (from cffi>=1.12->cryptography>=3.4.0->pyjwt[crypto]) (2.21)
...
输出 pip 卡住:
...
cffi==1.16.0
cryptography==41.0.4
pycparser==2.21
PyJWT==2.8.0
...
是否可以仅将 PyJWT[crypto]==2.8.0
放入 requirements.txt
中?
当我在 requirements.txt
中投入太多内容时,我认为将来安装其他软件包会变得更加困难......我认为。
最佳答案
您可以让您的requirements.txt足够灵活,并使用约束文件。
这个约束文件基本上是 pip freeze 的输出,并固定所有版本,包括它们的依赖项。如果您需要添加依赖项或升级,只需在requirements.txt中执行此操作并重新生成约束文件。这样,就可以保证您拥有一致的部署。
技术上:
# Create the constraint file
pip freeze > constraint.txt
# use it:
pip install -c constraint.txt
官方文档:https://pip.pypa.io/en/stable/user_guide/#constraints-files
关于python - 如何卡住需求中的包版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77221352/