如何修复python2.7中的“AttributeError:'module'对象没有属性'storage'”错误
Posted
技术标签:
【中文标题】如何修复python2.7中的“AttributeError:\'module\'对象没有属性\'storage\'”错误【英文标题】:How to fix "AttributeError: 'module' object has no attribute 'storage'" error in python2.7如何修复python2.7中的“AttributeError:'module'对象没有属性'storage'”错误 【发布时间】:2019-04-12 09:41:04 【问题描述】:在 apache 光束管道中,我从云存储中获取输入并尝试将其写入 biqguery 表中。但是在管道执行期间出现此错误。 "AttributeError: 'module' 对象没有属性 'storage'"
def run(argv=None):
with open('gl_ledgers.json') as json_file:
schema = json.load(json_file)
schema = json.dumps(schema)
parser = argparse.ArgumentParser()
parser.add_argument('--input',
dest='input',
default='gs://bucket_name/poc/table_name/2019-04-12/2019-04-12 13:47:03.219000_file_name.csv',
help='Input file to process.')
parser.add_argument('--output',
dest='output',
required=False,
default="path to bigquery table",
help='Output file to write results to.')
known_args, pipeline_args = parser.parse_known_args(argv)
pipeline_options = PipelineOptions(pipeline_args)
pipeline_options.view_as(SetupOptions).save_main_session = True
p = beam.Pipeline(options=pipeline_options)
(p
| 'read' >> ReadFromText(known_args.input)
# | 'Format to json' >> (beam.ParDo(self.format_output_json))
| 'Write to BigQuery' >> beam.io.WriteToBigQuery(known_args.output, schema=schema)
)
result = p.run()
result.wait_until_finish()
if __name__ == '__main__':
run()
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/dataflow_worker/batchworker.py", line 773, in run
self._load_main_session(self.local_staging_directory)
File "/usr/local/lib/python2.7/dist-packages/dataflow_worker/batchworker.py", line 489, in _load_main_session
pickler.load_session(session_file)
File "/usr/local/lib/python2.7/dist-packages/apache_beam/internal/pickler.py", line 269, in load_session
return dill.load_session(file_path)
File "/usr/local/lib/python2.7/dist-packages/dill/_dill.py", line 410, in load_session
module = unpickler.load()
File "/usr/lib/python2.7/pickle.py", line 864, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 1139, in load_reduce
value = func(*args)
File "/usr/local/lib/python2.7/dist-packages/dill/_dill.py", line 828, in _import_module
return getattr(__import__(module, None, None, [obj]), obj)
AttributeError: 'module' object has no attribute 'storage'```
【问题讨论】:
您能否展示您的导入以及您安装了哪些库? 【参考方案1】:这可能与pipeline_options.view_as(SetupOptions).save_main_session = True
有关。你需要那条线吗?
尝试删除它,看看它是否能解决问题。很可能您的进口产品之一不能腌制。如果没有导入,我无法帮助您进一步调试。您也可以尝试将导入移动到运行函数中。
【讨论】:
【参考方案2】:可能是duplicate,在这种情况下,问题是需要安装google-cloud-storage
,而不是google-cloud
。
【讨论】:
以上是关于如何修复python2.7中的“AttributeError:'module'对象没有属性'storage'”错误的主要内容,如果未能解决你的问题,请参考以下文章
如何修复 python2.7 的 netifaces 模块安装?
在 python2.7 中运行我的代码时出现错误如何修复该错误? [复制]
AttributeError: (Class) object has no attribute '__name__' 创建 ModelForms [Django & Python2.7]