【问题标题】:git commit error: version inconsistency between python 2 and python 3.7git commit 错误:python 2 和 python 3.7 之间的版本不一致
【发布时间】:2019-05-29 17:16:29
【问题描述】:

我在我的项目中使用 Python 3.7。然后当我尝试做

edamame$ git commit --amend --no-edit

我收到以下错误(git status 工作正常):

Your PYTHONPATH points to a site-packages dir for Python 3.x but you are running Python 2.x!
     PYTHONPATH is currently: "/Users/edamame/tools/sim/scripting/:/usr/local/lib/python3.7/:/usr/local/lib/python3.7/site-packages/"
     You should `unset PYTHONPATH` to fix this.

我尝试了以下但没有运气:

edamame$ pip3 install git

Collecting git
  Could not find a version that satisfies the requirement git (from versions: )
No matching distribution found for git

所以我每次都必须像下面这样手动设置 PYTHONPATH,这非常不方便。有什么建议吗?谢谢!

edamame$ export PYTHONPATH=

【问题讨论】:

  • git commit 通常不会调用 Python。 .git/hooks 中是否启用了任何钩子,如果有,是否使用 Python?
  • 我在.git/hooks下有以下内容:commit-msg.sample post-merge pre-commit.sample pre-receive.sample .. fsmonitor-watchman.sample post-update.sample pre -push prepare-commit-msg.sample applypatch-msg.sample post-checkout pre-applypatch.sample pre-push.sample update.sample commit-msg post-commit pre-commit pre-rebase.sample 但我不确定是否他们使用 Python ...

标签: python-3.x git python-2.7 pre-commit-hook


【解决方案1】:

如果您使用的是Bash shell,您可以将export PYTHONPATH= 添加到您的~/.bashrc,然后使用以下命令重新加载~/.bashrc

$ source ~/.bashrc

这样您就不必每次手动输入export PYTHONPATH=

【讨论】:

    【解决方案2】:

    问题是您的pre-commitpost-commit 挂钩使用Python 2.7。

    您应该在编辑器中打开它们中的每一个,看看它们是否使用 Python 2.7(通过查看 shebang)、自定义版本或 /usr/bin/python/usr/bin/python2/usr/bin/python2.7 之一。如果是这样,您应该将其转换为使用带有适当 shebang 的 Python 3 或删除它(只需删除它就足够了)。

    如果它来自另一个项目或存储库,您可以尝试重新安装该项目的 Python 3 版本,这可能会安装您的钩子的 Python 3 版本。

    【讨论】:

      猜你喜欢
      • 2019-11-27
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 2016-10-28
      • 2020-05-31
      • 2022-01-07
      • 1970-01-01
      相关资源
      最近更新 更多