python - 有没有办法为我的脚本指定最低 python 版本要求,因为 pipfile 不支持这个?
问题描述
有没有办法为我的脚本指定最低 python 版本要求?例如,我的脚本需要 python 3.6+,因为它使用 f-string。我已经在 3.7、3.8、3.9 下测试了我的脚本,它们都可以工作。
但是由于 pipfile 不支持最低版本,请参考pipenv 在 pipfile 中指定 python 的最低版本?和这个未解决的问题https://github.com/pypa/pipfile/issues/87
那么有没有办法做到这一点?现在我只是把它写在自述文件中。
- - 更新 - -
https://github.com/pypa/pipenv/issues/2683确实说过
请注意,python_version 键是可选的。如果它引起问题,您总是可以删除它,否则记录版本要求(即在自述文件中)。
解决方案
检查这篇文章。这可能会满足您的要求:
#!/usr/bin/env python
import sys
if sys.version_info[0] != 3 or sys.version_info[1] < 6:
print("This script requires Python version 3.6")
sys.exit(1)
# rest of script, including real initial imports, here
推荐阅读
- c - 为什么它返回-8而不是-4 ..?
- python - Sphinx 不从父类继承文档字符串
- maven - 仅为特定阶段设置属性
- reactjs - Gatsby Module Federation CORS 错误和急切消费问题
- android - 为什么使用 GlobalScope 需要 @DelicateCoroutinesApi
- matlab - 为什么 MATLAB R2021a 中的散点图颜色不同?
- python - Python 中是否有 `(void)foo` 的等价物?
- angular - 重置行数据后,ag网格行数据正在更新
- android - 为什么我无法在 Xubuntu 上打开我的 Android Studio 项目?
- java - 如何导入我用java编写的类