Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to import git in python

I am facing these issues. Can you help me with the same ? Why am I seeing this error ? Do I have to add anything in the requirements.txt file ?

>>> import git
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
 import git
File "git\__init__.py", line 29, in <module>
_init_externals()
File "git\__init__.py", line 23, in _init_externals
raise ImportError("'gitdb' could not be found in your PYTHONPATH")
ImportError: 'gitdb' could not be found in your PYTHONPATH

>>> from git import Repo
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
from git import Repo
File "git\__init__.py", line 29, in <module>
_init_externals()
File "git\__init__.py", line 23, in _init_externals
raise ImportError("'gitdb' could not be found in your PYTHONPATH")
ImportError: 'gitdb' could not be found in your PYTHONPATH
like image 853
Bharath Kashyap Avatar asked Feb 16 '15 07:02

Bharath Kashyap


4 Answers

I already had gitdb and smmap installed so I had to reinstall them.

You can reinstall them by running the following command in your terminal:

pip3 install --upgrade --force-reinstall gitdb; pip3 install --upgrade --force-reinstall smmap
like image 100
Josh Correia Avatar answered Nov 02 '22 02:11

Josh Correia


I also got the message ImportError: 'gitdb' could not be found in your PYTHONPATH (when trying to use GitPython).
BUT I had gitdb already installed!
Thanks to this hint I figured out that gitdb silently failed because it was missing smmap.
So I installed this and it worked.

like image 40
Roman Avatar answered Nov 02 '22 02:11

Roman


You need to install gitdb package.

$ sudo easy_install gitdb
like image 3
Ozgur Vatansever Avatar answered Nov 02 '22 03:11

Ozgur Vatansever


I had the same problem. However, gitdb and smmap were already installed by pip. As I used brew to install python and its dependencies on my mac, when I checked brew doctor command, it said that my /usr/local/sbin directory is not in my PATH. So I added it to my PATH (though it didn't have anything to do with the python) and everything worked out eventually.

like image 2
Amytis Avatar answered Nov 02 '22 02:11

Amytis