ImportError: No module named git after reformatting laptop
Asked Answered
F

5

29

My laptop has been formatted and a new OS was installed, and since then I have gotten this error:

ImportError: No module named git

This refers to a Python code that simply imports git.

Location of git before my laptop was formatted: /usr/local/bin/git Location of git after the laptop was formatted: /usr/bin/git

How / what do I change in my Python code to refer to the right path?

Freemason answered 12/2, 2015 at 16:54 Comment(1)
The git command line option is not a Python module. You'll need to install that separately.Ensnare
E
65

The git module is not the same thing as the git command line executable. They happen to have the same name and cover related tasks, but they are distinct software packages.

I'm going to assume that the git module your code is importing is the one provided by the GitPython project. You'll need to install that project, see their installation instructions:

# pip install gitpython
Ensnare answered 12/2, 2015 at 16:57 Comment(0)
H
7

In my cas, I installed pythong2-git, it solved my problem.

sudo apt-get install python3-git
Highcolored answered 15/7, 2018 at 14:37 Comment(0)
S
6

In my case, running apt install python-git in Terminal/CLI fixed the issue.

Speleology answered 7/10, 2019 at 14:9 Comment(0)
S
1

You can try this.

GitPython’s git repo is available on GitHub, which can be browsed at:

https://github.com/gitpython-developers/GitPython and cloned using:

$ git clone https://github.com/gitpython-developers/GitPython git-python

Initialize all submodules to obtain the required dependencies with:

$ cd git-python
$ git submodule update --init --recursive
Seacoast answered 24/2, 2020 at 7:16 Comment(0)
A
0

In Centos7 (might also work in Redhat System), if you are using Python2.7 :

sudo yum install epel-release

sudo yum install python-pip

sudo yum install GitPython.noarch

The above command is to install gitpython in Python2

Amagasaki answered 17/8, 2021 at 13:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.