..
在 docker build 的时候使用 pip 安装依赖报错,但是换个机器就没问题
研发反馈,在 CI 流程中,打包镜像的时候,使用 pip 安装依赖报错,但是在自己的服务器就没问题,报错信息如下:
2024-11-11 16:43:31 [91mERROR: Exception:
2024-11-11 16:43:31 Traceback (most recent call last):
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 180, in exc_logging_wrapper
2024-11-11 16:43:31 status = run_func(*args)
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 245, in wrapper
2024-11-11 16:43:31 return func(self, options, args)
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 377, in run
2024-11-11 16:43:31 requirement_set = resolver.resolve(
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 95, in resolve
2024-11-11 16:43:31 result = self._result = resolver.resolve(
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 546, in resolve
2024-11-11 16:43:31 state = resolution.resolve(requirements, max_rounds=max_rounds)
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 397, in resolve
2024-11-11 16:43:31 self._add_to_criteria(self.state.criteria, r, parent=None)
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 173, in _add_to_criteria
2024-11-11 16:43:31 if not criterion.candidates:
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/resolvelib/structs.py", line 156, in __bool__
2024-11-11 16:43:31 return bool(self._sequence)
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 155, in __bool__
2024-11-11 16:43:31 return any(self)
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 143, in <genexpr>
2024-11-11 16:43:31 return (c for c in iterator if id(c) not in self._incompatible_ids)
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 97, in _iter_built_with_inserted
2024-11-11 16:43:31 candidate = func()
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 182, in _make_candidate_from_link
2024-11-11 16:43:31 base: Optional[BaseCandidate] = self._make_base_candidate_from_link(
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 228, in _make_base_candidate_from_link
2024-11-11 16:43:31 self._link_candidate_cache[link] = LinkCandidate(
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 290, in __init__
2024-11-11 16:43:31 super().__init__(
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 156, in __init__
2024-11-11 16:43:31 self.dist = self._prepare()
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 222, in _prepare
2024-11-11 16:43:31 dist = self._prepare_distribution()
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 301, in _prepare_distribution
2024-11-11 16:43:31 return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 525, in prepare_linked_requirement
2024-11-11 16:43:31 return self._prepare_linked_requirement(req, parallel_builds)
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 596, in _prepare_linked_requirement
2024-11-11 16:43:31 local_file = unpack_url(
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 168, in unpack_url
2024-11-11 16:43:31 file = get_http_url(
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 109, in get_http_url
2024-11-11 16:43:31 from_path, content_type = download(link, temp_dir.path)
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/network/download.py", line 147, in __call__
2024-11-11 16:43:31 for chunk in chunks:
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_internal/cli/progress_bars.py", line 52, in _rich_progress_bar
2024-11-11 16:43:31 with progress:
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/rich/progress.py", line 1169, in __enter__
2024-11-11 16:43:31 self.start()
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/rich/progress.py", line 1160, in start
2024-11-11 16:43:31 self.live.start(refresh=True)
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/rich/live.py", line 132, in start
2024-11-11 16:43:31 self._refresh_thread.start()
2024-11-11 16:43:31 File "/opt/conda/lib/python3.10/threading.py", line 935, in start
2024-11-11 16:43:31 _start_new_thread(self._bootstrap, ())
2024-11-11 16:43:31 RuntimeError: can't start new thread
2024-11-11 16:43:32 [0mThe command '/bin/sh -c python3 -m pip install --upgrade pip' returned a non-zero code: 2
从上面日志可以看出是 rich 这个库报错的,rich 这个库的功能在安装依赖的过程中展示漂亮的日志,我们可以通过关闭 pip 的日志来规避这个问题。
pip install <package> -q
添加一个 -q 参数,关闭日志,问题就解决了。