有没有办法指定我的脚本的最低 python 版本要求?例如,我的脚本需要 python 3.6+,因为它使用 f-string。我已经在 3.7、3.8、3.9 下测试了我的脚本,它们都可以工作。
但是由于 pipfile 不支持最低版本,请参阅 pipenv 在 pipfile 中指定 python 的最低版本? 和这个开放问题 https://github.com/pypa/pipfile/issues/87
那么有没有办法做到这一点?现在我只是写在readme中。
---更新---
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