AWS Glue에서 “ImportError: No module named(이름이 지정된 모듈 없음)”을 해결하려면 어떻게 해야 합니까?

2분 분량
0

AWS Glue Python 셸을 사용하여 추가 모듈이나 패키지를 가져오려고 하면 “ImportError: No module named(이름이 지정된 모듈 없음)” 응답이 표시됩니다. 예: ImportError: No module named pyarrow.compat

간략한 설명

AWS Glue Python 셸은 .egg.whl 파일을 사용합니다. Python은 .egg 또는 .whl 파일에서 직접 가져올 수 있습니다. 호환성을 유지하려면 로컬 빌드 환경에서 Python 셸 작업과 동일한 Python 버전을 사용하는지 확인하세요. 예를 들어 Python 3을 사용하여 .egg 파일을 빌드하는 경우 AWS Glue Python 셸 작업에 Python 3을 사용합니다.

참고: 2022년 6월 1일부터 Python 셸 작업은 Python 3만 지원합니다. 자세한 내용은 AWS Glue 버전 지원 정책을 참조하십시오.

해결 방법

1.    setup.py 파일을 생성하고 install_requires 파라미터를 추가하여 가져올 모듈을 나열합니다.

from setuptools import setup

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

2.    현재 디렉터리 아래에 reshift_module라는 이름의 폴더를 생성합니다.

$ mkdir redshift_module

그런 다음 패키지를 설치합니다.

$ python setup.py develop

예제 출력:

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.    다음 중 하나를 수행합니다.

.egg 파일 생성:

python setup.py bdist_egg

또는 .whl 파일 생성:

python setup.py bdist_wheel

5.    .egg 또는 .whl 파일을 dist 폴더에서 Amazon Simple Storage Service(Amazon S3) 버킷으로 복사합니다. 자세한 내용은 자체 Python 라이브러리 제공을 참조하세요. 예:

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

참고: AWS 명령줄 인터페이스(AWS CLI) 명령을 실행할 때 오류가 발생할 경우 AWS CLI의 최신 버전을 사용하고 있는지 확인하세요.

6.    모듈이 이제 Python 셸 작업에 설치됩니다. 확인하려면 Amazon CloudWatch Logs 그룹에서 Python 셸 작업(/aws-glue/python-jobs/output)을 확인하세요. 다음은 성공적인 출력의 예입니다.

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

관련 정보

AWS Glue 1.0 또는 0.9 ETL 작업에서 외부 Python 라이브러리를 사용하려면 어떻게 해야 합니까?

AWS Glue 2.0 ETL 작업에서 외부 Python 라이브러리를 사용하려면 어떻게 해야 합니까?

AWS 공식
AWS 공식업데이트됨 2년 전