需求.txt未安装在Docker容器中

发布于 2025-02-13 08:56:35 字数 2497 浏览 1 评论 0原文

我有以下dockerfile

FROM jupyter/scipy-notebook

COPY . ./work

COPY setup.py /work

RUN pip install --upgrade pip && pip install -e .

RUN pip install -r ./work/requirements.txt

COPY src /work/src

WORKDIR /work

,以下docker-compose.yml

version: '3.7'

networks:
  ling172:

services:
   jupyter:
      
      image: jupyter/datascience-notebook:r-4.0.3
      environment:
        - JUPYTER_TOKEN=password
        - JUPYTER_ENABLE_LAB=yes

      volumes:
        - .:/home/jovyan/work
        - ./notebooks:/home/jovyan/work
        - ./src:/home/jovyan/work
      ports:
        - 7777:8888
      container_name: almond_analysis
      networks:
        - ling172

和以下要求。txt文件

openpyxl==3.0.10

项目结构为

almond_analysis:
    notebooks:
        data_exploration.ipynb
    src:
       __init__.py
       plots.py
    .gitignore
    docker-compose.yml
    Dockerfile
    README.md
    requirements.txt
    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.*",
)

问题是,一旦我打开data_exploration。 ipynb笔记本OpenPyXl尚未安装软件包,这意味着尚未读取unignts.txt文件。我怀疑这是因为我正在使用命令docker组成-d启动容器,这意味着我没有重建图像,这意味着未读取Dockerfile。因此,我如下修改了docker-compose.yml文件(即我添加了构建:。

version: '3.7'

networks:
  ling172:

services:
   jupyter:
      build: .
      image: jupyter/datascience-notebook:r-4.0.3
      environment:
        - JUPYTER_TOKEN=password
        - JUPYTER_ENABLE_LAB=yes

      volumes:
        - .:/home/jovyan/work
        - ./notebooks:/home/jovyan/work
        - ./src:/home/jovyan/work
      ports:
        - 7777:8888
      container_name: almond_analysis
      networks:
        - ling172

,但没有运气。

有人知道如何成功安装unignts.txt中的软件包吗?

I have got the following Dockerfile

FROM jupyter/scipy-notebook

COPY . ./work

COPY setup.py /work

RUN pip install --upgrade pip && pip install -e .

RUN pip install -r ./work/requirements.txt

COPY src /work/src

WORKDIR /work

and the following docker-compose.yml

version: '3.7'

networks:
  ling172:

services:
   jupyter:
      
      image: jupyter/datascience-notebook:r-4.0.3
      environment:
        - JUPYTER_TOKEN=password
        - JUPYTER_ENABLE_LAB=yes

      volumes:
        - .:/home/jovyan/work
        - ./notebooks:/home/jovyan/work
        - ./src:/home/jovyan/work
      ports:
        - 7777:8888
      container_name: almond_analysis
      networks:
        - ling172

and the following requirements.txt file

openpyxl==3.0.10

The project structure is

almond_analysis:
    notebooks:
        data_exploration.ipynb
    src:
       __init__.py
       plots.py
    .gitignore
    docker-compose.yml
    Dockerfile
    README.md
    requirements.txt
    setup.py

and the setup file is

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.*",
)

The problem is that once I open the data_exploration.ipynb notebook the openpyxl package has not been installed, which means that the requirements.txt file has not been read. I suspect that this is because I am starting the container with the command docker compose up -d which means that I am not rebuilding the image, which means that the Dockerfile is not read. So I modified the docker-compose.yml file as follows (ie I added build: .)

version: '3.7'

networks:
  ling172:

services:
   jupyter:
      build: .
      image: jupyter/datascience-notebook:r-4.0.3
      environment:
        - JUPYTER_TOKEN=password
        - JUPYTER_ENABLE_LAB=yes

      volumes:
        - .:/home/jovyan/work
        - ./notebooks:/home/jovyan/work
        - ./src:/home/jovyan/work
      ports:
        - 7777:8888
      container_name: almond_analysis
      networks:
        - ling172

but without luck.

Does anyone know how to install, successfully, the packages in requirements.txt?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本王不退位尔等都是臣 2025-02-20 08:56:35

通过键入docker-compose -d-build与第二个docker-compose.yml文件和所有其他文件(如@dallyger建议) )。

Solved by typing docker-compose up -d --build with the second docker-compose.yml file and all other files as shown in the question (as suggested by @dallyger).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文