Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing pygit2/libgit2 in Python virtualenv on a Mac

I think I'm about to lose my mind. I'm trying to simply install pygit2 in my python virtualenv on my macbook air so I can get to work. However this is not budging and I have been trying to set it up all day.

I'm supposed follow these instructions :

http://www.pygit2.org/install.html#how-to-install

I have tried countless amounts of things, messing around with the rpath because apparently on macs this is implemented differently :

How to set the runtime path (-rpath) of an executable with gcc under Mac OSX?

... and a countless amount of other variations, I'm just guessing at this point, however each time I try to build pygit2 it always leads to this result :

(testenv)emil ~/sites/env/testenv/pygit2 > which python
/Users/emil/Sites/env/testenv/bin/python
(testenv)emil ~/sites/env/testenv/pygit2 > python -c 'import pygit2'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "pygit2/__init__.py", line 32, in <module>
    import _pygit2
ImportError: dlopen(/Users/emil/sites/env/testenv/lib/python2.7/site-packages/_pygit2.so, 2): Symbol not found: _git_remote_fetchspec
  Referenced from: /Users/emil/sites/env/testenv/lib/python2.7/site-packages/_pygit2.so
  Expected in: flat namespace
 in /Users/emil/sites/env/testenv/lib/python2.7/site-packages/_pygit2.so

It doesn't seem to be linking the libraries properly :

(testenv)emil ~/sites/env/testenv/pygit2 > nm /Users/emil/sites/env/testenv/lib/python2.7/site-packages/_pygit2.so | grep _git | less

000000000000626c T _Repository_git_object_lookup_prefix
0000000000011288 d _Repository_git_object_lookup_prefix__doc__
                 U _git_blob_create_frombuffer
                 U _git_blob_create_fromdisk
                 U _git_blob_create_fromworkdir
                 U _git_blob_rawsize
                 U _git_checkout_head
                 U _git_checkout_index
                 U _git_checkout_tree
                 U _git_commit_author
                 U _git_commit_committer
                 U _git_commit_create
                 U _git_commit_free
                 U _git_commit_lookup
                 U _git_commit_lookup_prefix
                 ...

When I try to use pip it says :

(testenv)emil ~/sites/env/testenv/pygit2 > pip install pygit2
Requirement already satisfied (use --upgrade to upgrade): pygit2 in /Users/emil/sites/env/testenv/lib/python2.7/site-packages
Cleaning up...
(testenv)emil ~/sites/env/testenv/pygit2 > pip install pygit2 --upgrade
Requirement already up-to-date: pygit2 in /Users/emil/sites/env/testenv/lib/python2.7/site-packages
Cleaning up...

If someone has set this up before I would appreciate any help, otherwise I will use this to document the issue and organize my thoughts and hopefully record a solution.

like image 995
Emil Davtyan Avatar asked Sep 20 '26 12:09

Emil Davtyan


1 Answers

The instructions on pygit2's site seem a bit misleading. Their default branch (master) binds targets libgit2's master branch (i.e. latest release, at this time 0.18.0), but libgit2's default branch is development. The meaning of "latest" on the site isn't clear.

The function the linker can't find has been removed since the last release, so it looks like you're simply building against the wrong libgit2 version. Use libgit2's master branch or its v0.18.0 tag and you should be fine.

like image 200
Carlos Martín Nieto Avatar answered Sep 22 '26 01:09

Carlos Martín Nieto