使用多个版本的 py2.7 安装 Google Cloud SDK 时出现 sqlite3 错误

env*_*nce 4 sqlite python-2.7 google-cloud-platform gcloud google-cloud-sdk

第一次从 AWS 设置迁移到 GCE,所以请耐心回答我幼稚的问题。

在步骤中./google-cloud-sdk/install.sh,我遇到了以下错误:

  Welcome to the Google Cloud SDK!
  Traceback (most recent call last):
    File "/Users/t/Desktop/./google-cloud-sdk/bin/bootstrapping/install.py", line 8, in <module>
      import bootstrapping
    File "/Users/t/Desktop/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 19, in <module>
      from googlecloudsdk.core.credentials import store as c_store
    File "/Users/t/Desktop/google-cloud-sdk/lib/googlecloudsdk/core/credentials/store.py", line 34, in <module>
      from googlecloudsdk.core.credentials import creds
    File "/Users/t/Desktop/google-cloud-sdk/lib/googlecloudsdk/core/credentials/creds.py", line 40, in <module>
      import sqlite3
    File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
      from dbapi2 import *
    File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/dbapi2.py", line 28, in <module>
      from _sqlite3 import *
  ImportError: No module named _sqlite3
Run Code Online (Sandbox Code Playgroud)

仔细检查后,我注意到我的可视化中有两个 python2.7 版本/usr/local/Cellar/python2.7.10_22.7.11

奇怪的是,当我去 python 命令行时,这个问题:

  Python 2.7.10 (default, Oct  6 2017, 22:29:07)
  [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.

  >>> import sqlite3
  >>> from _sqlite3 import *
  >>> print('hello, this seems to work')
      hello, this seems to work
Run Code Online (Sandbox Code Playgroud)

虽然不幸的install.sh是正在py2.7.11从系统中选择版本而不是 python 版本,但我不确定我们是否可以设置一些环境变量(例如,$CLOUDSDK_PYTHON在我们开始安装之前)。

小智 5

是的,您应该将 $CLOUDSDK_PYTHON 环境变量设置为指向正确的 Python 安装。看到一个类似的问题:google-cloud-sdk installation not find right Python 2.7 version in CentOS /usr/local/bin

  • 如果有人在使用 asdf 版本管理器时遇到此问题,我可以通过将 $CLOUDSDK_PYTHON 设置为我的系统 python(位于 /usr/bin/python3.8)来解决此问题 (2认同)