为什么我缺少git2.h文件,如何恢复它?

11

每次我尝试设置pygit2时都会遇到奇怪的问题。以下是我运行的命令和生成的错误。

$ python3 setup.py install
running install
running build
running build_py
running build_ext
building '_pygit2' extension
/usr/bin/clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Os -w -pipe -march=native -Qunused-arguments -mmacosx-version-min=10.7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/lib -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include -I/usr/local/include -Iinclude -I/usr/local/Cellar/python3/3.2.3/include/python3.2m -c src/pygit2.c -o build/temp.macosx-10.7-x86_64-3.2/src/pygit2.o
In file included from src/pygit2.c:32:
include/pygit2/error.h:6:10: fatal error: 'git2.h' file not found
#include <git2.h>
         ^
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1

我认为我成功地安装了libgit2(构建和编译都完成得很好)。也许这是路径问题?我已经将LIBGIT2环境变量设置为libgit2文件夹中src目录下。那么这是正确的位置吗?

4个回答

5
我从未安装过 libgit2,但以下方法可能会有所帮助:
如果您的发行版存储库包含 libgit2,我建议在安装相应版本之前删除您已经编译的内容。然后从仓库中安装libgit2(二进制文件)和libgit2-dev (头文件等)软件包。这将把二进制文件和源代码放置到正确的目录下。
否则,请尝试将git2.h符号链接到/usr/local/include下。

3

以下步骤适用于我:

brew install libgit2 

2
看起来 LIBGIT2 变量没有生效(您能展示一下如何设置这个变量吗?),因为额外的 include 指令使用了默认的 /usr/local/includeLIBGIT2 环境变量需要设置成库文件所在的前缀,通常是 /usr 或者 /usr/local。看起来库文件没有安装在 /usr/local,因为编译器找不到它,所以也许你需要先运行 export LIBGIT2=/usr 再运行 setup.py

0

您必须使用 macOS。以下是我的解决方法:

brew install libgit2

如果由于“Permission denied @ dir_s_mkdir”而无法工作,只需运行以下命令即可:
 sudo chown -R $(whoiam) $(brew --prefix)/*

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接