Python安裝pygit2失敗問題及解決
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的版本太低了。
現(xiàn)在是3.6,我更新到3.9后就好了。更新命令
conda update python
python調(diào)用gitpython,遇到gitpython庫不支持的復雜命令或個性命令時的解決
需求
在執(zhí)行git log命令時,git中支持諸如:
git log --pretty=format:"%H,%an,%cd" “D:\your_target_file_path”> D:/test/log_data/log.csv
但是當我們希望通過python批量拉取自定義repo的時候
我們發(fā)現(xiàn)gitpython時,并不支持這類非常規(guī)命令(如果有知道如何使用非常規(guī)命令的小伙伴在評論區(qū)指出)
這個時候我們可以通過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)
總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
淺析Python 中的 WSGI 接口和 WSGI 服務的運行
這篇文章主要介紹了Python 中的 WSGI 接口和 WSGI 服務的相關資料,幫助大家更好的理解和使用python,感興趣的朋友可以了解下2020-12-12
pytorch MSELoss計算平均的實現(xiàn)方法
這篇文章主要介紹了pytorch MSELoss計算平均的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-05-05

