【问题标题】:Why does Travis CI fails to build Python project?为什么 Travis CI 无法构建 Python 项目?
【发布时间】:2019-05-10 01:29:27
【问题描述】:

我有一个使用 Microsoft 的 API ( Pywin32 ) 的简单 Python 脚本。我能够在我的本地机器上成功运行该项目,但在 Travis 中,它会引发错误 -

    100% |████████████████████████████████| 51kB 17.9MB/s 
Collecting pylint==2.2.2 (from -r requirements.txt (line 15))
  Downloading https://files.pythonhosted.org/packages/a5/06/ecef826f319055e6b231716730d7f9047dd7524ffda224b521d989f085b6/pylint-2.2.2-py3-none-any.whl (750kB)
    100% |████████████████████████████████| 757kB 18.9MB/s 
Collecting pywin32==224 (from -r requirements.txt (line 16))
  Could not find a version that satisfies the requirement pywin32==224 (from -r requirements.txt (line 16)) (from versions: )
No matching distribution found for pywin32==224 (from -r requirements.txt (line 16))
The command "pip install -r requirements.txt" failed and exited with 1 during .
Your build has been stopped.

在我的本地系统中,Python 版本是 3.6.6 而 pip 是 18.1 。但是,如果您在 Travis 中注意到,pip 版本是 10.0.1 。这可能是问题吗?

我的 travis.yml 文件包含 -

language: python
python:
  - "3.6.6"
pip:
  - "18.1"
install:
  - pip install -r requirements.txt
script:
  - python main.py

Python 包 pywin32==224 存在并且可以在我的本地机器上下载,所以我猜错误不是来自他们这边。

感谢您的帮助。

编辑 -

尝试安装 Python 后,出现以下错误:

0.01s$ source ~/virtualenv/python3.6/bin/activate
$ python --version
Python 3.6.3
$ pip --version
pip 9.0.1 from /home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages (python 3.6)
0.08s$ choco install python3
choco: command not found
The command "choco install python3" failed and exited with 127 during .
Your build has been stopped.

编辑 2 -

新的 .travis.yml :

language: python
python:
  - "3.6"
os: windows
before_install:
        - choco install python3
        - export PATH="/c/Python37:/c/Python37/Scripts:$PATH"
        - python -m pip install --upgrade pip wheel
install:
  - pip install -r requirements.txt
script:
  - python main.py 

输出 -

Worker information

The language 'python' is currently unsupported on the Windows Build Environment.
Let us know if you'd like to see it: https://travis-ci.community/c/environments/windows. Thanks for understanding!

【问题讨论】:

标签: python python-3.x pip continuous-integration travis-ci


【解决方案1】:

pywin32 是 WinAPI 包装器,因此它是仅限 Windows 的包,您不能在 Linux 上使用它。

Travis CI 默认在 Linux 上运行,但自 2018 年 10 月起,可以通过在 .travis.yml 文件中添加 os: windows 来使用 Windows。在此查看Travis blog post。

但是,由于它是“抢先体验”功能,它仍然遗漏了很多东西,包括 Python support。因此,如果您现在需要 Python - 唯一的方法是手动安装它,即像 here

使用 Python 3.8 更新示例(2020 年 4 月),现在似乎是默认设置:

- os: windows
  language: sh
  python: "3.8"
  before_install:
        - choco install python3
        - export PATH="/c/Python38:/c/Python38/Scripts:$PATH"
        - python -m pip install --upgrade pip wheel

【讨论】:

  • 谢谢。我试试看。
  • 更新了问题。
  • 更新后的输出看起来仍然像 Linux 输出。无论如何,您必须拥有os: windows。
  • 不,没有变化。似乎根本不支持 Python。更新(编辑 2)
  • @BoudhayanDev 请仔细阅读最后一个链接的内容。已经有项目成功使用它。你不应该使用language: python,因为它不受支持,你必须自己安装你需要的一切
猜你喜欢
  • 2016-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-09
相关资源
最近更新 更多