当前位置: 代码网 > it编程>前端脚本>Python > Python安装pygit2失败问题及解决

Python安装pygit2失败问题及解决

2024年07月05日 Python 我要评论
python安装pygit2失败报错输出这是最后一部分输出 in file included from src/blob.c:30:0: src/blob.h:33:10: fatal error:

python安装pygit2失败

报错输出

这是最后一部分输出

  in file included from src/blob.c:30:0:
  src/blob.h:33:10: fatal error: git2.h: 没有那个文件或目录
   #include <git2.h>
            ^~~~~~~~
  compilation terminated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  error: failed building wheel for pygit2
failed to build pygit2
error: could not build wheels for pygit2 which use pep 517 and cannot be installed directly

原因

我是因为python的版本太低了。

现在是3.6,我更新到3.9后就好了。更新命令

 conda update python

python调用gitpython,遇到gitpython库不支持的复杂命令或个性命令时的解决

需求

在执行git log命令时,git中支持诸如:

git log --pretty=format:"%h,%an,%cd" “d:\your_target_file_path”> d:/test/log_data/log.csv

但是当我们希望通过python批量拉取自定义repo的时候

我们发现gitpython时,并不支持这类非常规命令(如果有知道如何使用非常规命令的小伙伴在评论区指出)

这个时候我们可以通过python+cmd的思路来解决这个问题


在这里插入图片描述

git_log.py

import subprocess

# microsoftdocs/azure-docs-sdk-python
repofullname = input(str("请输入repo:"))
repofullname_split = repofullname.split("/")
repo_file = repofullname_split[0]+"_"+repofullname_split[1]
cmd1 = "cd \\"
cmd2 = "d:"
cmd3 = "cd test"
cmd5 = "cd {}".format(repo_file)
cmd6 = "git init"
cmd8 = "git checkout -b baymax_branch"
cmd14 = """git log --pretty=format:"%h,%an,%cd" > d:/test/log_data/log_{}.csv""".format(repo_file)
cmd = cmd1 + " && " + cmd2 + " && " + cmd3 + " && " + \
      cmd5 + " && " + cmd6 + " && " + cmd8 + " && " + cmd14

subprocess.popen(cmd, shell=true)

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com