我使用poetry库来管理项目依赖关系,所以当我使用
docker build --tag=helloworld .
我犯了这个错误
[AttributeError]
'NoneType' object has no attribute 'group' 在umongo (2.1.0)软件包上安装中断
这是我的pyproject.toml文件
[tool.poetry.dependencies]
python = "^3.7.0"
asyncio = "^3.4"
aiohttp = "^3.4"
motor = "^2.0"
umongo = "^2.0"
pyyaml = "^3.13"
[tool.poetry.dev-dependencies]
pytest = "^3.4"
black = {version = "^18.3-alpha.0",allows-prereleases = true}
mypy = "^0.650.0"
wemake-python-styleguide = "^0.5.1"
pytest-mock = "^1.10"
pytest-asyncio = "^0.9.0"
pytest-aiohttp = "^0.3.0"和poetry.lock https://pastebin.com/kUjAKJHM
Dockerfile:
FROM python:3.7.1-alpine
RUN mkdir -p /opt/project/todo_api
RUN pip --no-cache-dir install poetry
COPY ./pyproject.toml /opt/project
COPY poetry.lock /opt/project
RUN cd /opt/project && poetry install --no-dev
COPY ./todo_api /opt/project/todo_api
COPY ./todo_api.yml /opt/project/todo_api.yml
WORKDIR /opt/project
ENTRYPOINT poetry run python -m aiohttp.web todo_api.main:main发布于 2019-08-02 21:14:24
以下几点对我来说是可行的:
FROM python:3.7.1-alpine
WORKDIR /opt/project
RUN pip install --upgrade pip && pip --no-cache-dir install poetry
COPY ./pyproject.toml .
RUN poetry install --no-dev使用pyproject.toml:
[tool.poetry]
name = "57331667"
version = "0.0.1"
authors = ["skufler <skufler@email.com>"]
[tool.poetry.dependencies]
python = "^3.7.0"
asyncio = "^3.4"
aiohttp = "^3.4"
motor = "^2.0"
umongo = "^2.0"
pyyaml = "^3.13"
[tool.poetry.dev-dependencies]
pytest = "^3.4"
black = {version = "^18.3-alpha.0",allows-prereleases = true}
mypy = "^0.650.0"
wemake-python-styleguide = "^0.5.1"
pytest-mock = "^1.10"
pytest-asyncio = "^0.9.0"
pytest-aiohttp = "^0.3.0"然后:
docker build --tag=57331667 --file=./Dockerfile .结果:
...
Creating virtualenv 57331667-py3.7 in /root/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 15 installs, 0 updates, 0 removals
- Installing idna (2.8)
- Installing multidict (4.5.2)
- Installing six (1.12.0)
- Installing async-timeout (3.0.1)
- Installing attrs (18.2.0)
- Installing chardet (3.0.4)
- Installing marshmallow (2.19.5)
- Installing pymongo (3.8.0)
- Installing python-dateutil (2.8.0)
- Installing yarl (1.3.0)
- Installing aiohttp (3.5.4)
- Installing asyncio (3.4.3)
- Installing motor (2.0.0)
- Installing pyyaml (3.13)
- Installing umongo (2.1.0)
Removing intermediate container c6a9c7652b5c
---> 89354562cf16
Successfully built 89354562cf16
Successfully tagged 57331667:latest发布于 2019-08-06 10:51:29
替代方法
不要将poetry安装到部署环境中。它是一个包管理工具,旨在改进图书馆的开发和协作。如果您想部署一个应用程序,您只需要一个包安装程序(read:pip) -而且poetry对构建过程和虚拟环境的固执己见是有害的,而不是有帮助的。
在这种情况下,您想要复制到您的坞映像中的工件是1)您最近构建的库,以及2),它是经过测试的依赖关系的舵手,由poetry.lock定义。
第一个简单,运行poetry build -f wheel,您有一个很好的便携式车轮。第二个问题还不容易,因为poetry不支持建造轮椅(也许永远也不会),而且pip wheel也不接受poetry.lock的文件格式。因此,如果你想沿着这条路走下去,你需要做一个支持poetry export -f requirements.txt > requirements.txt的测试版poetry (v1.0.0b7相当稳定),它允许您创建一个与当前锁文件相同的requirements.txt文件。
一旦您得到了它,您就可以运行pip wheel -w dist -r requirements.txt了,最后,您已经完成了为docker映像创建所有工件。现在,以下内容将发挥作用:
FROM python:3.7.1-alpine
WORKDIR /opt/project
COPY dist dist
RUN pip install --no-index --find-links dist todo_api
ENTRYPOINT python -m aiohttp.web todo_api.main:main优点
poetry的依赖(可能与此相关,因为它仍然是<v1.0)缺点
发布于 2021-12-07 20:58:51
如果您想在生产中使用pip3安装它,下面是最新版本的诗歌(2021年末)如何导出requirements.txt文件:
# Production with no development dependencies
poetry export --no-interaction --no-ansi --without-hashes --format requirements.txt --output ./requirements.prod.txt
# For development, including development dependencies
poetry export --no-interaction --no-ansi --without-hashes --format requirements.txt --dev --output ./requirements.dev.txthttps://stackoverflow.com/questions/57331667
复制相似问题