kubectl pyenv python版本冲突

2024-10-03 23:28:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在我的mac上运行一些kubectl命令,在那里我使用pyenv来管理python版本。当python命令在某些情况下无法运行时,python命令无法找到。在

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

我尝试过将.python-version更改为2.7.4系统和其他几个版本,但似乎无法使其正常工作。我渴望一条线索,谁能给我指点方向吗?在


Tags: toio命令版本configpyenvwhichusers
1条回答
网友
1楼 · 发布于 2024-10-03 23:28:56

kubectl不需要Python,但是gcloud需要。在

以下是gcloud源代码的一部分(实际上是用bash编写的):

#  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

所以,检查您的环境变量,以了解当您启动gcloud时发生了什么。在

作为一个简单的解决方法,您可以使用自制软件安装python2,或者只制作一个symlink python2->;python2:

^{pr2}$

另一种方法是配置pyenv设置,如pyenv documentation中所述,以获得必要的python版本。在

相关问题 更多 >