gpt4 book ai didi

python - 在 Cloud DataFlow 上运行我的代码时出现 ImportError : No module named psycopg2. 扩展

转载 作者:行者123 更新时间:2023-11-29 13:13:04 27 4
gpt4 key购买 nike

我正在尝试从云外壳运行我的云数据流代码我正在起诉以下代码

 from __future__ import absolute_import
import argparse
import logging
import apache_beam as beam
from apache_beam.io import ReadFromText
from apache_beam.io import WriteToText
from apache_beam.options.pipeline_options import PipelineOptions
import csv
import psycopg2
from io import StringIO
import argparse
import logging
import sys
import re
import csv
conn = psycopg2.connect("dbname='db_bio' user='postgres' host='*****' port='5432' password='poui19956'")

class scrip_val(beam.DoFn):
def process(self, element):
f = StringIO(element)
print(type(f))
reader = csv.reader(f, delimiter=',')
for row in reader:
cur.execute("insert into bio values(%s,%s,%s,%s,%s)",row)
conn.commit()
return [len(element)]
def run():
parser = argparse.ArgumentParser()
parser.add_argument('--input',
dest='input',
default='gs://pydataflow',
help='Input file to process.')

known_args, pipeline_args = parser.parse_known_args()

with beam.Pipeline(options=PipelineOptions(pipeline_args)) as p:
lines = p | 'read' >> ReadFromText(known_args.input)
(lines
| 'words'>> beam.ParDo(scrip_val())
)
if __name__ == '__main__':
logging.getLogger().setLevel(logging.INFO)
run()`

但是当我尝试使用此命令从 Cloud Shell 运行此代码时

python -m  bulksumlog --input [Bucket_location]  --runner DataflowRunner --project [Project_id] --temp_locat
ion [temo_Bucket_location] --save_main_session True

出现以下错误

 return dill.load_session(file_path)
File "/usr/local/lib/python2.7/dist-packages/dill/_dill.py", line 402, 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 1096, in load_global
klass = self.find_class(module, name)
File "/usr/local/lib/python2.7/dist-packages/dill/_dill.py", line 465, in find_class
return StockUnpickler.find_class(self, module, name)
File "/usr/lib/python2.7/pickle.py", line 1130, in find_class
__import__(module)
ImportError: No module named psycopg2.extensions

我安装了所有与psycopg2相关的python库

最佳答案

我们应该使用 psycopg2-binary 运行。就我而言,我安装了 psycopg2-binary(使用 pip),但仍然出现此错误。我在 Fernando Munoz 的回答中找到了帮助 here .我的步骤是:a) pip uninstall psycopg2,b) pip uninstall psycopg2-binary,c) sudo apt install build-dep python-psycopg2(Debian 的先决条件),d) pip install psycopg2-binary

关于python - 在 Cloud DataFlow 上运行我的代码时出现 ImportError : No module named psycopg2. 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52436918/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com