My code requires Python version of 3.6 or higher. To ensure this, I use the following:
import sys
version = sys.version_info
assert version.major > 3 or (version.major == 3 and version.minor >= 6)
But this doesn't seem like the best way to do this (from a good coding practices viewpoint). Is there a better way?
What is the appropriate way to make sure your script is being run on an appropriate version of Python?
This information should be specified in your packaging information, so users are informed of the python version requirement before they ever install your python package.
Your project should have a setup.py
script that is used to install your package. You can specify the python dependency in that setup script
setup(
name='my_package',
version='1.0.0',
python_requires='>=3.6.0'
...
)
This way, it won't allow anyone to build, download, or install your package to an incompatible python version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With