22Installation
33**********************************************************************
44
5- .. |lq | unicode :: U+00AB
6- .. |rq | unicode :: U+00BB
7-
8-
95.. contents :: Contents
106 :local:
117
@@ -17,8 +13,8 @@ Install pygit2:
1713
1814.. code-block :: sh
1915
20- $ pip install -U pip
21- $ pip install pygit2
16+ pip install -U pip
17+ pip install pygit2
2218
2319 The line above will install binary wheels if available in your platform.
2420
@@ -33,12 +29,12 @@ If you get the error::
3329 fatal error: git2.h: No such file or directory
3430
3531It means that pip did not find a binary wheel for your platform, so it tried to
36- build from source, but it failed because it could not find the libgit2 headers.
32+ build from source. It failed to build because it could not find the libgit2 headers.
3733Then:
3834
3935- Verify pip is updated
4036- Verify there is a binary wheel of pygit2 for your platform
41- - Otherwise install from the source distribution
37+ - Otherwise ` install from the source distribution `_
4238
4339Caveats:
4440
@@ -58,12 +54,12 @@ Python requirements (these are specified in ``setup.py``):
5854- cffi 2.0 or later
5955
6056Libgit2 **v1.9.x **; binary wheels already include libgit2, so you only need to
61- worry about this if you install the source package .
57+ worry about this if you ` install from the source distribution `_ .
6258
6359Optional libgit2 dependencies to support ssh and https:
6460
6561- https: WinHTTP (Windows), SecureTransport (OS X) or OpenSSL.
66- - ssh: libssh2 1.9.0 or later, pkg-config
62+ - ssh: libssh2 1.9.1 or later, pkg-config
6763
6864To run the tests:
6965
@@ -72,8 +68,9 @@ To run the tests:
7268Version numbers
7369===============
7470
75- The version number of pygit2 is composed of three numbers separated by dots
76- |lq | *major.medium.minor * |rq |:
71+ The version number of pygit2 is composed of three numbers separated by dots::
72+
73+ <major>.<medium>.<minor>
7774
7875- *major * will always be 1 (until we release 2.0 in a far undefined future)
7976- *medium * will increase whenever we make breaking changes, or upgrade to new
@@ -86,6 +83,8 @@ of Python and the required libgit2 version.
8683+-------------+----------------+------------+
8784| pygit2 | Python | libgit2 |
8885+-------------+----------------+------------+
86+ | 1.19 | 3.10 - 3.14(t) | 1.9 |
87+ +-------------+----------------+------------+
8988| 1.17 - 1.18 | 3.10 - 3.13 | 1.9 |
9089+-------------+----------------+------------+
9190| 1.16 | 3.10 - 3.13 | 1.8 |
@@ -139,33 +138,41 @@ lockstep with libgit2, e.g. pygit2 0.28.x worked with libgit2 0.28.x
139138Advanced
140139===========================
141140
141+ .. _install from the source distribution :
142+
142143Install libgit2 from source
143144---------------------------
144145
146+ Installing from source requires
147+
148+ * a C compiler (such as gcc)
149+ * the CPython API headers (typically in a ``apt `` package named ``python3-dev ``)
150+
145151To install the latest version of libgit2 system wide, in the ``/usr/local ``
146152directory, do:
147153
148154.. code-block :: sh
155+ :caption: On Linux using bash
149156
150- $ wget https://github.com/libgit2/libgit2/archive/refs/tags/v1.9.0 .tar.gz -O libgit2-1.9.0 .tar.gz
151- $ tar xzf libgit2-1.9.0 .tar.gz
152- $ cd libgit2-1.9.0 /
153- $ cmake .
154- $ make
155- $ sudo make install
157+ wget https://github.com/libgit2/libgit2/archive/refs/tags/v1.9.1 .tar.gz -O libgit2-1.9.1 .tar.gz
158+ tar - xzf libgit2-1.9.1 .tar.gz
159+ cd libgit2-1.9.1 /
160+ cmake .
161+ make
162+ sudo make install
156163
157164 .. seealso ::
158165
159166 For detailed instructions on building libgit2 check
160- https://libgit2.github.com /docs/guides/build-and-link/
167+ https://libgit2.org /docs/guides/build-and-link/
161168
162169Now install pygit2, and then verify it is correctly installed:
163170
164171.. code-block :: sh
165172
166- $ pip install pygit2
167- ...
168- $ python -c ' import pygit2'
173+ pip install pygit2
174+ # ...
175+ python -c ' import pygit2'
169176
170177
171178 Troubleshooting
@@ -174,9 +181,9 @@ Troubleshooting
174181The verification step may fail if the dynamic linker does not find the libgit2
175182library:
176183
177- .. code-block :: sh
184+ .. code-block :: text
178185
179- $ python -c ' import pygit2'
186+ python -c 'import pygit2'
180187 Traceback (most recent call last):
181188 File "<string>", line 1, in <module>
182189 File "pygit2/__init__.py", line 29, in <module>
@@ -188,9 +195,10 @@ the ``/usr/local/lib`` directory, but the linker does not look for it there. To
188195fix this call ``ldconfig ``:
189196
190197.. code-block :: sh
198+ :caption: On Linux using bash
191199
192- $ sudo ldconfig
193- $ python -c ' import pygit2'
200+ sudo ldconfig
201+ python -c ' import pygit2'
194202
195203 If it still does not work, please open an issue at
196204https://github.com/libgit2/pygit2/issues
@@ -222,29 +230,32 @@ Create the virtualenv, activate it, and set the ``LIBGIT2`` environment
222230variable:
223231
224232.. code-block :: sh
233+ :caption: On Linux using bash
225234
226- $ virtualenv venv
227- $ source venv/bin/activate
228- $ export LIBGIT2=$VIRTUAL_ENV
235+ virtualenv venv
236+ source venv/bin/activate
237+ export LIBGIT2=$VIRTUAL_ENV
229238
230239 Install libgit2 (see we define the installation prefix):
231240
232241.. code-block :: sh
242+ :caption: On Linux using bash
233243
234- $ wget https://github.com/libgit2/libgit2/archive/refs/tags/v1.9.0 .tar.gz -O libgit2-1.9.0 .tar.gz
235- $ tar xzf libgit2-1.9.0 .tar.gz
236- $ cd libgit2-1.9.0 /
237- $ cmake . -DCMAKE_INSTALL_PREFIX=$LIBGIT2
238- $ cmake --build . --target install
244+ wget https://github.com/libgit2/libgit2/archive/refs/tags/v1.9.1 .tar.gz -O libgit2-1.9.1 .tar.gz
245+ tar xzf libgit2-1.9.1 .tar.gz
246+ cd libgit2-1.9.1 /
247+ cmake . -DCMAKE_INSTALL_PREFIX=$LIBGIT2
248+ cmake --build . --target install
239249
240250 Install pygit2:
241251
242252.. code-block :: sh
253+ :caption: On Linux using bash
243254
244- $ export LDFLAGS=" -Wl,-rpath,'$LIBGIT2 /lib',--enable-new-dtags $LDFLAGS "
255+ export LDFLAGS=" -Wl,-rpath,'$LIBGIT2 /lib',--enable-new-dtags $LDFLAGS "
245256 # on OSX: export LDFLAGS="-Wl,-rpath,'$LIBGIT2/lib' $LDFLAGS"
246- $ pip install pygit2
247- $ python -c ' import pygit2'
257+ pip install pygit2
258+ python -c ' import pygit2'
248259
249260
250261 The run-path
@@ -258,43 +269,49 @@ this time.
258269So you need to either set ``LD_LIBRARY_PATH `` before using pygit2, like:
259270
260271.. code-block :: sh
272+ :caption: On Linux using bash
261273
262- $ export LD_LIBRARY_PATH=$LIBGIT2 /lib
263- $ python -c ' import pygit2'
274+ export LD_LIBRARY_PATH=$LIBGIT2 /lib
275+ python -c ' import pygit2'
264276
265277 Or, like we have done in the instructions above, use the `rpath
266278<http://en.wikipedia.org/wiki/Rpath> `_, it hard-codes extra search paths within
267279the pygit2 extension modules, so you don't need to set ``LD_LIBRARY_PATH ``
268280every time. Verify yourself if curious:
269281
270282.. code-block :: sh
283+ :caption: On Linux using bash
271284
272- $ readelf --dynamic lib/python2.7/site-packages/pygit2-0.27.0-py2.7-linux-x86_64.egg/pygit2/_pygit2.so | grep PATH
285+ readelf --dynamic lib/python2.7/site-packages/pygit2-0.27.0-py2.7-linux-x86_64.egg/pygit2/_pygit2.so | grep PATH
273286 0x000000000000001d (RUNPATH) Library runpath: [/tmp/venv/lib]
274287
275288
276289 Installing on Windows
277290===================================
278291
279- `pygit2 ` for Windows is packaged into wheels and can be easily installed with
280- `pip `:
292+ `` pygit2 ` ` for Windows is packaged into wheels and can be easily installed with
293+ `` pip ` `:
281294
282295.. code-block :: console
283296
284297 pip install pygit2
285298
286- For development it is also possible to build `pygit2 ` with `libgit2 ` from
287- sources. `libgit2 ` location is specified by the ``LIBGIT2 `` environment
288- variable. The following recipe shows you how to do it from a bash shell :
299+ For development it is also possible to build `` pygit2 `` with `` libgit2 ` ` from
300+ sources. `` libgit2 ` ` location is specified by the ``LIBGIT2 `` environment
301+ variable. The following recipe shows you how to do it:
289302
290- .. code-block :: sh
303+ .. code-block :: pwsh
304+ :caption: On Windows using PowerShell (and CMake v3.21 or newer)
305+
306+ git clone -- depth= 1 - b v1.9.1 https:// github.com / libgit2/ libgit2.git
307+ $env: CMAKE_INSTALL_PREFIX = " C:/Dev/libgit2"
308+ $env: CMAKE_GENERATOR = " Visual Studio 17 2022"
309+ $env: CMAKE_GENERATOR_PLATFORM = " x64" # or "Win32" or "ARM64"
310+ cmake - B libgit2/ build - S libgit2
311+ cmake -- build libgit2/ build -- config release -- target install
291312
292- $ export LIBGIT2=C:/Dev/libgit2
293- $ git clone --depth=1 -b v1.9.0 https://github.com/libgit2/libgit2.git
294- $ cd libgit2
295- $ cmake . -DCMAKE_INSTALL_PREFIX=$LIBGIT2 -G " Visual Studio 14 Win64"
296- $ cmake --build . --config release --target install
297- $ ctest -v
313+ # let pip know where to find libgit2 when building pygit2
314+ $env: LIBGIT2 = " $env: CMAKE_INSTALL_PREFIX "
298315
299316 At this point, you're ready to execute the generic `pygit2 ` installation steps
300317described at the start of this page.
@@ -321,8 +338,8 @@ XCode and Homebrew are already installed.
321338
322339.. code-block :: sh
323340
324- $ brew update
325- $ brew install libgit2
326- $ pip3 install pygit2
341+ brew update
342+ brew install libgit2
343+ pip3 install pygit2
327344
328345 To build from a non-Homebrew libgit2 follow the guide in `libgit2 within a virtual environment `_.
0 commit comments