10 examples of 'check python version' in Python

Every line of 'check python version' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
18def check_python(version):
19 required_version = tuple(int(i) for i in version.split('.'))
20 actual_version = sys.version_info[:2]
21
22 assert actual_version >= required_version, (
23 'Must use at least Python %s but have version %d.%d' %
24 (version, actual_version[0], actual_version[1]))
282def check_python_version():
283 if sys.version_info < (3, 5):
284 stderr.write("DistAlgo requires Python version 3.5 or newer.\n")
285 return False
286 else:
287 return True
32def python_version() -> None:
33 """
34 Check that the Python version is supported
35 """
36 py_version = sys.version.split()[0]
37 if py_version < "3.5":
38 print(error_message(), "Unsupported Python version")
39 sys.exit(1)
43def check_pyinstaller_version():
44 """Using is_module_satisfies() for pyinstaller fails when
45 installed using 'pip install develop.zip' command
46 (PyInstaller Issue #2802)."""
47 # Example version string for dev version of pyinstaller:
48 # > 3.3.dev0+g5dc9557c
49 version = PyInstaller.__version__
50 match = re.search(r"^\d+\.\d+(\.\d+)?", version)
51 if not (match.group(0) >= PYINSTALLER_MIN_VERSION):
52 raise SystemExit("Error: pyinstaller %s or higher is required" % PYINSTALLER_MIN_VERSION)
16@staticmethod
17def python_is_version(version=None):
18 if re.search('^'+str(version)+'\.\d+\.\d+', str(Version.python()), re.M | re.I) is None:
19 return False
20 return True
146@staticmethod
147def python_version():
148 """
149 :return: python version object
150 """
151 import sys
152 # version.major, version.minor, version.micro
153 return sys.version_info
17def check_py():
18
19 if os_system() == "Windows":
20 try:
21 py_ver = subprocess.check_output(
22 "py -3 -V").decode('UTF-8').splitlines()[0]
23 print("Script has detected " + py_ver +
24 " version present on the machine.")
25 except:
26 print("Script could not detect Python 3 on the machine.\n"
27 "Go to https://www.python.org/downloads/ page and download latest Python 3 version.")
28 else:
29 try:
30 py_ver = subprocess.check_output(["python3", "-V"]).decode('UTF-8').splitlines()[0]
31 print("Script detected " + py_ver +
32 " version present on the machine.")
33 except:
34 print("Script could not detect Python 3 on the machine.\n"
35 "Go to https://www.python.org/downloads/ page and download latest Python 3 version.")
53def CheckVersion(given, required, name):
54 """ For a given set of versions str *required* and str *given*,
55 where version are usually separated by dots, print whether for
56 the module str *name* the required verion is met or not.
57 """
58 try:
59 req = LooseVersion(required)
60 giv = LooseVersion(given)
61 except:
62 print(" WARNING: Could not verify version of "+name+".")
63 return
64 if req > giv:
65 print(" WARNING: You are using "+name+" v. "+given+\
66 " | Required: "+name+" "+ required)
67 else:
68 print(" OK: "+name+" v. "+given+" | "+required+" required")
140def checkPythonVersion(minVersion, minHexVersion):
141 """Function to check that the Python version number is greater
142 than the minimum required.
143
144 Arguments:
145 minVersion - String representation of minimum version required
146 minHexVersion - Hexadecimal representation of minimum version required
147
148 Return value: True if Python version number is greater than minimum,
149 False otherwise"""
150
151 import sys
152
153 status = True
154
155 if sys.hexversion < minHexVersion:
156 from GangaCore.Utility.logging import getLogger
157 logger = getLogger(modulename=True)
158 logger.error("Ganga requires Python version %s or greater" %
159 str(minVersion))
160 logger.error("Currently using Python %s" % sys.version.split()[0])
161 status = False
162
163 return status
37def check_cython_version(self, version=None, minver=None, maxver=None):
38 log_s = []
39 if version:
40 log_s.append("version=%r"%version)
41 minver=version
42 maxver=version
43 else:
44 if minver:
45 log_s.append("minver=%r"%minver)
46 if maxver:
47 log_s.append("maxver=%r"%maxver)
48 if isinstance(minver, str):
49 minver = minver.split('.')
50 if isinstance(maxver, str):
51 maxver = maxver.split('.')
52 if minver:
53 minver = tuple(map(int, minver))
54 if maxver:
55 maxver = tuple(map(int, maxver))
56
57 # Trick to be compatible python 2.x and 3.x
58 try:
59 u = unicode
60 except NameError:
61 u = str
62
63 cmd = [self.env.CYTHON[0], '--version']
64 o = u(check_output(cmd, stderr=STDOUT), 'UTF-8').strip()
65 m = cython_ver_re.match(o)
66 self.start_msg('Checking for cython version')
67 if not m:
68 self.end_msg('Not found', 'YELLOW')
69 self.fatal("No version found")
70 else:
71 v = m.group(1)
72 ver = tuple(map(int, v.split('.')))
73 check = (not minver or minver <= ver) and (not maxver or maxver >= ver)
74 self.to_log(' cython %s\n -> %r\n' % (" ".join(log_s), v))
75 if check:
76 self.end_msg(v)
77 self.env.CYTHON_VERSION = ver
78 else:
79 self.end_msg('wrong version %s' % v, 'YELLOW')
80 self.fatal("Bad cython version (%s)"%v)
81 return True

Related snippets