Python 的 setuptools 无法在我的 Github Actions 工作流程中随机安装

问题描述 投票:0回答:2

在过去的几周里,我注意到我的 Github Actions 工作流程在安装 setuptools 库时随机失败。通常运行工作流程一两次就能解决问题,但我不确定如何避免这种情况发生。

  • Github Actions 运行于:ubuntu-latest
  • Python版本:3.10.13(使用3.11.6和3.11.8测试)
  • setuptools版本:在我的pyproject.toml中设置为69.1.1,但诗歌决定将其更新为69.2.0

安装是通过 Poetry 进行的,无需 virtualenv (

poetry config virtualenvs.create false && poetry install --no-root
)。

错误日志:

...
- Updating setuptools (65.5.0 -> 69.1.1)

  ChefInstallError

  Failed to install setuptools >= 40.8.0.
  
  Output:
  Updating dependencies
  Resolving dependencies...
  
  Package operations: 1 install, 0 updates, 0 removals
  
    - Installing setuptools (69.2.0)
  
    CalledProcessError
  
    Command '['/tmp/tmpd2m4qzu7/.venv/bin/python', '-I', '-W', 'ignore', '-c', '\nimport importlib.util\nimport json\nimport sys\n\nfrom pathlib import Path\n\nspec = importlib.util.spec_from_file_location(\n    "packaging", Path(r"/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/packaging/__init__.py")\n)\npackaging = importlib.util.module_from_spec(spec)\nsys.modules[spec.name] = packaging\n\nspec = importlib.util.spec_from_file_location(\n    "packaging.tags", Path(r"/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/packaging/tags.py")\n)\npackaging_tags = importlib.util.module_from_spec(spec)\nspec.loader.exec_module(packaging_tags)\n\nprint(\n    json.dumps([(t.interpreter, t.abi, t.platform) for t in packaging_tags.sys_tags()])\n)\n']' returned non-zero exit status 1.
  
    at /opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/subprocess.py:526 in run
         522│             # We don't call process.wait() as .__exit__ does that for us.
         523│             raise
         524│         retcode = process.poll()
         525│         if check and retcode:
      →  526│             raise CalledProcessError(retcode, process.args,
         527│                                      output=stdout, stderr=stderr)
         528│     return CompletedProcess(process.args, retcode, stdout, stderr)
         529│ 
         530│ 
  
  The following error occurred when trying to handle this error:
  
  
    EnvCommandError
  
    Command ['/tmp/tmpd2m4qzu7/.venv/bin/python', '-I', '-W', 'ignore', '-c', '\nimport importlib.util\nimport json\nimport sys\n\nfrom pathlib import Path\n\nspec = importlib.util.spec_from_file_location(\n    "packaging", Path(r"/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/packaging/__init__.py")\n)\npackaging = importlib.util.module_from_spec(spec)\nsys.modules[spec.name] = packaging\n\nspec = importlib.util.spec_from_file_location(\n    "packaging.tags", Path(r"/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/packaging/tags.py")\n)\npackaging_tags = importlib.util.module_from_spec(spec)\nspec.loader.exec_module(packaging_tags)\n\nprint(\n    json.dumps([(t.interpreter, t.abi, t.platform) for t in packaging_tags.sys_tags()])\n)\n'] errored with the following return code 1
    
    Error output:
    Traceback (most recent call last):
      File "<string>", line 18, in <module>
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/packaging/tags.py", line 26, in <module>
      File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/packaging/_manylinux.py", line 10, in <module>
      File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 879, in exec_module
      File "<frozen importlib._bootstrap_external>", line 1016, in get_code
      File "<frozen importlib._bootstrap_external>", line 1073, in get_data
    FileNotFoundError: [Errno 2] No such file or directory: '/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/packaging/_elffile.py'
    
  
    at /opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/poetry/utils/env/base_env.py:342 in _run
        338│                 output = subprocess.check_output(
        339│                     cmd, stderr=stderr, env=env, text=True, **kwargs
        340│                 )
        341│         except CalledProcessError as e:
      → 342│             raise EnvCommandError(e)
        343│ 
        344│         return output
        345│ 
        346│     def execute(self, bin: str, *args: str, **kwargs: Any) -> int:
  
  Cannot install setuptools.
  
  
  
  Error:
  

  at /opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/poetry/installation/chef.py:102 in install
       98│             InstalledRepository.load(self._env),
       99│         )
      100│         installer.update(True)
      101│         if installer.run() != 0:
    → 102│             raise ChefInstallError(requirements, io.fetch_output(), io.fetch_error())
      103│ 
      104│ 
      105│ class Chef:
      106│     def __init__(

Cannot install build-system.requires for odfpy.

我尝试过更改 python 版本,以防它是特定版本的 Python 的错误,并且我还尝试在 Poetry 之前使用 pip 安装 setuptools,以防它是诗歌错误,但这没有什么区别。

几个月来它一直运行良好,现在每 3 次运行中有 1 次会因此错误而失败。有什么想法吗?

python-3.x github-actions setuptools python-poetry
2个回答
4
投票

我不知道为什么我之前没有测试过这个(我猜是隧道视觉),但我通过在我的 pyproject.toml 中将 setuptools 库的最大版本限制为 69.1.* 来解决这个问题,如下所示:

setuptools = "~69.1"

如果其他人遇到此问题,该错误似乎是由 setuptool 版本 69.2.0 引起的,但版本 69.1.1 工作得很好。


0
投票

即使在 pyproject.toml 中将

setuptools
版本锁定为“~69.1”之后,我仍然在 GitHub Actions 中遇到完全相同的错误。即使 pyproject.toml 中有
setuptools = "~69.1"
,它也会尝试安装 setuptools (75.6.0)。

#11 5.921   - Updating setuptools (65.5.1 -> 69.1.1)

#11 13.88   ChefInstallError
#11 13.89 
#11 13.90   Failed to install setuptools >= 40.8.0.
#11 13.90   
#11 13.90   Output:
#11 13.90   Updating dependencies
#11 13.90   Resolving dependencies...
#11 13.90   
#11 13.90   Package operations: 1 install, 0 updates, 0 removals
#11 13.90   
#11 13.90     - Installing setuptools (75.6.0)
#11 13.90   
#11 13.90     CalledProcessError
© www.soinside.com 2019 - 2024. All rights reserved.