我有以下 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.yaml
和 pyproject.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/