Xcode 更新破坏了 gcloud 和 gsutil
Posted
技术标签:
【中文标题】Xcode 更新破坏了 gcloud 和 gsutil【英文标题】:Xcode update broke gcloud and gsutil 【发布时间】:2021-01-22 13:47:31 【问题描述】:几个小时前,我将 Xcode 更新到最新版本,这导致 gcloud
和 gsutil
命令停止工作。例如,在更新完成前一分钟,gsutil -m rsync
命令运行良好。
在写这个问题时,我注意到我不再有 git
工作。
由于我不是 Python 人,有人可以向我解释一下现在到底发生了什么吗?我希望得到一些帮助。
python -V
输出为Python 2.7.16
。
python3 -V
输出为Python 3.9.0
。
pip -V
输出为pip 20.2.3 from /Users/<MY_USER>/Library/Python/2.7/lib/python/site-packages/pip (python 2.7)
pip3 -V
输出为pip 20.2.3 from /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip (python 3.9)
这就是我得到gcloud help
:
Traceback (most recent call last):
File "/Users/<MY_USER>/gcloud/sdk/lib/gcloud.py", line 104, in <module>
main()
File "/Users/<MY_USER>/gcloud/sdk/lib/gcloud.py", line 62, in main
from googlecloudsdk.core.util import encoding
File "/Users/<MY_USER>/gcloud/sdk/lib/googlecloudsdk/__init__.py", line 23, in <module>
from googlecloudsdk.core.util import importing
File "/Users/<MY_USER>/gcloud/sdk/lib/googlecloudsdk/core/util/importing.py", line 23, in <module>
import imp
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imp.py", line 23, in <module>
from importlib import util
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/util.py", line 2, in <module>
from . import abc
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/abc.py", line 17, in <module>
from typing import Protocol, runtime_checkable
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 26, in <module>
import re as stdlib_re # Avoid confusion with the re we export.
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 124, in <module>
import enum
File "/Users/<MY_USER>/gcloud/sdk/lib/third_party/enum/__init__.py", line 26, in <module>
spec = importlib.util.find_spec('enum')
AttributeError: module 'importlib' has no attribute 'util'
这就是我得到gsutil help
:
Traceback (most recent call last):
File "/Users/<MY_USER>/gcloud/sdk/bin/bootstrapping/gsutil.py", line 13, in <module>
import bootstrapping
File "/Users/<MY_USER>/gcloud/sdk/bin/bootstrapping/bootstrapping.py", line 32, in <module>
import setup # pylint:disable=g-import-not-at-top
File "/Users/<MY_USER>/gcloud/sdk/bin/bootstrapping/setup.py", line 57, in <module>
from googlecloudsdk.core.util import platforms
File "/Users/<MY_USER>/gcloud/sdk/lib/googlecloudsdk/__init__.py", line 23, in <module>
from googlecloudsdk.core.util import importing
File "/Users/<MY_USER>/gcloud/sdk/lib/googlecloudsdk/core/util/importing.py", line 23, in <module>
import imp
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imp.py", line 23, in <module>
from importlib import util
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/util.py", line 2, in <module>
from . import abc
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/abc.py", line 17, in <module>
from typing import Protocol, runtime_checkable
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 26, in <module>
import re as stdlib_re # Avoid confusion with the re we export.
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 124, in <module>
import enum
File "/Users/<MY_USER>/gcloud/sdk/lib/third_party/enum/__init__.py", line 26, in <module>
spec = importlib.util.find_spec('enum')
AttributeError: module 'importlib' has no attribute 'util'
【问题讨论】:
【参考方案1】:所以在几乎一无所获之后,我找到了一个解决方案:我需要做的是将一个名为 CLOUDSDK_PYTHON
的环境变量设置为 /usr/bin/python
。
我编辑了我的.zprofile
并添加了:
export CLOUDSDK_PYTHON="/usr/bin/python"
我仍然不知道是什么原因造成的,所以如果有人愿意花时间,我会很高兴解释一下。
【讨论】:
gcloud 似乎还不支持 Python 3.9。请参阅此答案:***.com/a/64011263/339052“Python 3.9 正在发布候选版本中,预计 Gcloud SDK 不支持 3.9,它是为与 2.7.x 和 3.6 - 3.8 兼容而编写的”我在更新 Python 后在 Win10 上遇到了同样的问题.似乎默认情况下不使用 gcloud 包含的 Python,因为较新的 Python 首先位于 PATH 中。 2020-11-04 更新:现在支持 Python 3.9。我能够使用此解决方案解决此问题。以上是关于Xcode 更新破坏了 gcloud 和 gsutil的主要内容,如果未能解决你的问题,请参考以下文章