简体   繁体   中英

kubectl pyenv python version conflict

I'm trying to run some kubectl commands on my mac, where I use pyenv to manage python versions. whenever I run certain kubectl command, it results in an error where kubectl states it cannot find the python2 command.

josh@venus:~/pjx/distribut_io ❯ kubectl get pods
Unable to connect to the server: error executing access token command "/Users/josh/google-cloud-sdk/bin/gcloud config config-helper --format=json": err=exit status 127 output= stderr=pyenv: python2: command not found

The `python2' command exists in these Python versions:
  2.7.4
  fp


josh@venus:~/pjx/distribut_io ❯ which python
/Users/josh/.pyenv/shims/python
josh@venus:~/pjx/distribut_io ❯ which python2
/Users/josh/.pyenv/shims/python2

I've tried changing .python-version to 2.7.4, system, and a couple other versions, and I can't seem to get this to work. I'm dying for a thread to pull on, can anyone provide some direction?

The kubectl doesn't require Python, but gcloud does.

Here is the part of the gcloud source code (it is written in bash, actually):

#  CLOUDSDK_ROOT_DIR            (a)  installation root dir
#  CLOUDSDK_PYTHON              (u)  python interpreter path
#  CLOUDSDK_PYTHON_ARGS         (u)  python interpreter arguments
#  CLOUDSDK_PYTHON_SITEPACKAGES (u)  use python site packages

...

# Cloud SDK requires python 2.7
case $CLOUDSDK_PYTHON in
*python2*)
  ;;
*python[0-9]*)
  CLOUDSDK_PYTHON=
  ;;
esac
# if CLOUDSDK_PYTHON is empty
if [ -z "$CLOUDSDK_PYTHON" ]; then
  # if python2 exists then plain python may point to a version != 2
  if which python2 >/dev/null; then
    CLOUDSDK_PYTHON=python2
  elif which python2.7 >/dev/null; then
    # this is what some OS X versions call their built-in Python
    CLOUDSDK_PYTHON=python2.7
  else
    CLOUDSDK_PYTHON=python
  fi
fi

So, check your environment variables to understand what is happening when you start gcloud.

As a simple workaround, you can install python2 using homebrew or just make a symlink python2 -> python:

sudo ln -s `which python` $(dirname `which python`)/python2

Another way is to configure pyenv settings as described in pyenv documentation to get necessary python versions in place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM