ValueError:在Docker Image中安装Python包时,“Requirement”对象没有字段“use_pep517”

btqmn9zl  于 2023-08-02  发布在  Python
关注(0)|答案(3)|浏览(185)

我在Dockerfile中使用pipenv安装Python依赖项时遇到问题。
Dockerfile:

RUN pip install --upgrade pip
RUN pip install pipenv

# Copy dependencies source code
WORKDIR /projects

# Copy project source code
WORKDIR /projects/source
COPY ./projects/source .

# Install packages
RUN pipenv install --system --deploy

字符串
我们使用以下pipenv依赖项成功构建了镜像:

# Result of pip install pipenv
Successfully installed certifi-2023.5.7 distlib-0.3.6 filelock-3.12.2 pipenv-2023.7.11 platformdirs-3.9.1 setuptools-68.0.0 virtualenv-20.24.0 virtualenv-clone-0.5.7


但是现在,当我们在Docker镜像中执行pipenv install --system --deploy时,我们遇到了这个错误:

# Result when executing pipenv install --system --deploy
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/pipenv/cli/options.py", line 58, in main
    return super().main(*args, **kwargs, windows_expand_args=False)
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/pipenv/cli/command.py", line 233, in install
    do_install(
  File "/usr/local/lib/python3.10/site-packages/pipenv/routines/install.py", line 170, in do_install
    do_init(
  File "/usr/local/lib/python3.10/site-packages/pipenv/routines/install.py", line 777, in do_init
    do_install_dependencies(
  File "/usr/local/lib/python3.10/site-packages/pipenv/routines/install.py", line 455, in do_install_dependencies
    batch_install(
  File "/usr/local/lib/python3.10/site-packages/pipenv/routines/install.py", line 596, in batch_install
    batch_install_iteration(
  File "/usr/local/lib/python3.10/site-packages/pipenv/routines/install.py", line 538, in batch_install_iteration
    _cleanup_procs(project, procs, failed_deps_queue, retry=retry)
  File "/usr/local/lib/python3.10/site-packages/pipenv/routines/install.py", line 651, in _cleanup_procs
    dep.use_pep517 = True
  File "/usr/local/lib/python3.10/site-packages/pipenv/vendor/requirementslib/models/common.py", line 18, in __setattr__
    raise ValueError(f'"{self.__class__.__name__}" object has no field "{name}"')
ValueError: "Requirement" object has no field "use_pep517"


当Docker尝试安装pipenv时,我确实注意到distlib版本发生了轻微的变化,但不确定这是否是问题所在

Successfully installed certifi-2023.5.7 distlib-0.3.7 filelock-3.12.2 pipenv-2023.7.11 platformdirs-3.9.1 setuptools-68.0.0 virtualenv-20.24.0 virtualenv-clone-0.5.7


我尝试升级我的本地pipenv并重建Pipfile.lock,但当我尝试在Docker镜像中构建它时,它仍然给出相同的错误。

a14dhokn

a14dhokn1#

我在Docker中构建的几个Python项目中遇到了同样的问题。看起来这是PyYAML的问题。这是我看到修复的另一个帖子:
Docker-compose no longer building image (AttributeError: cython_sources)
我为不同的项目使用了两种不同的解决方法。在一个项目中,我只是升级了所有工作的包。在另一个项目中,我最终不得不切换回PyYAML 5.3.1。这些项目只是内部的,所以我不太担心安全问题。
需要注意的一点是,尝试使用pip而不是pipenv安装失败的特定软件包(我一个接一个地尝试,直到找到罪魁祸首)将产生一个更具体的错误消息,导致我链接到答案。
希望这对你有帮助!

41zrol4v

41zrol4v2#

我在以前的优秀CI管道中遇到了同样的问题。对我来说,重新生成锁定文件修复了它。可以使用以下命令重新生成锁定文件:

pipenv lock

字符串

w6lpcovy

w6lpcovy3#

我也遇到了类似的问题,Cristhian Ulloa(https://stackoverflow.com/a/76724894/201657)的回复帮了我,所以我想分享一下我的情况。
在我的Pipfile中,我安装了schemachange==3.4.1,它依赖于PyYAML==5.4.1。我更改为schemachange==3.5.3,安装了PyYAML==6.0.1,运行pipenv lock来更新Pipfile.lock。git push艾德了两个已更改的文件...我的GitHub Actions管道成功了,而它之前失败了。

相关问题