您好我有一个 python 项目包含以下结构
在我的项目目录中
$ ls
models main.py Dockerfile
其中 models 是一个目录,这样
$ cd models
$ ls
model.py utils.py evaluation __init__.py
在我的main.py文件中,我有类似的东西
from models import model
在我的model.py档案中我有
from .utils import *
from evaluation import somefile
我正在尝试创建一个 docker 图像,我按照以下教程进行操作Dockerfile
FROM python:3.7.2-slim
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY main.py /
CMD [ "python", "./main.py" ]
在哪里requirements.txt安装numpy等
跑步docker build -t test很好,并相应地创造事物。但是当我跑的时候docker run test。它给出了错误
Traceback (most recent call last):
File "./main.py", line 1, in <module>
from models import model
ModuleNotFoundError: No module named 'models'
我假设执行时也有错误,from .utils import *甚至上述错误也已解决。from evaluation import somefilemodel.py
我想我认为我没有理解依赖关系在Docker中是如何工作的,没有正确解决依赖关系。这段代码在以 python 方式运行时工作正常,例如$ python main.py在终端中。
我找不到这部分的任何文件。有什么帮助吗?谢谢
交互式爱情
相关分类