【问题标题】:can't install a python package & use it in a GitHub Action无法安装 python 包并在 GitHub 操作中使用它
【发布时间】:2020-03-31 02:13:11
【问题描述】:

我有一个GitHub Repo,它有一个简单的 GitHub Actions 工作流程:

name: CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Run a one-line script
      run: echo Hello, world!
    - name: Run a multi-line script
      run: |
        echo Add other actions to build,
        echo test, and deploy your project.
        pip install twine
        twine --help

当我运行它时,它安装了 twine,但是fails 运行它,说找不到命令:

...
Successfully installed Pygments-2.5.2 bleach-3.1.0 certifi-2019.11.28 chardet-3.0.4 docutils-0.15.2 idna-2.8 pkginfo-1.5.0.1 readme-renderer-24.0 requests-2.22.0 requests-toolbelt-0.9.1 setuptools-42.0.2 six-1.13.0 tqdm-4.40.0 twine-1.15.0 urllib3-1.25.7 webencodings-0.5.1
/home/runner/work/_temp/1643cb1d-8b12-4aa8-8e1d-bd5bba60fd5b.sh: line 4: twine: command not found

我怎样才能让它工作?

提前致谢。

我已经知道使用 twine 的现有 GitHub 操作,它们不符合我的要求。我也知道我可以分叉一个动作并修改它,但我真正想知道的是,如果我可以运行echo hello world,为什么我不能运行pip install some-pkg; some-pkg ...

这似乎不是路径问题。我试过用python -m twine 代替twine。我尝试运行find 命令来查找机器上名称中包含twine 的所有文件(它没有找到任何文件)。

【问题讨论】:

    标签: python pip github-actions


    【解决方案1】:

    不确定这是否能解决问题,但无论如何强烈推荐。使用官方actions/setup-python 操作来准备环境。

        steps:
        - uses: actions/checkout@v1
        - uses: actions/setup-python@v1
        - name: Run a one-line script
          run: echo Hello, world!
        - name: Run a multi-line script
          run: |
            echo Add other actions to build,
            echo test, and deploy your project.
            pip install twine
            twine --help
    

    【讨论】:

    • 我认为我们应该鼓励使用官方的setup-python 操作,因为它为不同版本的 Python 正确设置了环境,并且以多平台方式。
    【解决方案2】:

    让这个工作:

    pip install --user twine
    python -m twine --help
    

    或者不使用python -m,而是指定路径:

    ~/.local/bin/twine --help
    

    【讨论】:

      猜你喜欢
      • 2022-11-28
      • 1970-01-01
      • 2021-04-28
      • 1970-01-01
      • 2022-11-02
      • 2021-12-11
      • 2021-04-28
      • 2018-05-13
      • 2014-01-29
      相关资源
      最近更新 更多