使用 gsutil 工具时如何指定 Python 位置
How to specify Python location when using gsutil Tool
我在需要 Python 2.6 的 CentOS 6.5 机器上安装了 gsutil 工具。根据 CentOS 6.5 文档,我们无法将其升级到 Python 2.7,但我们可以安装和使用 Python 2.7 作为单独安装到 2.6,只要 2.6 保持为系统默认值。我已经安装了 Python 2.7 作为它自己的独立实例并且运行良好。
根据 Google,gsutils 将在 2016 年 9 月 1 日之后不再支持 Python 2.6:
Warning: You are running Python 2.6, which stopped receiving security patches as of October 2013. gsutil will stop supporting Python 2.6 on September 1, 2016. Please update your Python installation to 2.7 to ensure compatibility with future gsutil versions.
我正在寻找一种方法将 gsutils 指向安装 Python 2.7 的目录,而无需更改环境变量或任何影响默认 2.6 安装的内容。任何帮助将不胜感激。
gsutil 将使用路径上的第一个 python
可执行文件。
您可以使用的一般方法是创建一个新目录,其中 python 符号链接到您要使用的二进制文件,然后将其添加到您的路径中。
例如:
$ mkdir ~/python27-bin
$ ln -s /usr/bin/python2.7 ~/python27-bin/python
$ PATH=~/python27-bin:$PATH ./gsutil version -l | grep python
python version: 2.7.6
为了方便起见,您可以创建一个名为 gsutil-2.7
的包装脚本来为您修改路径。
根据 Daron Scarborough 的评论,我可以简单地将它添加到我的 .bashrc 中而无需做任何其他花哨的事情:
alias gsutil='CLOUDSDK_PYTHON=python2.7 gsutil'
当然,这是在我之前安装了 Python 2.7 与 Python 2.6 分开之后。
基于 Brian 的回答(我怀疑每个人都因为 2016 年 9 月 1 日的消息而点击了这个!),您也可以添加相同的内容,
export CLOUDSDK_PYTHON=python2.7
到 /etc/environment(在大多数 Linux 发行版上)让它影响所有用户。
在不改变环境的情况下,你可以在 CentOS6.5 中保留多个 python 版本 "Redhat Software Colloection"
https://access.redhat.com/solutions/1252913
在我的案例中,我使用类似
scl enable python27 'gsutil version -l'
我在需要 Python 2.6 的 CentOS 6.5 机器上安装了 gsutil 工具。根据 CentOS 6.5 文档,我们无法将其升级到 Python 2.7,但我们可以安装和使用 Python 2.7 作为单独安装到 2.6,只要 2.6 保持为系统默认值。我已经安装了 Python 2.7 作为它自己的独立实例并且运行良好。
根据 Google,gsutils 将在 2016 年 9 月 1 日之后不再支持 Python 2.6:
Warning: You are running Python 2.6, which stopped receiving security patches as of October 2013. gsutil will stop supporting Python 2.6 on September 1, 2016. Please update your Python installation to 2.7 to ensure compatibility with future gsutil versions.
我正在寻找一种方法将 gsutils 指向安装 Python 2.7 的目录,而无需更改环境变量或任何影响默认 2.6 安装的内容。任何帮助将不胜感激。
gsutil 将使用路径上的第一个 python
可执行文件。
您可以使用的一般方法是创建一个新目录,其中 python 符号链接到您要使用的二进制文件,然后将其添加到您的路径中。
例如:
$ mkdir ~/python27-bin
$ ln -s /usr/bin/python2.7 ~/python27-bin/python
$ PATH=~/python27-bin:$PATH ./gsutil version -l | grep python
python version: 2.7.6
为了方便起见,您可以创建一个名为 gsutil-2.7
的包装脚本来为您修改路径。
根据 Daron Scarborough 的评论,我可以简单地将它添加到我的 .bashrc 中而无需做任何其他花哨的事情:
alias gsutil='CLOUDSDK_PYTHON=python2.7 gsutil'
当然,这是在我之前安装了 Python 2.7 与 Python 2.6 分开之后。
基于 Brian 的回答(我怀疑每个人都因为 2016 年 9 月 1 日的消息而点击了这个!),您也可以添加相同的内容,
export CLOUDSDK_PYTHON=python2.7
到 /etc/environment(在大多数 Linux 发行版上)让它影响所有用户。
在不改变环境的情况下,你可以在 CentOS6.5 中保留多个 python 版本 "Redhat Software Colloection" https://access.redhat.com/solutions/1252913
在我的案例中,我使用类似
scl enable python27 'gsutil version -l'