【问题标题】:gcloud version 306.0.0 causing "No module named 'urllib2'" errorsgcloud 版本 306.0.0 导致“没有名为 'urllib2' 的模块”错误
【发布时间】:2020-12-13 16:04:38
【问题描述】:

在将gcloud 从版本 290.0.1 更新到版本 306.0.0 后,运行gsutil cp 命令时出现错误:

Traceback (most recent call last):
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gsutil", line 21, in <module>
    gsutil.RunMain()
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gsutil.py", line 122, in RunMain
    import gslib.__main__
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/__main__.py", line 53, in <module>
    import boto
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/vendored/boto/boto/__init__.py", line 1216, in <module>
    boto.plugin.load_plugins(config)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/vendored/boto/boto/plugin.py", line 93, in load_plugins
    _import_module(file)
  File "/usr/lib/google-cloud-sdk/platform/gsutil/gslib/vendored/boto/boto/plugin.py", line 75, in _import_module
    return imp.load_module(name, file, filename, data)
  File "/usr/lib/python3.6/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/usr/lib/python3.6/imp.py", line 172, in load_source
    module = _load(spec)
  File "/usr/share/google/boto/boto_plugins/compute_auth.py", line 18, in <module>
    import urllib2
ModuleNotFoundError: No module named 'urllib2'

按照https://cloud.google.com/sdk/docs/downloads-apt-get#downgrading_cloud_sdk_versions 的降级说明暂时解决了这个问题:

sudo apt-get update && sudo apt-get install google-cloud-sdk=290.0.1-0

但我想知道如何使用最新版本。

【问题讨论】:

    标签: google-cloud-platform gcloud google-cloud-sdk


    【解决方案1】:

    我已经安装了306.0.0 版本并运行了gcloud cp 命令,但我没有遇到这个问题。出于这个原因,检查错误ModuleNotFoundError: No module named 'urllib2' 的原因,似乎它们总是与无法正常工作的Python 库有关——您可以查看herehere 这两个示例。

    但是,在进一步的搜索中,此插件通常用于 Compute Engine 和使用 Python 启动 VM 的脚本,更具体地与文件 compute_auth.py 相关 - 在消息中似乎与错误有关 - 并且当您可以查看here关于此文件的更多信息。

    考虑到这一点,新版本的 Cloud SDK 为 Compute Engine 带来了一些 updates,这可能会导致错误。如果您确实在您的应用程序中使用 Python,我会尝试这种情况下的解决方案here,即更新文件compute_auth.py,将行import urllib2 更改为import urllib.request as urllib2

    如果这不能解决,在Google's Issue Tracker 中提出错误将是最好的选择,以便进一步调查。

    【讨论】:

      猜你喜欢
      • 2011-02-17
      • 2018-05-22
      • 2017-05-31
      • 1970-01-01
      • 2011-09-29
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多