Qiulang
Qiulang

Reputation: 12395

Is there a way to specify minimum python version requirement for my script since pipfile does not support this?

Is there a way to specify minimum python version requirement for my script ? For example my script requires python 3.6+ because it uses f-string. I have test my script under 3.7, 3.8, 3.9, they all work.

But since pipfile doesn't support minimum version, refer to pipenv specify minimum version of python in pipfile? and this open issue https://github.com/pypa/pipfile/issues/87

So is there a way to do that ? Now I just write it in readme.

--- update ---

https://github.com/pypa/pipenv/issues/2683 indeed said

Note that the python_version key is optional. You can always remove it if it causes problems, and document the version requirements otherwise (i.e. in the README).

Upvotes: 2

Views: 686

Answers (1)

Albin
Albin

Reputation: 902

Check this post. This may do what you require:

#!/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

Upvotes: 1

Related Questions