3
2

More than 3 years have passed since last update.

Python 3(pyenv) と Google Cloud SDK を共存する

Posted at

GCP を使う上である種必須とも言える Google Cloud SDK は、Python 3がデフォルトの環境だと動かない問題がある。
Python 2の死までもう4ヶ月を切っているけどリプレースする気はあるのだろうか:thinking:

(pyenvの導入方法などは割愛)

pyenvを使っている環境で pyenv global 3.x.x とした際には $CLOUD_SDK_PYTHON という環境変数に Python 2 へのパスをセットするのが一般的なのだと思っていた。

しかし、 pyenv global 3.x.x 2.x.x とバージョンを2つ記載するとPython 2/3の環境を共存させることができる。

この場合の各バージョンは以下のようになる。

$ python --version
Python 3.x.x

$ python2 --version
Python 2.x.x

$ python3 --version
Python 3.x.x

pyenv help global を実行してもバージョンを複数指定できることは書いていない1

$ pyenv help global                                                                                  (git)-[fix/webdav-put]
Usage: pyenv global <version>

Sets the global Python version. You can override the global version at
any time by setting a directory-specific version with `pyenv local'
or by setting the `PYENV_VERSION' environment variable.

<version> should be a string matching a Python version known to pyenv.
The special version string `system' will use your default system Python.
Run `pyenv versions' for a list of available Python versions.

これにより上述の $CLOUD_SDK_PYTHON をセットしなくとも Google Cloud SDK が使えるようになる。


  1. GitHubのREADME には書いていた 

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2