Skip to content

Pyenv Usage: Makefile

Papa Bear Codes Python edited this page Jan 3, 2024 · 5 revisions

Document Release Date: 1/2/2024

Note: In the I.T. world, applications evolve rapidly. Please report any inaccuracy to papabearcodespython@gmail.com


Purpose of makefile

This code snippet can be put at the same level as a .python-version file and will then automatically with the command make install-python install python.

Pre-requisites

  • Pyenv installed
  • .python-version file in the current directory where the makefile will be.

Makefile content

Copy paste the following content in a text file called makefile.

NOTE: makefile does NOT have any extension.

# Versions
PYTHON_VERSION := $(shell cat .python-version)

# Python Installation Commands
INSTALL_PY_ENV_COMMAND := pyenv install $(PYTHON_VERSION) --skip-existing
ACTIVATE_PY_ENV_COMMAND := pyenv local

# Install pyenv
install-python: 
	@echo Install Python Version: $(PYTHON_VERSION)
	$(INSTALL_PY_ENV_COMMAND)
	@echo Activate Python Version: $(PYTHON_VERSION)
	$(ACTIVATE_PY_ENV_COMMAND)

Clone this wiki locally