在 GitLab CI YML 文件中使用 pywin32 - 在 pip 安装时出错

Using pywin32 in a GitLab CI YML file - getting error on pip install

尝试使用 GitLab 的 CI 管道 运行 一个 Python 程序。

我在 Teamcity 中有这个 运行ning,但我想在 GitLab 中尝试。

第一次尝试

我提供了一个明确的 pip install 命令列表,包括 wmi

# This file is a template, and might need editing before it works on your project.
# Official language image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/python/tags/
image: python:3.8.0

# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/reference/pip_install/#caching
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
cache:
  paths:
    - .cache/pip
    - venv/

before_script:
  - python -V  # Print out python version for debugging
  - pip install virtualenv
  - virtualenv venv
  - . venv/bin/activate

test:
  script:
  - python -m pip install --upgrade pip
  - python -m pip install locust
  - locust -V
  - python -m pip install multipledispatch
  - python -m pip install pycryptodome
  - python -m pip install pandas
  - python -m pip install wmi
  - python -m pip install pywin32==300
  - python -m pip install influxdb_client
  - set LOAD_TEST_CONF=load_test.conf
  - locust -f ./src/main.py --host http://x.x.x.x:yyyy -u 1000 -t 1m -r 250 -s 1800 --headless --csv=./LoadTestsData --csv-full-history --html=./LoadTestsReport_VPOS.html  --stream-file ./data/stream_jsons/streams_vpos.json --database=csv
   
pages:
  stage: deploy
  script:
    - mv ./LoadTests* ../public/
  artifacts:
    paths:
      - public

当我运行这个程序的时候,我得到了

ModuleNotFoundError: No module named 'win32com'

第二次尝试

所以我想我必须明确地向 pip install pywin32 添加一行。

失败

ERROR: Could not find a version that satisfies the requirement pywin32
# I tried python:latest, but I used 3.8 successfully in my IDE
image: python:3.8   

variables: ....
cache: ...

test:
  script: 
    - python -V
  - pip install virtualenv
  - virtualenv venv
  - . venv/bin/activate
  - python -m pip install --upgrade pip
  - python -m pip install locust
  - locust -V
  - python -m pip install pywin32==300      #   <----- doesn't like this
  - python -m pip install pypiwin32         #   or this
  - set LOAD_TEST_CONF=load_test.conf
  - locust -f ./src/main.py <a bunch of arguments...>

  ...

获得的结果

$ python -m pip install pywin32==300
ERROR: Could not find a version that satisfies the requirement pywin32==300 (from versions: 302)
ERROR: No matching distribution found for pywin32==300

不应该是 OS 不匹配,因为构建环境的 OS 是 Windows,正如我所见

OS/Arch:      windows/amd64

我也试了python -m pip install -r requirements.txt,结果还是一样

我该如何解决这个问题?

使用 Windows 标签的结果

Zach 的回答让我走上正轨。

除了标签 win2019 之外,我使用了与答案中完全相同的 YAML。我不是管理员;这是我发现的。

我只需要弄清楚安装问题:

虽然 python:3.8.0 图像具有可用的 windows 体系结构,但看起来它正在从该标签中提取 linux 版本。您可以通过将命令 uname -srm 添加到测试脚本的第一行来对此进行测试。

我无法在共享跑步者上获得 windows docker python 运行 图像,但我能够安装 python 3.8 在具有以下最小 .gitlab-ci.yml:

的跑步者上
test:
  before_script:
    - Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
    - choco install python3 --version=$PYTHON_VERSION --yes --force --no-progress
    - refreshenv
  script:
    - python -V
    - python -m pip install --upgrade pip
    - python -m pip install pywin32
  variables:
    PYTHON_VERSION: "3.8"
  tags:
    - windows