gpt4 book ai didi

python - 设置预提交时,包需要不同的 Python : 2. 7.17 不在 '>=3.6.1' 中

转载 作者:行者123 更新时间:2023-12-03 16:35:14 27 4
gpt4 key购买 nike

我克隆了一个存储库,安装了 pre-commit 并正在提交 第一次。
这是实际安装和设置预提交包的时间。我遇到了以下问题。

[INFO] Installing environment for https://github.com/asottile/seed-isort-config.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/home/roopak/.cache/pre-commit/repokb2ckm/py_env-python2.7/bin/python', u'/home/roopak/.cache/pre-commit/repokb2ckm/py_env-python2.7/bin/pip', 'install', '.')
return code: 1
expected return code: 0
stdout:
Processing /home/roopak/.cache/pre-commit/repokb2ckm

stderr:
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
ERROR: Package 'seed-isort-config' requires a different Python: 2.7.17 not in '>=3.6.1'

最佳答案

问题是我同时安装了 Python2.7 和 3。还有我的pre-commit安装时默认使用 Python 2.7。

解决方案1:从Python2.7中移除pre-commit,添加到Python3中。

根据 pre-commit 的创建者 - @anthony-sottile - 最好将 pre-commit 与 Python3 一起使用。为此,我们必须从 Python2.7 卸载 pre-commit 并通过 Python3 安装它。

$ pip uninstall pre-commit  # uninstall from Python2.7
$ pip3 install pre-commit # install with Python3

解决方案 2:使用 Python2.7 保持预提交(不推荐)

为了解决这个问题,我使用了 default_language_version来自预提交文档。
引用: https://pre-commit.com/#overriding-language-version

通过设置 default_language_version所有的钩子(Hook)都会使用这个特定的版本。如果任何特定的钩子(Hook)需要被覆盖这个属性 - language_version: - 可以设置在钩子(Hook)上。

例如:-
default_language_version:
# force all unspecified python hooks to run python3
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
- id: trailing-whitespace
name: trim trailing whitespace
description: This hook trims trailing whitespace on files
entry: trailing-whitespace-fixer

- id: check-merge-conflict
name: check for merge conflict
description: Prevent accidentally commiting files with merge conflicts.
language_version:
python: python2.7


这个例子 .pre-commit-config.yaml文件将默认 python 版本设置为 Python 3。对于钩子(Hook) - check-merge-conflict它将使用 Python 2.7。

关于python - 设置预提交时,包需要不同的 Python : 2. 7.17 不在 '>=3.6.1' 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61863309/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com