无法使用木星笔记本图像在Docker容器中安装模块
我有以下docker文件
FROM jupyter/scipy-notebook
COPY . ./work
RUN pip install -r ./work/requirements.txt
COPY setup.py /work
RUN pip install --upgrade pip && pip install -e .
COPY src /work/src
WORKDIR /work
和以下项目结构:
almond_analysis:
notebooks:
data_exploration.ipynb
src:
__init__.py
plots.py
.gitignore
docker-compose.yml
Dockerfile
README.md
requirements.txt
setup.py
内部data_exploration.ipynb
笔记本,我想用命令导入模块
。但是,尽管我在Dockerfile中输入了src
作为测试运行PIP install -e。但是,当我对容器进行操作时,在
Work
目录中,并运行pip install -e。
错误消失了。我尝试在dockerfile的末尾添加cmd pip install -e。
而没有成功。我还阅读了 this 帖子(更具体地说,更具体地说,要添加行运行APT-GET更新
和 运行apt-get install -y-no-no-install-recommends
,但没有成功。
我的setup.py
文件看起来像这样:
from setuptools import find_packages, setup
import sys
import os
sys.path.insert(0, os.path.abspath( os.path.dirname(__file__)))
requirements_path="requirements.txt"
with open(requirements_path) as requirements_file:
requirements = requirements_file.read().splitlines()
setup(
name="almond_analysis",
version="0.0.1",
description = "Almond analysis",
long_description="Analysing yield with Python."
author= "George N",
packages=find_packages(),
install_requires=requirements,
classifiers=[
"Programming Language :: Python :: 3"
],
python_requires =">= 3.0.*",
)
有人知道如何使modulenotfounderror
走开吗?
I have got the following Docker file
FROM jupyter/scipy-notebook
COPY . ./work
RUN pip install -r ./work/requirements.txt
COPY setup.py /work
RUN pip install --upgrade pip && pip install -e .
COPY src /work/src
WORKDIR /work
and the following project structure:
almond_analysis:
notebooks:
data_exploration.ipynb
src:
__init__.py
plots.py
.gitignore
docker-compose.yml
Dockerfile
README.md
requirements.txt
setup.py
Inside the data_exploration.ipynb
notebook, I would like to import the module src
with the command import src as test
. However, despite me having typed RUN pip install -e .
in the Dockerfile, I get the error ModuleNotFoundError: No module named 'src'
. When I do to my container though, inside the work
directory, and run pip install -e .
the error goes away. I tried adding CMD pip install -e .
at the end of the Dockerfile without success. I read also what was suggested in this post (more specifically to add the lines RUN apt-get update
andRUN apt-get install -y --no-install-recommends
but without success.
My setup.py
file looks like this:
from setuptools import find_packages, setup
import sys
import os
sys.path.insert(0, os.path.abspath( os.path.dirname(__file__)))
requirements_path="requirements.txt"
with open(requirements_path) as requirements_file:
requirements = requirements_file.read().splitlines()
setup(
name="almond_analysis",
version="0.0.1",
description = "Almond analysis",
long_description="Analysing yield with Python."
author= "George N",
packages=find_packages(),
install_requires=requirements,
classifiers=[
"Programming Language :: Python :: 3"
],
python_requires =">= 3.0.*",
)
Does someone have an idea on how to make the ModuleNotFoundError
go away?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将代码安装在
Work
文件夹下,然后您不需要安装任何内容,或者确实需要Dockerfile,除非您拥有其他依赖关系。在主机上,为笔记本创建文件夹...
笔记本/src/plots.py
在Compose中,将其安装在Working Directory
/home/jovyan/jovyan/work
上环境,并在工作文件夹中创建笔记本,然后导入模块。
如果您不使用Docker或Jupyter,这与您在主机上所做的工作流程相同,因此这两个都不是问题所在。
Mount your code under the
work
folder, then you don't need to install anything, or really need a Dockerfile unless you have other dependencies.On host, create folder for notebooks...
notebooks/src/plots.py
In compose, mount it under the working directory
/home/jovyan/work
Load up the Jupyter environment, and create a notebook in the work folder, and then import the module.
This is the same workflow you'd do on your host if you weren't using Docker or Jupyter, so neither of those are really the problem.