MAC version not working in python

Here’s a few examples of before_install for macOS dependent on PYTHON_VERSION env var being set

  env: &env_osx_base
    PYTHON_VERSION: &py36 3.6.6
  before_install: &install-from-pyenv
  - brew update
  - brew install pyenv || brew upgrade pyenv
  - &ensure_pyenv_preloaded |
    eval "$(pyenv init -)"
    eval "$(pyenv virtualenv-init -)"
  - &install_python pyenv install --skip-existing --keep --verbose "$PYTHON_VERSION"
  - &switch_python pyenv shell "$PYTHON_VERSION"
  - &python_version python --version
  before_install: &install-from-python_org
  - export PYTHON_VERSION_LONG=$(git ls-remote --tags git://github.com/python/cpython.git "${PYTHON_VERSION}*" "v${PYTHON_VERSION}*" | grep -v '\^{}$' | awk '{print$2}' | sed 's#^refs/tags/##;s#^v##' | grep -v '[abcepr]' | tail -n1)
  - export PYTHON_VERSION_SHORT=$(echo ${PYTHON_VERSION_LONG} | awk -F. '{print$1"."$2}')
  - echo "Selected version vars are:"
  - echo "PYTHON_VERSION=${PYTHON_VERSION}"
  - echo "PYTHON_VERSION_SHORT=${PYTHON_VERSION_SHORT}"
  - echo "PYTHON_VERSION_LONG=${PYTHON_VERSION_LONG}"
  - export PYTHON_INSTALL_PATH="/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION_SHORT}"
  - export PYTHON_INSTALL_EXE="${PYTHON_INSTALL_PATH}/bin/python${PYTHON_VERSION_SHORT}"
  - export PATH="${PYTHON_INSTALL_PATH}/bin:${PATH}"
  - export PYTHON_VENV_PATH="${HOME}/virtualenv/python${PYTHON_VERSION_SHORT}"
  - export PYTHON_INSTALLER_PATH="${PYTHON_INSTALLER_DIR_PATH}/python-${PYTHON_VERSION_LONG}.pkg"
  - env
  - curl -Lo "${PYTHON_INSTALLER_PATH}" -C - "https://www.python.org/ftp/python/${PYTHON_VERSION_LONG}/python-${PYTHON_VERSION_LONG}-macosx10.6.pkg" && sudo installer -pkg "${PYTHON_INSTALLER_PATH}" -target /
  - ls "${PYTHON_INSTALL_PATH}/bin"
  - export VENV_CMD=$(command -v virtualenv 2>/dev/null || command -v pyvenv 2>/dev/null || echo "${PYTHON_INSTALL_EXE} -m venv")
  - |
    if [[ "${VENV_CMD}" =~ virtualenv$ ]]
    then
        export VENV_CMD="${VENV_CMD} -p '${PYTHON_INSTALL_EXE}'"
    fi
  - echo "${VENV_CMD}"
  - ${VENV_CMD} "${PYTHON_VENV_PATH}"
  - . "${PYTHON_VENV_PATH}/bin/activate"
  - curl https://bootstrap.pypa.io/get-pip.py | python
  - *python_version
  - pip --version