Guy
Guy

Reputation: 820

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

Trying to run a Python program using GitLab's CI pipeline.

I had this running in Teamcity, but I wanted to try in GitLab.

First attempt

I supplied an explicit list of pip install commands including 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

enter image description here

When I ran the program, I got enter image description here

ModuleNotFoundError: No module named 'win32com'

Second attempt

So I figured I had to explicitly add a line to pip install pywin32.

That failed with

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...>

  ...

Results Obtained

$ 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

It shouldn't be an OS mismatch, since the OS of the build environment is Windows, as I see

OS/Arch:      windows/amd64

I also tried python -m pip install -r requirements.txt, but the results were the same.

How do I resolve this?

Result Using Windows Tag

Zach's answer is getting me on the right track.

I used the exact YAML as in the answer, except with a tag of win2019. I'm not the admin; this is what I found.

I just need to figure out the install problem: enter image description here

Upvotes: 3

Views: 934

Answers (1)

Zachary Yates
Zachary Yates

Reputation: 13386

While the python:3.8.0 image has a windows architecture available, it looks like it's pulling the linux version from that tag. You can test this by adding the command uname -srm to the first line of your test scripts.

I wasn't able to get a windows docker image for python running on a shared runner, but I was able to install python 3.8 on a runner with the following minimal .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

Upvotes: 2

Related Questions