Skip to content

Instantly share code, notes, and snippets.

@tats-u
Last active July 22, 2019 02:35
Show Gist options
  • Save tats-u/54f31fec905c70837ca671d78a4f2e83 to your computer and use it in GitHub Desktop.
Save tats-u/54f31fec905c70837ca671d78a4f2e83 to your computer and use it in GitHub Desktop.
Get Python version with GNU Make
# Replace '.' with '' to get $PYTHON_VERSION_INT directly
# e.g. 3.7
PYTHON_VERSION = $(shell python -c "import sys;print('.'.join(map(str,sys.version_info[:2])))")
# e.g. 37
PYTHON_VERSION_INT = $(subst .,,$(PYTHON_VERSION))
# e.g. 3
PYTHON_MAJOR_VERSION = $(basename $(PYTHON_VERSION))
# e.g. 7
PYTHON_MINOR_VERSION = $(subst .,,$(suffix $(PYTHON_VERSION)))
all:
@echo Python version: $(PYTHON_VERSION)
@echo Python major version: $(PYTHON_MAJOR_VERSION)
@echo Python minor version: $(PYTHON_MINOR_VERSION)
@echo Python version integer: $(PYTHON_VERSION_INT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment