官方文档:
https://docs.amazonaws.cn/glue/latest/dg/aws-glue-programming-python-libraries.html
方案思路:
遇到 pip 下载失败多半是由于国内的网络对于官方源访问不友好,所以就有两个思路:
-
- 切换国内的源,国内源在国内访问一般都很快很稳定;
- 本地下载好后打包上传,glue job 中引用自己打的包,杜绝 glue 使用网络下载依赖模块;
基于以上思路,目前共想到 3 种方案:
方案1:
第 1 种思路,在 job parameters 添加以下参数以使用国内镜像源安装依赖库:
--additional-python-modules timezonefinder,pygeohash
--python-modules-installer-option --default-timeout=1000 -i https://pypi.douban.com/simple --extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple --extra-index-url https://mirrors.aliyun.com/pypi/simple/ --extra-index-url https://pypi.mirrors.ustc.edu.cn/simple/
方案2(不建议):
第 1 种思路,在 glue job 中添加以下代码:
import os
libs = {"numpy", "matplotlib", "pillow", "sklearn", "requests", "jieba", "beautifulsoup4", "wheel", "networkx", "sympy"}
try:
for lib in 1ibs:
os.system("pip install" + lib + "-i https://pypi.douban.com/simple --extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple --extra-index-url https://mirrors.aliyun.com/pypi/simple/ --extra-index-url https://pypi.mirrors.ustc.edu.cn/simple/")
print("Install Succeed" + lib)
except:
print( "Install Failed")
但不建议采用此方案,此方案将非业务代码与业务代码进行耦合,违背 AOP 原则,不利于维护。
方案3(终极方案):
第 2 种思路,在本地安装依赖库后,打包上传到 s3,glue job 使用 s3 上的依赖包:
# 1.本地安装依赖库:
pip3 install timezonefinder
# 2.压缩依赖库:
pip3 show timezonefinder
Location: /home/dogxu/.local/lib/python3.7/site-packages
zip -r timezonefinder-6.0.1.zip /home/dogxu/.local/lib/python3.7/site-packages/timezonefinder/
# 3.上传到 s3:
aws s3 cp timezonefinder-6.0.1.zip s3://dogxu/py3_modules/
# 4.glue job 添加依赖库路径:
Python lib path s3://dogxu/glue_scripts/fms_functions.py,s3://dogxu/py3_modules/timezonefinder-6.0.1.zip
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容