我正在按照this教程在AWS sagemaker上部署一个自定义的pytorch模型。在我的例子中,我很少依赖于安装一些模块。
我需要在我的inference.py脚本中使用pycocotools。我可以使用这个bash命令很容易地在一个单独的笔记本中安装pycocotool,
%%bash
pip -g install pycocotools
但是当我为部署创建我的端点时,我得到了这个错误,即pycocotools没有被定义。我需要在我的inference.py脚本中使用pycocotools。如何将其安装到.py文件中
发布于 2021-04-21 08:31:28
在inference.py的开头添加以下行:
from subprocess import check_call, run, CalledProcessError
import sys
import os
# Since it is likely that you're going to run inference.py multiple times, this avoids reinstalling the same package:
if not os.environ.get("INSTALL_SUCCESS"):
try:
check_call(
[ sys.executable, "pip", "install", "pycocotools",]
)
except CalledProcessError:
run(
["pip", "install", "pycocotools",]
)
os.environ["INSTALL_SUCCESS"] = "True"https://stackoverflow.com/questions/67186515
复制相似问题