“gcloud storage cp t.txt gs://my.bucket.name/”给出错误:ModuleNotFoundError:没有名为“google.auth”的模块

问题描述 投票:0回答:1

我正在尝试使用以下方式将文件上传到存储桶:

gcloud storage cp t.txt gs://my.bucket.name/

但是有一个错误:

Copying file://t.txt to gs://adhoc.textra.me/t.txt
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/spawn.py", line 122, in spawn_main
    exitcode = _main(fd, parent_sentinel)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/spawn.py", line 132, in _main
    self = reduction.pickle.load(from_parent)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/share/google-cloud-sdk/lib/googlecloudsdk/command_lib/storage/tasks/task_graph_executor.py", line 37, in <module>
    from googlecloudsdk.command_lib.storage import encryption_util
  File "/opt/homebrew/share/google-cloud-sdk/lib/googlecloudsdk/command_lib/storage/encryption_util.py", line 28, in <module>
    from googlecloudsdk.command_lib.storage import hash_util
  File "/opt/homebrew/share/google-cloud-sdk/lib/googlecloudsdk/command_lib/storage/hash_util.py", line 25, in <module>
    from googlecloudsdk.command_lib.storage import fast_crc32c_util
  File "/opt/homebrew/share/google-cloud-sdk/lib/googlecloudsdk/command_lib/storage/fast_crc32c_util.py", line 32, in <module>
    from googlecloudsdk.command_lib import info_holder
  File "/opt/homebrew/share/google-cloud-sdk/lib/googlecloudsdk/command_lib/info_holder.py", line 45, in <module>
    from googlecloudsdk.core.credentials import store as c_store
  File "/opt/homebrew/share/google-cloud-sdk/lib/googlecloudsdk/core/credentials/store.py", line 34, in <module>
    from googlecloudsdk.api_lib.auth import external_account as auth_external_account
  File "/opt/homebrew/share/google-cloud-sdk/lib/googlecloudsdk/api_lib/auth/external_account.py", line 24, in <module>
    from googlecloudsdk.core.credentials import creds as c_creds
  File "/opt/homebrew/share/google-cloud-sdk/lib/googlecloudsdk/core/credentials/creds.py", line 33, in <module>
    from google.auth import compute_engine as google_auth_compute_engine
ModuleNotFoundError: No module named 'google.auth'
  Completed files 0/1 | 0B/16.5kiB

此时它挂起并且无法上传。

这是在 Macos 上通过 Brew 安装了

google-cloud-sdk

$ brew info google-cloud-sdk
==> google-cloud-sdk: 479.0.0 (auto_updates)
https://cloud.google.com/sdk/
Installed
/opt/homebrew/Caskroom/google-cloud-sdk/479.0.0 (132B)
From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/g/google-cloud-sdk.rb
==> Name
Google Cloud SDK
==> Description
Set of tools to manage resources and applications hosted on Google Cloud
==> Artifacts
google-cloud-sdk/install.sh (Installer)
google-cloud-sdk/bin/gsutil (Binary)
google-cloud-sdk/completion.bash.inc -> /opt/homebrew/etc/bash_completion.d/google-cloud-sdk (Binary)
google-cloud-sdk/bin/bq (Binary)
google-cloud-sdk/bin/docker-credential-gcloud (Binary)
google-cloud-sdk/completion.zsh.inc -> /opt/homebrew/share/zsh/site-functions/_google_cloud_sdk (Binary)
google-cloud-sdk/bin/gcloud (Binary)
google-cloud-sdk/bin/git-credential-gcloud.sh -> git-credential-gcloud (Binary)
==> Caveats
To add gcloud components to your PATH, add this to your profile:

  for bash users
    source "$(brew --prefix)/share/google-cloud-sdk/path.bash.inc"

  for zsh users
    source "$(brew --prefix)/share/google-cloud-sdk/path.zsh.inc"
    source "$(brew --prefix)/share/google-cloud-sdk/completion.zsh.inc"

  for fish users
    source "$(brew --prefix)/share/google-cloud-sdk/path.fish.inc"

==> Analytics
install: 11,361 (30 days), 33,066 (90 days), 118,204 (365 days)

SDK已更新至最新版本:

$
~/delicious/textra (git)  $ gcloud -v
Google Cloud SDK 487.0.0
beta 2024.08.06
bq 2.1.7
core 2024.08.06
gcloud-crc32c 1.0.0
gsutil 5.30

使用

gsutil
上传效果很好,但我想使用
gcloud compute cp ...
这样我就可以指定配置,例如
gcloud --configuration=dev compute cp ...

编辑:我尝试完全卸载并删除配置文件并重新安装,结果相同。

我还能尝试什么来解决这个问题?

python google-cloud-platform gcloud
1个回答
0
投票

您的命令

brew info google-cloud-sdk
正在返回一个警告:

==> Caveats
To add gcloud components to your PATH, add this to your profile:

  for bash users
    source "$(brew --prefix)/share/google-cloud-sdk/path.bash.inc"

  for zsh users
    source "$(brew --prefix)/share/google-cloud-sdk/path.zsh.inc"
    source "$(brew --prefix)/share/google-cloud-sdk/completion.zsh.inc"

  for fish users
    source "$(brew --prefix)/share/google-cloud-sdk/path.fish.inc"

您应该运行与您的 shell 匹配的那个。

如果不起作用,请尝试:

gcloud components reinstall

如果仍然不起作用,您可以使用以下命令检查 gcloud 使用的 Python:

gcloud info --format='value(basic.python_location)'

采用返回的路径,将

python
替换为
pip
并添加
install google-auth
,然后运行命令。它将使用正确的 Python/Pip 来安装
google.auth

也就是说,由于您的酿造正在返回警告,所以我会重点关注这一点。

© www.soinside.com 2019 - 2024. All rights reserved.