gitpython modules GitCommandError and Repo import error

You have installed gitpython using pip install gitypython in Mac.

And now you try importing the modules (from git.exc import GitCommandError or from git import Repo) that work with git repository, but then you run into the below error

>>> from git.exc import GitCommandError
Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/lib/python2.7/site-packages/git/__init__.py”, line 33, in
_init_externals()
File “/usr/local/lib/python2.7/site-packages/git/__init__.py”, line 27, in _init_externals
raise ImportError(“‘gitdb’ could not be found in your PYTHONPATH”)
ImportError: ‘gitdb’ could not be found in your PYTHONPATH

If you have installed python using ‘brew install python’ or ‘brew install python@2’, then it install pip for you, as well as when you did gitpython, it would have added the gitdb. It’s seems that the folder /usr/local/sbin wasn’t in my PATH ( link ), so after I added it to my .bash_profile (PATH=$PATH:/usr/local/sbin) and ran ‘source bash_profile’, I was able to import the above modules.

Hope this helps.

ebates promo.png

Leave a comment