On linux 20.04, I want to import the git module (gitpython) in python, but the program seems to treat git as a git module. I also want to import pydriller module in python too, this also depends on the git module (gitpython).
The git version and the gitpython version are as follows:
(collect_vul_patch) xinguo@amax-vlis5:~/vulnerability_data/0-code$ **git version**
**git version 2.25.1**
(collect_vul_patch) xinguo@amax-vlis5:~/vulnerability_data/0-code$ **pip3 show gitpython**
**Name: GitPython
Version: 3.1.18**
Summary: Python Git Library
Home-page: https://github.com/gitpython-developers/GitPython
Author: Sebastian Thiel, Michael Trier
Author-email: [email protected], [email protected]
License: BSD
Location: /data0/xinguo/anaconda3/envs/collect_vul_patch/lib/python3.6/site-packages
Requires: typing-extensions, gitdb
Required-by: PyDriller
The error is as follows:
Traceback (most recent call last):
File "test.py", line 3, in <module>
print(os.environ["GIT_PYTHON_REFRESH"])
File "/data0/xinguo/anaconda3/envs/collect_vul_patch/lib/python3.6/os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'GIT_PYTHON_REFRESH'
(collect_vul_patch) xinguo@amax-vlis5:~/vulnerability_data/0-code$ python test.py
Traceback (most recent call last):
File "/data0/xinguo/anaconda3/envs/collect_vul_patch/lib/python3.6/site-packages/git/__init__.py", line 87, in <module>
refresh()
File "/data0/xinguo/anaconda3/envs/collect_vul_patch/lib/python3.6/site-packages/git/__init__.py", line 76, in refresh
if not Git.refresh(path=path):
File "/data0/xinguo/anaconda3/envs/collect_vul_patch/lib/python3.6/site-packages/git/cmd.py", line 243, in refresh
cls().version()
File "/data0/xinguo/anaconda3/envs/collect_vul_patch/lib/python3.6/site-packages/git/cmd.py", line 585, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "/data0/xinguo/anaconda3/envs/collect_vul_patch/lib/python3.6/site-packages/git/cmd.py", line 1124, in _call_process
return self.execute(call, **exec_kwargs)
File "/data0/xinguo/anaconda3/envs/collect_vul_patch/lib/python3.6/site-packages/git/cmd.py", line 928, in execute
raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(255)
cmdline: git version
stdout: 'git version 2.25.1'
The above exception was the direct cause of the following exception:
**Traceback (most recent call last):
File "test.py", line 5, in <module>
import git
File "/data0/xinguo/anaconda3/envs/collect_vul_patch/lib/python3.6/site-packages/git/__init__.py", line 89, in <module>
raise ImportError('Failed to initialize: {0}'.format(exc)) from exc
ImportError: Failed to initialize: Cmd('git') failed due to: exit code(255)
cmdline: git version
stdout: 'git version 2.25.1'**
How should I fix this problem to make python can import git module success?