首页 > 解决方案 > Gitlab CI 无法从 Pipfile.lock 安装正则表达式

问题描述

我正在尝试通过 Gitlab CI 运行测试,但在设置环境时遇到问题。我正在 Windows 上开发,这就是重新生成锁定文件的原因。我尝试了各种 pipenv 命令的组合,但这一切似乎都归结为这个正则表达式问题。我确实使用 --support 转储了输出,并且我看到 Gitlab 中的正则表达式哈希与我的 Windows 版本不同,因此锁定文件确实为 3.7-slim 容器成功重新生成。

.gitlab-ci.yml(相关测试部分)

test-python3.7:
  stage: UnitTest
  image: python:3.7-slim
  timeout: 0h 10m
  script:
  - pip install pipenv
  - pipenv lock --dev
  - pipenv install --dev
  - cd src
  - pipenv run coverage run -m unittest discover && coverage report -m
  coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
  retry:
    max: 2
    when:
    - stuck_or_timeout_failure

Gitlab CI 日志:

$ pipenv lock --dev
Creating a virtualenv for this project…
Pipfile: /builds/michjnich/sudoku/Pipfile
Using /usr/local/bin/python (3.7.5) to create virtualenv…
Already using interpreter /usr/local/bin/python
Using base prefix '/usr/local'
New python executable in /root/.local/share/virtualenvs/sudoku-BhtRYaDu/bin/python
Installing setuptools, pip, wheel...
done.

