简体   繁体   English

使用 Python3 将 meld 设置为 git 合并工具

[英]Setting meld as git mergetool with Python3

I've tried setting meld as my mergetool to use with git doing:我尝试将 meld 设置为与 git 一起使用的合并工具:

git config --global merge.tool meld
git config --global mergetool.meld.path c:/Progra~2/meld/bin/meld

As outlined in answers to questions like:如对以下问题的回答中所述:

How to set Meld as git mergetool 如何将 Meld 设置为 git 合并工具

I used to have this working on my old work machine but now on my new machine where I have Python3 installed instead of 2.7 I am getting the following error whenever I try git mergetool:我曾经在我的旧工作机器上运行这个,但现在在我安装了 Python3 而不是 2.7 的新机器上,每当我尝试 git 合并工具时,我都会收到以下错误:

C:/Program Files/Git/mingw64/libexec/git-core/mergetools/meld: c:/Progra~2/Meld/bin/meld: C:/msys64/MINGW32/bin/python3.exe: bad interpreter: No such file or directory C:/Program Files/Git/mingw64/libexec/git-core/mergetools/meld: c:/Progra~2/Meld/bin/meld: C:/msys64/MINGW32/bin/python3.exe: bad interpreter: No这样的文件或目录

Any ideas what extra steps I need to make to get this to work with Python3?任何想法我需要采取哪些额外步骤才能使其与 Python3 一起使用?

EDIT: I have tried pointing directly to Meld.exe too but that causes the following crash:编辑:我也尝试过直接指向 Meld.exe 但这会导致以下崩溃:

在此处输入图像描述

The .../bin/meld script is mostly there for reference. .../bin/meld脚本主要供参考。 You should set你应该设置

git config mergetool.meld.path "C:/Program Files (x86)/Meld/Meld.exe"

You don't need to use Progra~2 notation unless you really want to for some reason.你不需要使用Progra~2表示法,除非你真的出于某种原因想要这样做。

The only issue that I am having is that it is not properly picking up the installed dependency extensions in C:/Program Files (x86)/Meld/lib .我遇到的唯一问题是它没有正确选择C:/Program Files (x86)/Meld/lib中安装的依赖扩展。 You need to add C:/Program Files (x86)/Meld/lib to your PATH environment variable, either with SET PATH=C:/Program Files (x86)/Meld/lib;%PATH% , or through the "Edit Environment Variables for your account" somewhere in control panel/start menu.您需要使用SET PATH=C:/Program Files (x86)/Meld/lib;%PATH%或通过“编辑环境”将C:/Program Files (x86)/Meld/libPATH环境变量中您帐户的变量”在控制面板/开始菜单的某处。

Alternative Approach替代方法

If you open C:\Program Files (x86)\Meld\bin\meld in a text editor, you will see that it is a shell script that is intended to be run in python3 (called from C:\Program Files\Git\bin\sh.exe most likely). If you open C:\Program Files (x86)\Meld\bin\meld in a text editor, you will see that it is a shell script that is intended to be run in python3 (called from C:\Program Files\Git\bin\sh.exe最有可能)。

The first line of meld reads: meld的第一行是:

#!C:/msys64/MINGW32/bin/python3.exe

This issue does not pop up when using Meld.exe because it does not use the script through a python interpreter.使用Meld.exe时不会弹出此问题,因为它不通过 python 解释器使用脚本。

It is unlikely that the python interpreter is installed at that location on your machine. python 解释器不太可能安装在您机器上的该位置。 Instead, you can replace the shebang line to point to an existing interpreter.相反,您可以替换 shebang 行以指向现有的解释器。 For example, on my machine, meld starts with:例如,在我的机器上, meld以:

#!C:/Users/MadPhysicist/AppData/Local/Continuum/anaconda3/python.exe

This still won't be enough for the script to find the meld package and all the installed GTK, cairo, etc. DLLs, so you have to tweak both the python and system paths.这仍然不足以让脚本找到meld package 和所有已安装的 GTK、cairo 等 DLL,因此您必须同时调整 Z23EEEB4347BDD26BFC6B7EE9A3B7 系统路径和系统路径Insert the following before the line import meld # noqua: E402 (line ~78):import meld # noqua: E402 (line ~78) 行之前插入以下内容:

os.environ['PATH'] = os.pathsep.join((melddir, os.path.join(melddir, 'lib'), os.environ['PATH']))
sys.path[0:0] = [os.path.join(melddir, 'lib/python3.7/site-packages')]

I was not ever able to get the first line to set up Cairo, GTK, etc. correctly for meld .我无法获得第一条线来正确设置 Cairo、 meld等。 You can, however, skip the first line and just install the packages using conda or pip.但是,您可以跳过第一行,直接使用 conda 或 pip 安装软件包。 You will still need to insert the meld package into sys.path .您仍然需要将融合 package 插入sys.path

Keep in mind that meld is compiled in 32 bits, as evidenced by the x86 in the install folder.请记住, x86 meld证明。 You can only run it with a 32-bit python interpreter if you use the included DLLs, which may require additional installation.如果您使用包含的 DLL,则只能使用 32 位 python 解释器运行它,这可能需要额外安装。 You do not need a 32-bit interpreter if your environment contains all the necessary packages already.如果您的环境已经包含所有必需的包,则不需要 32 位解释器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM