Tags: #python #script #shell #version
import sys
if not sys.version_info >= (3, 6, 0):
print("this script requires the use of Python 3.6+")
sys.exit(1)
python_version_check=$(python -c 'import sys; print(1 if sys.version_info >= (3, 7, 0) else 0)')
if [[ "$python_version_check" == "1" ]]; then
echo "🐍 you have at least the minimum version of Python required."
else
printf "\n ❗️ your python version is below the minimum required - 3.7.0\n\n"
read -p "👉 Would you like to continue anyway? (y/N) " -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
echo "❌ Stopping setup. Please install or run the appropriate version of Python, then re-run this script."
exit 1
fi
fi
#!/usr/bin/env python
import platform
import sys
print(platform.python_version())
print(sys.version)
"""
Output:
2.7.10
2.7.10 (default, Feb 22 2019, 21:55:15)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)]
"""