我正在尝试使用以下指南在 Mac 上安装 gcloud:macOS 快速入门 执行 install.sh 脚本时出现以下错误
Pratyushs-MacBook-Pro-2:~ pratyush$ ./google-cloud-sdk\ 2/install.sh
Welcome to the Google Cloud SDK!
Traceback (most recent call last):
File "/Users/pratyush/./google-cloud-sdk 2/bin/bootstrapping/install.py", line 12, in <module>
import bootstrapping
File "/Users/pratyush/google-cloud-sdk 2/bin/bootstrapping/bootstrapping.py", line 44, in <module>
from googlecloudsdk.core.credentials import store as c_store
File "/Users/pratyush/google-cloud-sdk 2/lib/googlecloudsdk/core/credentials/store.py", line 36, in <module>
from googlecloudsdk.core.credentials import creds
File "/Users/pratyush/google-cloud-sdk 2/lib/googlecloudsdk/core/credentials/creds.py", line 37, in <module>
import sqlite3
File "/usr/local/Cellar/python@2/2.7.15_1/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/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/dbapi2.py", line 28, in <module>
from _sqlite3 import *
ImportError: dlopen(/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_sqlite3.so, 2): Symbol not found: _sqlite3_enable_load_extension
Referenced from: /usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_sqlite3.so
Expected in: /usr/lib/libsqlite3.dylib
in /usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_sqlite3.so
Pratyushs-MacBook-Pro-2:~ pratyush$
Python 版本:2.7.15 Mac:High Sierra v10.13.4
有人能帮我解决这个错误吗?
谢谢。
答案1
安装脚本失败,因为它运行的是系统 Python 2 解释器(at /usr/bin/python
)。正如您所发现的,macOS 附带的默认 Python 解释器是很多麻烦的根源。它永远不应该被使用。Apple 是从未来的 macOS 版本中删除它。
1.安装合适版本的Python
要安装gcloud
,首先需要安装最新的 Python 3 解释器brew
。
$ brew install python
2. 验证是否正在使用Good Python tm
新的解释器将安装在/usr/local/bin/python3
。使用 验证它是否优先于系统 Python which -a
。
$ which -a python3
/usr/local/bin/python3
/usr/bin/python3
如果/usr/local/bin/python3
不是第一个结果,请编辑您的$PATH
并确保/usr/local/bin
出现在之前/usr/bin
。
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
3. 安装gcloud
$ brew install --cask google-cloud-sdk