Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1K
Views
Instalación de AWS Glue psycopg2

Estoy tratando de ejecutar un código que usa psycopg2 para manipular una instancia de Redshift. Lo intenté importando un archivo de rueda, ya que veo que son compatibles con los trabajos de Glue python. Veo que la biblioteca está instalada en el punto final cuando se ejecuta, pero luego aparece un error:

 import boto3 import psycopg2
 Aug 4, 2020, 1:24:06 PM Pending execution Processing ./glue-python-libs-92ng4pcb/psycopg2-2.8.5-cp36-cp36m-win_amd64.whl Installing collected packages: psycopg2 Successfully installed psycopg2-2.8.5 Considering file without prefix as a python extra file s3://gluelibraries/boto3.zip
 WARNING: The directory '/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. 2020-08-04T13:24:44.831+02:00 Traceback (most recent call last): File "/tmp/runscript.py", line 123, in <module> runpy.run_path(temp_file_path, run_name='__main__') File "/usr/local/lib/python3.6/runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname) File "/usr/local/lib/python3.6/runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/tmp/glue-python-scripts-1t08aq9n/postloading.py", line 6, in <module> File "/glue/lib/installation/psycopg2/__init__.py", line 51, in <module> from psycopg2._psycopg import ( # noqa ModuleNotFoundError: No module named 'psycopg2._psycopg' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/tmp/runscript.py", line 142, in <module> raise e_type(e_value).with_traceback(new_stack) File "/tmp/glue-python-scripts-1t08aq9n/postloading.py", line 6, in <module> File "/glue/lib/installation/psycopg2/__init__.py", line 51, in <module> from psycopg2._psycopg import ( # noqa ModuleNotFoundError: No module named 'psycopg2._psycopg'

Teóricamente, los trabajos de Glue en python (a diferencia de los trabajos de pyspark) deberían admitir bibliotecas de python que no sean puras

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Me he enfrentado a un problema similar con el paquete psycopg2. Tiene que ver con la compatibilidad con el tiempo de ejecución de Python que accede al módulo psycopg2.

Sigue este hilo. Espero que tengas tu solución. Uso de psycopg2 con Lambda para actualizar Redshift (Python)

over 4 years ago · Santiago Trujillo Report

0

basado en https://stackoverflow.com/a/58305654/4725074

Instale psycopg2-binary en un directorio y comprima el contenido de ese directorio:

 mkdir psycopg2-binary cd psycopg2-binary pip install psycopg2-binary -t . # in case using python3: # python3 -m pip install --system psycopg2-binary -t . zip -r9 psycopg2.zip *

Luego copié psycopg2.zip en un depósito de S3 y lo agregué como una biblioteca adicional de Python en "Ruta de la biblioteca de Python" en el trabajo de Glue Spark.

Luego inicié el trabajo con el siguiente script para verificar si psycopg2 está presente (Glue descargará el archivo zip en el directorio en el que se encuentra el script del trabajo)

 from awsglue.transforms import * from awsglue.utils import getResolvedOptions from pyspark.context import SparkContext from awsglue.context import GlueContext from awsglue.job import Job import sys import os import zipfile ## @params: [JOB_NAME] args = getResolvedOptions(sys.argv, ['JOB_NAME']) sc = SparkContext() glueContext = GlueContext(sc) spark = glueContext.spark_session job = Job(glueContext) job.init(args['JOB_NAME'], args) zip_ref = zipfile.ZipFile('./psycopg2.zip', 'r') print os.listdir('.') zip_ref.extractall('/tmp/packages') zip_ref.close() sys.path.insert(0, '/tmp/packages') import psycopg2 print(psycopg2.__version__) job.commit()

Esto funcionó para mí.

over 4 years ago · Santiago Trujillo Report

0

Ahora, con la versión 2 de Glue, puede pasar bibliotecas de python como parámetros a Glue Jobs. Usé pyscopg2-binary en lugar de pyscopg2 y funcionó para mí. Luego, en el código importé psycopg2.

--módulos-adicionales-python

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!