python - kubectl pyenv python 版本冲突
问题描述
我正在尝试在我的 mac 上运行一些 kubectl 命令,我使用 pyenv 来管理 python 版本。每当我运行某些 kubectl 命令时,都会导致 kubectl 指出它找不到 python2 命令的错误。
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、system 和其他几个版本,但我似乎无法让它工作。我很想拉线,有人可以提供一些方向吗?
解决方案
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,或者只创建一个符号链接 python2 -> python:
sudo ln -s `which python` $(dirname `which python`)/python2
另一种方法是按照pyenv 文档中的描述配置 pyenv 设置,以获取必要的 python 版本。
推荐阅读
- javascript - 同一个JS文件的多个副本加载时间
- javascript - 发布 Json 字符串获取 NULL
- ruby-on-rails - 无法推送到 Heroku (Ruby 2.3.4)
- c# - 如何检查 URL 是否存在 XSS 风险并对其进行清理以使其不是
- laravel - React 应用程序中没有“Access-Control-Allow-Origin”。但是刷新后消失
- sql-server - SqlBulkCopy 无效的列长度...但它不是
- java - 迭代从 JSP 上的 servlet 发送的 ArrayList?
- azure - 使用 Azure 应用服务 - Azure AD B2 - MobileServiceClient - 身份验证失败
- grails - 在 Intellij 2018.1.4 中为 gsp 添加代码样式
- groovy - Groovy 执行复杂的 shell 命令