我尝试创建一个Docker容器来部署在AWS lambda上,但我不断收到错误:
"Unable to import module 'app': No module named '_tkinter'", "errorType": "Runtime.ImportModuleError", "stackTrace": []}
我创建的Docker文件如下:
FROM public.ecr.aws/lambda/python:3.8
RUN yum -y update
RUN yum -y install gcc
RUN yum install -y gcc-c++
RUN yum install -y git
RUN yum install -y which
COPY requirements.txt ./requirements.txt
RUN pip install -r requirements.txt \
&& pip install -e git+https://github.com/ganesh3/icevision.git@master#egg=icevision[inference] --upgrade -q
COPY model_dir ./model_dir
COPY /app/app.py ./
CMD ["app.handler"]
requirements.txt如下:
--find-links https://download.pytorch.org/whl/torch_stable.html
torch==1.10.0+cpu
torchvision==0.11.1+cpu
--find-links https://download.openmmlab.com/mmcv/dist/cpu/torch1.10.0/index.html
mmcv-full==1.3.17
mmdet==2.17.0
numpy
Pillow
tk
The app.py is as below:
# app.py used in the early stages of the project just to test if I was able to import the icevision library
import sys
import os
print("Executing install for fonts")
os.system('mkdir -p /root/.icevision/fonts/')
os.system('curl -LJO https://raw.githubusercontent.com/airctic/storage/master/SpaceGrotesk-Medium.ttf')
os.system('cp SpaceGrotesk-Medium.ttf /root/.icevision/fonts/')
os.system('yum install -y tkinter tcl-devel tk-devel')
os.system('yum search tkinter')
os.system('yum install -y python3-tkinter.x86_64')
print("Before tkinter import")
import tkinter
print("After tkinter import")
import icevision
def handler(event, context):
return 'Hello from AWS Lambda using Python ' + sys.version + ' and IceVision ' + icevision.__version__ + '!'
我还使用以下命令登录到Docker容器:
docker exec -it <container_name> sh
然后我登录到python shell并运行:
>>> import icevision
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/var/task/src/icevision/icevision/__init__.py", line 3, in <module>
from icevision import parsers
File "/var/task/src/icevision/icevision/parsers/__init__.py", line 1, in <module>
from icevision.parsers.parser import *
File "/var/task/src/icevision/icevision/parsers/parser.py", line 7, in <module>
from icevision.data import *
File "/var/task/src/icevision/icevision/data/__init__.py", line 5, in <module>
from icevision.data.convert_records_to_coco_style import *
File "/var/task/src/icevision/icevision/data/convert_records_to_coco_style.py", line 17, in <module>
from icevision.models.inference import *
File "/var/task/src/icevision/icevision/models/__init__.py", line 15, in <module>
from icevision.models import mmdet
File "/var/task/src/icevision/icevision/models/mmdet/__init__.py", line 2, in <module>
from icevision.models.mmdet.models import *
File "/var/task/src/icevision/icevision/models/mmdet/models/__init__.py", line 18, in <module>
from icevision.models.mmdet.models import mask_rcnn
File "/var/task/src/icevision/icevision/models/mmdet/models/mask_rcnn/__init__.py", line 2, in <module>
from icevision.models.mmdet.common.mask.two_stage import *
File "/var/task/src/icevision/icevision/models/mmdet/common/mask/two_stage/__init__.py", line 2, in <module>
from icevision.models.mmdet.common.mask.two_stage.model import *
File "/var/task/src/icevision/icevision/models/mmdet/common/mask/two_stage/model.py", line 3, in <module>
from turtle import back
File "/var/lang/lib/python3.8/turtle.py", line 107, in <module>
import tkinter as TK
File "/var/lang/lib/python3.8/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
我在Python壳里跑了下面:
import subprocess
subprocess.call(['pip', 'install', 'tk'])
我还运行了以下命令来安装tkinter:
yum install -y tkinter
yum install -y python3-tkinter
tkinter的导入仍然失败。我正在检查这个,因为我得到这个错误,无论是否导入tkinter,因为一些其他库正在内部导入它。
有人能建议修改以解决错误吗?
温馨的问候Ganesh Bhat
1条答案
按热度按时间deyfvvtc1#
已注解掉以下代码以解决此问题: