python - 包需要不同的 Python:2.7.17 not in '>=3.6.1' while setting up pre-commit
问题描述
我克隆了一个存储库,安装了 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
所有的钩子将使用这个特定的版本。如果需要覆盖任何特定的钩子,language_version:
则可以在钩子上设置此属性。
例如:-
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。对于钩子 -check-merge-conflict
它将使用 Python 2.7。
推荐阅读
- pokeapi - PokeAPI:有没有办法请求规范化数据而不是嵌套 json?
- javascript - 如何根据当前状态值使单选按钮选中/激活
- flutter - 重构问题:提取为小部件/方法/变量......有什么优点和缺点?
- python - Telegram-python-Bot 使用 callback_query 获取用户文本输入
- xamarin - 将 CarouselPage 转换为 CarouselView
- mongodb - Mongo db 4.2:将数组项的字段替换为匹配文档的另一个字段的值
- r - 在带有 tidymodels 的 r 中:警告消息:“所有模型在 [fit_resamples()] 中均失败。请参阅 `.notes` 列。” 内部:错误:在指标中:`roc_auc`
- c++ - 是否可以在 void 函数中使用 getline ?
- meteor - Meteortesting mocha 代码覆盖率错误:无法保存 json / html 报告
- java - 没有为 JDateChooser(string,string,char) 找到合适的构造函数