I have a docker-image in which I want to install my own package, mypackage, using the .toml and .lock file from poetry - inspired by this SO answer.
It seems to work fine, all the dependencies in the .toml are being installed but the package itself is not.
If I add an RUN poetry add mypackage I get an error Package 'mypackage' is listed as a dependency of itself. If I don't I get a ModuleError: No module named 'mypackage'.
If I spawn er terminal in the container, I can pip list the dependencies, but not mypackage
I have also tried copying mypackage/ into my workdir (scripts/) in the Dockerfile but the same issue persists. Maybe there's some file-structure that's wrong? I'm not very experience with Docker, thus some of the files might not be where I think they are.
# pyproject.toml
[tool.poetry]
name = "mypackage"
version = "1"
description = ""
authors = ["me"]
readme = "README.md"
[tool.poetry.dependencies]
python = "~3.10"
waitress = "2.1.2"
flask = "2.2.2"
scikit-learn = "1.2.1"
cython = "^0.29.33"
gensim = "^4.3.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
and
FROM python:3.10-slim-bullseye
RUN apt update && apt install
RUN apt install python3-pip -y
RUN pip install "poetry==1.3.1"
RUN mkdir /scripts
COPY poetry.lock pyproject.toml /scripts/
# COPY mypackage/ /scripts/
WORKDIR /scripts
RUN poetry config virtualenvs.create false \
&& poetry install --no-dev --no-interaction --no-ansi
# RUN poetry add mypackage
CMD poetry run python -c "import mypackage;"