gcloud版本306.0.0导致“没有名为'urllib2'的模块”错误

问题描述

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,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

但是我想知道如何使它与最新版本一起使用。

解决方法

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

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

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

如果无法解决此问题,最好进行here内的错误检查,以供进一步调查。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...