为什么Travis CI在构建Python项目时失败?

3

我有一个简单的 Python 脚本,使用微软的 API ( Pywin32 )。在我的本地机器上能够成功运行该程序,但在 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!

1
我相信Travis默认运行Linux,因此没有Win API。您尝试在.travis.yml中添加“os:windows”了吗?请参见https://blog.travis-ci.com/2018-10-11-windows-early-release - The Godfather
是的,我尝试过了,但不幸的是,Windows操作系统不支持Python。 - Boudhayan Dev
1个回答

4

pywin32是WinAPI包装器,所以它只能在Windows上使用,不能在Linux上使用。

Travis CI默认在Linux上运行,但自2018年10月以来,通过在.travis.yml文件中添加os: windows的方式可以使用Windows。请查看Travis博客文章了解更多信息。

然而,由于这是“早期版本”功能,因此仍然缺少很多功能,包括Python支持。因此,如果您现在需要Python,则唯一的方法是手动安装,例如:这里

更新示例(2020年4月)使用Python 3.8,似乎现在已成为默认:

- 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

谢谢。我会尝试一下的。 - Boudhayan Dev
更新了问题。 - Boudhayan Dev
更新后的输出仍然像Linux输出。无论如何,您必须拥有os:windows - The Godfather
没有变化。看起来 Python 根本不受支持。更新(编辑2) - Boudhayan Dev
@BoudhayanDev 请仔细阅读最后一个链接的内容。已经有成功使用它的项目了。你不应该使用 language: python,因为它不受支持,你必须自己安装所需的一切。 - The Godfather
请注意,现在路径为 /c/Python38 - HitLuca

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接