Wie behebe ich „ImportError“: Kein Modul mit dem Namen „“ in AWS Glue?

Lesedauer: 3 Minute
0

Wenn ich versuche, zusätzliche Module oder Pakete mithilfe der AWS Glue Python-Shell zu importieren, erhalte ich einen „ImportError“: Kein Modul mit dem Namen „Antwort“. Zum Beispiel: Fehler beim Import: Kein Modul namens pyarrow.compat

Kurzbeschreibung

Die AWS Glue Python-Shell verwendet .egg - und .whl-Dateien. Python kann direkt aus einer .egg oder .whl -Datei importieren. Um die Kompatibilität aufrechtzuerhalten, stellen Sie sicher, dass Ihre lokale Build-Umgebung dieselbe Python-Version wie der Python-Shelljob verwendet. Wenn Sie beispielsweise eine .egg -Datei mit Python 3 erstellen, verwenden Sie Python 3 für den Python-Shelljob von AWS Glue.

Hinweis: Ab dem 1. Juni 2022 unterstützen Python-Shelljobs nur Python 3. Weitere Informationen finden Sie in der Richtlinie zur Unterstützung von AWS Glue-Versionen.

Behebung

1.    Erstellen Sie die Datei setup.py und fügen Sie den Parameter install_requires hinzu, um die Module aufzulisten, die Sie importieren möchten:

from setuptools import setup

setup(
    name="redshift_module",
    version="0.1",
    packages=['redshift_module'],
    install_requires=['pyarrow','pandas','numpy','fastparquet']
)

2.    Erstellen Sie einen Ordner mit dem Namen reshift_module unter dem aktuellen Verzeichnis:

$ mkdir redshift_module

Installieren Sie dann die Pakete:

$ python setup.py develop

Beispiel für eine Ausgabe:

running develop
running egg_info
writing requirements to redshift_module.egg-info/requires.txt
writing redshift_module.egg-info/PKG-INFO
writing top-level names to redshift_module.egg-info/top_level.txt
writing dependency_links to redshift_module.egg-info/dependency_links.txt
reading manifest file 'redshift_module.egg-info/SOURCES.txt'
writing manifest file 'redshift_module.egg-info/SOURCES.txt'
running build_ext
Creating /usr/local/lib/python3.6/site-packages/redshift-module.egg-link (link to .)
redshift-module 0.1 is already the active version in easy-install.pth
Using /Users/test/Library/Python/3.6/lib/python/site-packages
Searching for pandas==0.24.2
Best match: pandas 0.24.2
Adding pandas 0.24.2 to easy-install.pth file

Using /usr/local/lib/python3.6/site-packages
Searching for pyarrow==0.12.1
Best match: pyarrow 0.12.1
Adding pyarrow 0.12.1 to easy-install.pth file
Installing plasma_store script to /usr/local/bin

3.    Führen Sie einen der folgenden Schritte aus:

Erstellen Sie eine .egg -Datei:

python setup.py bdist_egg

-oder- Erstellen Sie eine.whl-Datei:

python setup.py bdist_wheel

5.    Kopieren Sie die .egg oder .whl Datei aus dem Ordner dist in einen Amazon Simple Storage Service (Amazon S3)-Bucket. Weitere Informationen finden Sie unter Bereitstellen einer eigenen Python-Bibliothek. Beispiel:

dist aws s3 cp MOA_EDM_cdc_controller_g2-0.2.9-py3-none-any.whl s3://doc-example-bucket/glue-libs/python-shell-jobs/
upload: ./MOA_EDM_cdc_controller_g2-0.2.9-py3-none-any.whl to s3://doc-example-bucket/glue-libs/python-shell-jobs/MOA_EDM_cdc_controller_g2-0.2.9-py3-none-any.whl

Hinweis: Wenn Sie beim Ausführen von AWS Command Line Interface (AWS CLI)-Befehlen Fehler erhalten, stellen Sie sicher, dass Sie die neueste AWS CLI-Version verwenden.

6.    Das Modul ist jetzt in Ihrem Python-Shelljob installiert. Suchen Sie zur Bestätigung in der Amazon CloudWatch Logs-Gruppe nach Python-Shelljobs (/aws-glue/python-jobs/output). Hier ist ein Beispiel für eine erfolgreiche Ausgabe:

Searching for pyarrow
Reading https://pypi.python.org/simple/pyarrow/
Downloading https://files.pythonhosted.org/packages/fe/3b/267c0fdb3dc5ad7989417cfb447fbcbec008bafc1bb26d4f0221c5e4e508/pyarrow-0.12.1-cp27-cp27mu-manylinux1_x86_64.whl#sha256=63170571cccaf0bf01a1d30eacc4d9274bd5c4f448c2b5b1a4ddc125952f4284
Best match: pyarrow 0.12.1
Processing pyarrow-0.12.1-cp27-cp27mu-manylinux1_x86_64.whl
Installing pyarrow-0.12.1-cp27-cp27mu-manylinux1_x86_64.whl to /glue/lib/installation
writing requirements to /glue/lib/installation/pyarrow-0.12.1-py3.6-linux-x86_64.egg/EGG-INFO/requires.txt
Adding pyarrow 0.12.1 to easy-install.pth file
Installing plasma_store script to /glue/lib/installation
Installed /glue/lib/installation/pyarrow-0.12.1-py3.6-linux-x86_64.egg

Ähnliche Informationen

Wie verwende ich externe Python-Bibliotheken in meinem AWS Glue 1.0 oder 0.9 ETL-Job?

Wie verwende ich externe Python-Bibliotheken in meinem AWS Glue 2.0-ETL-Job?

AWS OFFICIAL
AWS OFFICIALAktualisiert vor 2 Jahren