如果使用 Linux Docker 图片,我可以 运行 Python 在 GitLab CI 中使用 WMI 的应用程序吗?
Can I run Python app using WMI in GitLab CI if using Linux Docker image?
Objective
在 Gitlab 中 运行ner, 运行:
- 一些 JMeter 测试
- 一个 Python 使用 WMI 收集服务器指标的应用程序
问题
JMeter 命令运行良好,使用 alpine/jmeter
图像。
default:
image:
name: alpine/jmeter:5.4.1
entrypoint: [""]
没问题。
但我想要 运行 我编写的 Python 程序,它使用 WMI 获取 Windows 性能计数器。
问题:当执行 pip install -r requirements.txt
时,一切都已安装,但最后一部分失败:
$ pip install -r ../../requirements.txt
Collecting certifi==2021.5.30
Downloading certifi-2021.5.30-py2.py3-none-any.whl (145 kB)
Collecting cffi==1.14.5
Downloading cffi-1.14.5-cp38-cp38-manylinux1_x86_64.whl (411 kB)
Collecting chardet==4.0.0
Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
Collecting click==8.0.1
Downloading click-8.0.1-py3-none-any.whl (97 kB)
Collecting colorama==0.4.4
Downloading colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting ConfigArgParse==1.5
Downloading ConfigArgParse-1.5-py3-none-any.whl (19 kB)
Collecting crypto==1.4.1
Downloading crypto-1.4.1-py2.py3-none-any.whl (18 kB)
Collecting Flask==1.1.2
Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
Collecting Flask-BasicAuth==0.2.0
Downloading Flask-BasicAuth-0.2.0.tar.gz (16 kB)
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'done'
Collecting gevent==21.1.2
Downloading gevent-21.1.2-cp38-cp38-manylinux2010_x86_64.whl (6.3 MB)
Collecting geventhttpclient==1.4.4
Downloading geventhttpclient-1.4.4-cp38-cp38-manylinux2010_x86_64.whl (77 kB)
Collecting greenlet==1.1.0
Downloading greenlet-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (164 kB)
Collecting idna==2.10
Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting influxdb==5.3.1
Downloading influxdb-5.3.1-py2.py3-none-any.whl (77 kB)
Collecting influxdb-client==1.17.0
Downloading influxdb_client-1.17.0-py3-none-any.whl (450 kB)
Collecting itsdangerous==2.0.1
Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting Jinja2==3.0.1
Downloading Jinja2-3.0.1-py3-none-any.whl (133 kB)
Collecting locust==1.5.3
Downloading locust-1.5.3-py3-none-any.whl (765 kB)
Collecting locust-influxdb-listener==0.0.5
Downloading locust_influxdb_listener-0.0.5-py3-none-any.whl (7.6 kB)
Collecting MarkupSafe==2.0.1
Downloading MarkupSafe-2.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30 kB)
Collecting msgpack==1.0.2
Downloading msgpack-1.0.2-cp38-cp38-manylinux1_x86_64.whl (302 kB)
Collecting multipledispatch==0.6.0
Downloading multipledispatch-0.6.0-py3-none-any.whl (11 kB)
Collecting Naked==0.1.31
Downloading Naked-0.1.31-py2.py3-none-any.whl (590 kB)
Collecting numpy==1.21.2
Downloading numpy-1.21.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.8 MB)
Collecting pandas==1.3.2
Downloading pandas-1.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.5 MB)
Collecting psutil==5.8.0
Downloading psutil-5.8.0-cp38-cp38-manylinux2010_x86_64.whl (296 kB)
Collecting pycparser==2.20
Downloading pycparser-2.20-py2.py3-none-any.whl (112 kB)
Collecting pycryptodome==3.10.1
Downloading pycryptodome-3.10.1-cp35-abi3-manylinux2010_x86_64.whl (1.9 MB)
Collecting python-dateutil==2.8.1
Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Collecting pytz==2021.1
Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)
ERROR: Could not find a version that satisfies the requirement pywin32==300 (from versions: none)
ERROR: No matching distribution found for pywin32==300
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1
我试过的
用pypywin32
替换pywin32==301
确保python版本是3.8
尝试使用 python:3.8-windowsservercore,但这甚至没有成功,因为它与 Linux.[=] 的默认 JMeter 图像冲突24=]
我尝试将 pywin32==300 添加到 requirements.txt
。
结果就是
ERROR: Could not find a version that satisfies the requirement pywin32==300 (from versions: none)
ERROR: No matching distribution found for pywin32==300
default:
image:
name: alpine/jmeter:5.4.1
entrypoint: [""]
api test:
image:
name: python:3.8
stage: test
script:
- |
git --version
set -e
cd ../..
- rm -rf engine-load-tests
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.company.net/qa/engine-automation/engine-load-tests.git
- cd engine-load-tests/src/win_perf_counters/
- PYTHONPATH=`pwd`./:$PYTHONPATH
- python3 -m venv .venv
- source .venv/bin/activate
- python -V
- pip install --upgrade pip
- pip install -r ../../requirements.txt
- python ./main.py ../../load_test.conf csv
我是不是在尝试做一些不可能的事情?
知道如何让 Python 申请到 运行 吗?
不,wmi
包依赖于 pywin32
,它只能在 Windows 上使用,因为它依赖于 Windows 二进制文件(windows DLL 文件)只能是 运行 on Windows.
因此,您必须在 Windows 上 运行 这个 Python 应用程序,而不是 Linux。
然而,Jmeter 确实适用于 Windows 和 Linux。
Objective
在 Gitlab 中 运行ner, 运行:
- 一些 JMeter 测试
- 一个 Python 使用 WMI 收集服务器指标的应用程序
问题
JMeter 命令运行良好,使用 alpine/jmeter
图像。
default:
image:
name: alpine/jmeter:5.4.1
entrypoint: [""]
没问题。
但我想要 运行 我编写的 Python 程序,它使用 WMI 获取 Windows 性能计数器。
问题:当执行 pip install -r requirements.txt
时,一切都已安装,但最后一部分失败:
$ pip install -r ../../requirements.txt
Collecting certifi==2021.5.30
Downloading certifi-2021.5.30-py2.py3-none-any.whl (145 kB)
Collecting cffi==1.14.5
Downloading cffi-1.14.5-cp38-cp38-manylinux1_x86_64.whl (411 kB)
Collecting chardet==4.0.0
Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
Collecting click==8.0.1
Downloading click-8.0.1-py3-none-any.whl (97 kB)
Collecting colorama==0.4.4
Downloading colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting ConfigArgParse==1.5
Downloading ConfigArgParse-1.5-py3-none-any.whl (19 kB)
Collecting crypto==1.4.1
Downloading crypto-1.4.1-py2.py3-none-any.whl (18 kB)
Collecting Flask==1.1.2
Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
Collecting Flask-BasicAuth==0.2.0
Downloading Flask-BasicAuth-0.2.0.tar.gz (16 kB)
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'done'
Collecting gevent==21.1.2
Downloading gevent-21.1.2-cp38-cp38-manylinux2010_x86_64.whl (6.3 MB)
Collecting geventhttpclient==1.4.4
Downloading geventhttpclient-1.4.4-cp38-cp38-manylinux2010_x86_64.whl (77 kB)
Collecting greenlet==1.1.0
Downloading greenlet-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (164 kB)
Collecting idna==2.10
Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting influxdb==5.3.1
Downloading influxdb-5.3.1-py2.py3-none-any.whl (77 kB)
Collecting influxdb-client==1.17.0
Downloading influxdb_client-1.17.0-py3-none-any.whl (450 kB)
Collecting itsdangerous==2.0.1
Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting Jinja2==3.0.1
Downloading Jinja2-3.0.1-py3-none-any.whl (133 kB)
Collecting locust==1.5.3
Downloading locust-1.5.3-py3-none-any.whl (765 kB)
Collecting locust-influxdb-listener==0.0.5
Downloading locust_influxdb_listener-0.0.5-py3-none-any.whl (7.6 kB)
Collecting MarkupSafe==2.0.1
Downloading MarkupSafe-2.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30 kB)
Collecting msgpack==1.0.2
Downloading msgpack-1.0.2-cp38-cp38-manylinux1_x86_64.whl (302 kB)
Collecting multipledispatch==0.6.0
Downloading multipledispatch-0.6.0-py3-none-any.whl (11 kB)
Collecting Naked==0.1.31
Downloading Naked-0.1.31-py2.py3-none-any.whl (590 kB)
Collecting numpy==1.21.2
Downloading numpy-1.21.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.8 MB)
Collecting pandas==1.3.2
Downloading pandas-1.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.5 MB)
Collecting psutil==5.8.0
Downloading psutil-5.8.0-cp38-cp38-manylinux2010_x86_64.whl (296 kB)
Collecting pycparser==2.20
Downloading pycparser-2.20-py2.py3-none-any.whl (112 kB)
Collecting pycryptodome==3.10.1
Downloading pycryptodome-3.10.1-cp35-abi3-manylinux2010_x86_64.whl (1.9 MB)
Collecting python-dateutil==2.8.1
Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Collecting pytz==2021.1
Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)
ERROR: Could not find a version that satisfies the requirement pywin32==300 (from versions: none)
ERROR: No matching distribution found for pywin32==300
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1
我试过的
用
替换pypywin32
pywin32==301
确保python版本是3.8
尝试使用 python:3.8-windowsservercore,但这甚至没有成功,因为它与 Linux.[=] 的默认 JMeter 图像冲突24=]
我尝试将 pywin32==300 添加到
requirements.txt
。 结果就是ERROR: Could not find a version that satisfies the requirement pywin32==300 (from versions: none) ERROR: No matching distribution found for pywin32==300
default:
image:
name: alpine/jmeter:5.4.1
entrypoint: [""]
api test:
image:
name: python:3.8
stage: test
script:
- |
git --version
set -e
cd ../..
- rm -rf engine-load-tests
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.company.net/qa/engine-automation/engine-load-tests.git
- cd engine-load-tests/src/win_perf_counters/
- PYTHONPATH=`pwd`./:$PYTHONPATH
- python3 -m venv .venv
- source .venv/bin/activate
- python -V
- pip install --upgrade pip
- pip install -r ../../requirements.txt
- python ./main.py ../../load_test.conf csv
我是不是在尝试做一些不可能的事情?
知道如何让 Python 申请到 运行 吗?
不,wmi
包依赖于 pywin32
,它只能在 Windows 上使用,因为它依赖于 Windows 二进制文件(windows DLL 文件)只能是 运行 on Windows.
因此,您必须在 Windows 上 运行 这个 Python 应用程序,而不是 Linux。
然而,Jmeter 确实适用于 Windows 和 Linux。