python - 使用错误版本的 Python 的 Github 操作

标签 python github devops github-actions python-poetry

我有以下 Github 操作,我在其中指定了 Python 3.10:

name: Unit Tests
runs-on: ubuntu-latest
defaults:
  run:
    shell: bash
    working-directory: app
steps:
  - uses: actions/checkout@v3
  - name: Install poetry
    run: pipx install poetry
  - uses: actions/setup-python@v3
    with:
      python-version: "3.10"
      cache: "poetry"
  - run: poetry install
  - name: Run tests
    run: |
      make mypy
      make test

pyproject.toml 也指定了 Python 3.10:

[tool.poetry.dependencies]
python = ">=3.10,<3.11"

当操作运行时,我得到以下信息:

The currently activated Python version 3.8.10 is not supported by the project 
(>=3.10,<3.11).
Trying to find and use a compatible version. 
Using python3 (3.10.5)

看起来它使用的是 3.10,但 py.test 使用的是 3.8.10:

platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- 
/home/runner/.cache/pypoetry/virtualenvs/vital-background-pull-yluVa_Vi-py3.10/bin/python

对于上下文,此 Github 操作之前在 3.8 上运行。我已经更新了 test.yamlpyproject.toml 中的 python 版本,但它仍在使用 3.8。我还应该更改什么以使其使用 3.10?

谢谢

最佳答案

根本原因是段

- uses: actions/setup-python@v3
  with:
    python-version: "3.10"
    cache: "poetry"

用行缓存诗歌。由于 poetry 之前安装了与 Python 3.8 关联的 pip,因此将从与该 Python 版本关联的缓存中检索包。需要重新安装新的 Python 版本。

您可以从单个 GH 操作执行中删除 cache: poetry,或者 remove the cache manually .这将解决您的问题。

关于python - 使用错误版本的 Python 的 Github 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73033594/

相关文章:

github - 如何通过 termux 应用程序将代码提交到 Android 上的 GitHub

c# - 在 Azure DevOps Repos 上拆分大型软件项目

python - 尝试 python 中 split 命令的限制 - 列表索引超出范围

python - 如何使用 seaborn displot 将直方图条围绕刻度线居中?堆叠杆是必不可少的

python - 使用 Pandas groupby 迭代和修改数据框

git - 用 git 或 hub 命令替换 GitHub UI 序列

git - Maven 发布/Github OAuth token /Jenkins : could not read Username for 'https://github.com' : No such device or address

azure - 是否可以将 azure 工件从一个管道转发到另一个管道?

powershell - Azure 管道错误 'Windows PowerShell is in NonInteractive mode.'

python路径问题: ImportError when calling zodbconvert (FreeBSD 8. 1)