我正在嘗試使用以下指南在 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 解釋器(位於/usr/bin/python
)。正如您所發現的,macOS 附帶的預設 Python 解釋器是一個令人悲痛的根源。永遠不應該使用它。蘋果是從未來的 macOS 版本中刪除它。
1.安裝合適版本的Python
要安裝gcloud
,您首先需要安裝最新的 Python 3 解釋器brew
。
$ brew install python
2.驗證是否正在使用Good Python tm
新的解釋器將安裝在/usr/local/bin/python3
。驗證它的優先權是否高於帶有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