gpt4 book ai didi

python slim 或 alpine docker 镜像无法使用 pipenv 安装软件包

转载 作者:行者123 更新时间:2023-12-04 12:58:07 26 4
gpt4 key购买 nike

我正在尝试为我的 python 应用程序构建一个 docker 容器,但是在通过 pipenv 安装 python 包时遇到了问题。
如果我将基本图像设置为 python:3.8.5但是,如果我设置了 -slim,它会起作用版本或 -alpine版本失败并出现以下错误:

 Traceback (most recent call last):   File "/usr/local/bin/pipenv",
line 8, in <module>
sys.exit(cli()) File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/core.py",
line 829, in __call__
return self.main(*args, **kwargs) File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/core.py",
line 782, in main
rv = self.invoke(ctx) File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/core.py",
line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/core.py",
line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params) File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/core.py",
line 610, in invoke
return callback(*args, **kwargs) File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/decorators.py",
line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs) File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/core.py",
line 610, in invoke
return callback(*args, **kwargs) File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/decorators.py",
line 21, in new_func
return f(get_current_context(), *args, **kwargs) File "/usr/local/lib/python3.8/site-packages/pipenv/cli/command.py", line
232, in install
retcode = do_install( File "/usr/local/lib/python3.8/site-packages/pipenv/core.py", line 2052, in
do_install
do_init( File "/usr/local/lib/python3.8/site-packages/pipenv/core.py", line 1305, in
do_init
do_install_dependencies( File "/usr/local/lib/python3.8/site-packages/pipenv/core.py", line 899, in
do_install_dependencies
batch_install( File "/usr/local/lib/python3.8/site-packages/pipenv/core.py", line 796, in
batch_install
_cleanup_procs(procs, failed_deps_queue, retry=retry) File "/usr/local/lib/python3.8/site-packages/pipenv/core.py", line 703, in
_cleanup_procs
raise exceptions.InstallError(c.dep.name, extra=err_lines) pipenv.exceptions.InstallError: ERROR: Couldn't install package:
brotlipy Package installation failed...
Dockerfile
FROM python:3.8.5-slim

RUN pip install pipenv

WORKDIR /app

COPY ./ /app/

RUN pipenv install --sequential --deploy --verbose

RUN python -m spacy download en_core_web_sm

RUN pip install gunicorn[gevent]

EXPOSE 8080

CMD gunicorn -c src/gunicorn.conf.py --chdir src wsgi:app
pipfile
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
autopep8 = "*"

[packages]
pytest = "*"
aiomysql = "*"
pytest-asyncio = "*"
spacy = "*"
nltk = "*"
jsonschema = "*"
cachetools = "*"
pycountry = "*"
boto3 = "*"
aiohttp = {extras = ["speedups"], version = "*"}
install = "*"
cchardet = "*"
aiohttp-cors = "*"
pytest-aiohttp = "*"
aiohttp-devtools = "*"
json-logging = "*"

[requires]
python_version = "3.8"
更新:
添加包进行编译后,这次我得到了不同的错误,现在运行也需要很长时间。
RUN apk add gcc g++ libffi-dev musl-dev \
Exception information:
Traceback (most recent call last):
File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 216, in _main
status = self.run(options, args)
File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 182, in wrapper
return func(self, options, args)
File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 324, in run
requirement_set = resolver.resolve(
File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.8/site-packages/pip/_internal/resolution/legacy/resolver.py", line 183, in resolve
discovered_reqs.extend(self._resolve_one(requirement_set, req))
File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.8/site-packages/pip/_internal/resolution/legacy/resolver.py", line 388, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.8/site-packages/pip/_internal/resolution/legacy/resolver.py", line 340, in _get_abstract_dist_for
abstract_dist = self.preparer.prepare_linked_requirement(req)
File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 482, in prepare_linked_requirement
abstract_dist = _get_prepared_distribution(
File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 91, in _get_prepared_distribution
abstract_dist.prepare_distribution_metadata(finder, build_isolation)
File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.8/site-packages/pip/_internal/distributions/sdist.py", line 33, in prepare_distribution_metadata
self.req.load_pyproject_toml()
File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.8/site-packages/pip/_internal/req/req_install.py", line 503, in load_pyproject_toml
pyproject_toml_data = load_pyproject_toml(
File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.8/site-packages/pip/_internal/pyproject.py", line 95, in load_pyproject_toml
raise InstallationError(
pip._internal.exceptions.InstallationError: Disabling PEP 517 processing is invalid: project specifies a build backend of setuptools.build_meta in pyproject.toml
Removed cryptography==3.0 from https://files.pythonhosted.org/packages/bf/ac/552fc8729d90393845cc3a2062facf4a89dcbe206fa78771d60ddaae7554/cryptography-3.0.tar.gz#sha256=8e924dbc025206e97756e8903039662aa58aa9ba357d8e1d8fc29e3092322053 (from -r /tmp/pipenv-9avbndah-requirements/pipenv-ituvdg4a-requirement.txt (line 1)) from build tracker '/tmp/pip-req-tracker-roedt7he'
Removed build tracker: '/tmp/pip-req-tracker-roedt7he'
Removing intermediate container de278d8d660a
---> bb539a91d593
Step 7/10 : RUN python -m spacy download en_core_web_sm
---> Running in d568290d25da
/usr/local/bin/python: No module named spacy

最佳答案

可以将问题最小化为 Dockerfile

FROM python:3.8.5-slim
RUN pip install --no-cache-dir brotlipy
如果你运行这个,你会得到错误
...
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1
...
-slim-alpine图像不包括 C 编译器,而 python:3.8.5图像。如果您安装 C 编译器,您可能会遇到其他错误,例如缺少 limit.s , ffi.h ,以及 C++ 标准库。
这是一个使用 -alpine 的最小工作示例图片。
FROM python:3.8.5-alpine
RUN apk add gcc g++ libffi-dev musl-dev \
&& python -m pip install --no-cache-dir brotlipy \
&& apk del gcc g++ libffi-dev musl-dev
这是 -slim 的完整示例图片。使用 pipenv run python运行 spacy 部分。
FROM python:3.8.5-slim

ARG DEBIAN_FRONTEND="noninteractive"

RUN pip install pipenv

WORKDIR /app

COPY ./ /app/

RUN apt-get update \
&& apt-get install --yes --no-install-recommends \
gcc g++ libffi-dev \
&& pipenv install --sequential --deploy --verbose \
&& apt-get autoremove --yes gcc g++ libffi-dev \
&& rm -rf /var/lib/apt/lists/*

RUN pipenv run python -m spacy download en_core_web_sm

RUN pipenv install gunicorn[gevent]

EXPOSE 8080

CMD gunicorn -c src/gunicorn.conf.py --chdir src wsgi:app

关于python slim 或 alpine docker 镜像无法使用 pipenv 安装软件包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63525628/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com