无法安装python软件包并在GitHub Action中使用它

时间:2019-12-06 04:59:28

标签: python pip github-actions

我有一个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

当我运行它时,它会安装麻线,但是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

如何使它正常工作?

先谢谢了。

我已经知道使用麻线的现有GitHub动作,它们无法满足我的要求。我也知道我可以派生一个动作并对其进行修改,但是我真正想知道的是,如果我可以运行echo hello world,为什么我不能运行pip install some-pkg; some-pkg ...

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

让它起作用:

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

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

~/.local/bin/twine --help