Virtualenv location: /root/.local/share/virtualenvs/sudoku-BhtRYaDu
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (b2e415)!
$ pipenv install --dev
Installing dependencies from Pipfile.lock (b2e415)…
An error occurred while installing regex==2019.11.1 --hash=sha256:15454b37c5a278f46f7aa2d9339bda450c300617ca2fca6558d05d870245edc7 --hash=sha256:1ad40708c255943a227e778b022c6497c129ad614bb7a2a2f916e12e8a359ee7 --hash=sha256:5e00f65cc507d13ab4dfa92c1232d004fa202c1d43a32a13940ab8a5afe2fb96 --hash=sha256:604dc563a02a74d70ae1f55208ddc9bfb6d9f470f6d1a5054c4bd5ae58744ab1 --hash=sha256:720e34a539a76a1fedcebe4397290604cc2bdf6f81eca44adb9fb2ea071c0c69 --hash=sha256:7caf47e4a9ac6ef08cabd3442cc4ca3386db141fb3c8b2a7e202d0470028e910 --hash=sha256:7faf534c1841c09d8fefa60ccde7b9903c9b528853ecf41628689793290ca143 --hash=sha256:b4e0406d822aa4993ac45072a584d57aa4931cf8288b5455bbf30c1d59dbad59 --hash=sha256:c31eaf28c6fe75ea329add0022efeed249e37861c19681960f99bbc7db981fb2 --hash=sha256:c7393597191fc2043c744db021643549061e12abe0b3ff5c429d806de7b93b66 --hash=sha256:d2b302f8cdd82c8f48e9de749d1d17f85ce9a0f082880b9a4859f66b07037dc6 --hash=sha256:e3d8dd0ec0ea280cf89026b0898971f5750a7bd92cb62c51af5a52abd020054a --hash=sha256:ec032cbfed59bd5a4b8eab943c310acfaaa81394e14f44454ad5c9eba4f24a74! Will try again.
Installing initially failed dependencies…
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 1874, in do_install
[pipenv.exceptions.InstallError]:       keep_outdated=keep_outdated
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 1253, in do_init
[pipenv.exceptions.InstallError]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 859, in do_install_dependencies
[pipenv.exceptions.InstallError]:       retry_list, procs, failed_deps_queue, requirements_dir, **install_kwargs
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 763, in batch_install
[pipenv.exceptions.InstallError]:       _cleanup_procs(procs, not blocking, failed_deps_queue, retry=retry)
[pipenv.exceptions.InstallError]:   File "/usr/local/lib/python3.7/site-packages/pipenv/core.py", line 681, in _cleanup_procs
[pipenv.exceptions.InstallError]:       raise exceptions.InstallError(c.dep.name, extra=err_lines)
[pipenv.exceptions.InstallError]: ['Collecting regex==2019.11.1', '  Using cached https://files.pythonhosted.org/packages/fc/1d/13cc7d174cd2d05808abac3f5fb37433e30c4cd93b152d2a9c09c926d7e8/regex-2019.11.1.tar.gz', 'Building wheels for collected packages: regex', '  Building wheel for regex (setup.py): started', "  Building wheel for regex (setup.py): finished with status 'error'", '  Running setup.py clean for regex', 'Failed to build regex', 'Installing collected packages: regex', '    Running setup.py install for regex: started', "    Running setup.py install for regex: finished with status 'error'"]
[pipenv.exceptions.InstallError]: ['ERROR: Command errored out with exit status 1:', '   command: /root/.local/share/virtualenvs/sudoku-BhtRYaDu/bin/python -u -c \'import sys, setuptools, tokenize; sys.argv[0] = \'"\'"\'/tmp/pip-install-4xs4zmcl/regex/setup.py\'"\'"\'; __file__=\'"\'"\'/tmp/pip-install-4xs4zmcl/regex/setup.py\'"\'"\';f=getattr(tokenize, \'"\'"\'open\'"\'"\', open)(__file__);code=f.read().replace(\'"\'"\'\\r\\n\'"\'"\', \'"\'"\'\\n\'"\'"\');f.close();exec(compile(code, __file__, \'"\'"\'exec\'"\'"\'))\' bdist_wheel -d /tmp/pip-wheel-_y82fvl8 --python-tag cp37', '       cwd: /tmp/pip-install-4xs4zmcl/regex/', '  Complete output (19 lines):', '  running bdist_wheel', '  running build', '  running build_py', '  creating build', '  creating build/lib.linux-x86_64-3.7', '  creating build/lib.linux-x86_64-3.7/regex', '  copying regex_3/__init__.py -> build/lib.linux-x86_64-3.7/regex', '  copying regex_3/regex.py -> build/lib.linux-x86_64-3.7/regex', '  copying regex_3/_regex_core.py -> build/lib.linux-x86_64-3.7/regex', '  copying regex_3/test_regex.py -> build/lib.linux-x86_64-3.7/regex', '  warning: build_py: byte-compiling is disabled, skipping.', '  ', '  running build_ext', "  building 'regex._regex' extension", '  creating build/temp.linux-x86_64-3.7', '  creating build/temp.linux-x86_64-3.7/regex_3', '  gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/usr/local/include/python3.7m -c regex_3/_regex.c -o build/temp.linux-x86_64-3.7/regex_3/_regex.o', "  unable to execute 'gcc': No such file or directory", "  error: command 'gcc' failed with exit status 1", '  ----------------------------------------', '  ERROR: Failed building wheel for regex', '    ERROR: Command errored out with exit status 1:', '     command: /root/.local/share/virtualenvs/sudoku-BhtRYaDu/bin/python -u -c \'import sys, setuptools, tokenize; sys.argv[0] = \'"\'"\'/tmp/pip-install-4xs4zmcl/regex/setup.py\'"\'"\'; __file__=\'"\'"\'/tmp/pip-install-4xs4zmcl/regex/setup.py\'"\'"\';f=getattr(tokenize, \'"\'"\'open\'"\'"\', open)(__file__);code=f.read().replace(\'"\'"\'\\r\\n\'"\'"\', \'"\'"\'\\n\'"\'"\');f.close();exec(compile(code, __file__, \'"\'"\'exec\'"\'"\'))\' install --record /tmp/pip-record-4ggezbwt/install-record.txt --single-version-externally-managed --compile --install-headers /root/.local/share/virtualenvs/sudoku-BhtRYaDu/include/site/python3.7/regex', '         cwd: /tmp/pip-install-4xs4zmcl/regex/', '    Complete output (19 lines):', '    running install', '    running build', '    running build_py', '    creating build', '    creating build/lib.linux-x86_64-3.7', '    creating build/lib.linux-x86_64-3.7/regex', '    copying regex_3/__init__.py -> build/lib.linux-x86_64-3.7/regex', '    copying regex_3/regex.py -> build/lib.linux-x86_64-3.7/regex', '    copying regex_3/_regex_core.py -> build/lib.linux-x86_64-3.7/regex', '    copying regex_3/test_regex.py -> build/lib.linux-x86_64-3.7/regex', '    warning: build_py: byte-compiling is disabled, skipping.', '    ', '    running build_ext', "    building 'regex._regex' extension", '    creating build/temp.linux-x86_64-3.7', '    creating build/temp.linux-x86_64-3.7/regex_3', '    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/usr/local/include/python3.7m -c regex_3/_regex.c -o build/temp.linux-x86_64-3.7/regex_3/_regex.o', "    unable to execute 'gcc': No such file or directory", "    error: command 'gcc' failed with exit status 1", '    ----------------------------------------', 'ERROR: Command errored out with exit status 1: /root/.local/share/virtualenvs/sudoku-BhtRYaDu/bin/python -u -c \'import sys, setuptools, tokenize; sys.argv[0] = \'"\'"\'/tmp/pip-install-4xs4zmcl/regex/setup.py\'"\'"\'; __file__=\'"\'"\'/tmp/pip-install-4xs4zmcl/regex/setup.py\'"\'"\';f=getattr(tokenize, \'"\'"\'open\'"\'"\', open)(__file__);code=f.read().replace(\'"\'"\'\\r\\n\'"\'"\', \'"\'"\'\\n\'"\'"\');f.close();exec(compile(code, __file__, \'"\'"\'exec\'"\'"\'))\' install --record /tmp/pip-record-4ggezbwt/install-record.txt --single-version-externally-managed --compile --install-headers /root/.local/share/virtualenvs/sudoku-BhtRYaDu/include/site/python3.7/regex Check the logs for full command output.']
ERROR: ERROR: Package installation failed...
ERROR: Job failed: exit code 1

标签: python-3.xgitlab-cipipenv

解决方案


日志说gcc找不到。看起来需要构建regex.

  • 要么gcc在你的容器中安装(可能还有更多元素)以构建regex.
  • 或者,根据文件列表,选择一个已经有预构建轮子可用的 Python 解释器版本,因为目前只有 Linux 上的 Python 3.6 轮子,而不是你当前使用的 Python 3.7。regex 2019.11.1

推荐阅读