Windows: libgit2.dll not found

I am trying the juliacall package, installed in a conda environment, and julia fails to find the libgit2 dll on windows. The problem appears when trying to install JuMP.

In stdlib/LibGit2/src/LibGit2.jl the problematic line seems to be @check ccall((:git_libgit2_init, :libgit2), Cint, ()) and I try to reproduce the problem below.

Giving it only the symbol :libgit2, the following python code (using juliacall with the julia installation that it has installed itself inside my conda environment) fails to find the dll.

(iqc_test) PS C:\Users\johan\IQC_Test> python
Python 3.10.6 | packaged by conda-forge | (main, Oct  7 2022, 20:14:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from juliacall import Main as jl
>>> jl.seval("ccall((:git_libgit2_init, :libgit2), Cint, ())")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\johan\.julia\packages\PythonCall\eU0yr\src\jlwrap\module.jl", line 25, in seval
    return self._jl_callmethod($(pyjl_methodnum(pyjlmodule_seval)), expr)
juliacall.JuliaError: could not load library "libgit2"
The specified module could not be found.
Stacktrace:
 [1] top-level scope
   @ .\none:1
 [2] eval
   @ .\boot.jl:368 [inlined]
 [3] eval
   @ .\Base.jl:65 [inlined]
 [4] pyjlmodule_seval(self::Module, expr::PythonCall.Py)
   @ PythonCall C:\Users\johan\.julia\packages\PythonCall\eU0yr\src\jlwrap\module.jl:13
 [5] _pyjl_callmethod(f::Any, self_::Ptr{PythonCall.C.PyObject}, args_::Ptr{PythonCall.C.PyObject}, nargs::Int64)
   @ PythonCall C:\Users\johan\.julia\packages\PythonCall\eU0yr\src\jlwrap\base.jl:62
 [6] _pyjl_callmethod(o::Ptr{PythonCall.C.PyObject}, args::Ptr{PythonCall.C.PyObject})
   @ PythonCall.C C:\Users\johan\.julia\packages\PythonCall\eU0yr\src\cpython\jlwrap.jl:47 

but giving it the full path to the dll seems to work better

(iqc_test) PS C:\Users\johan\IQC_Test> python
Python 3.10.6 | packaged by conda-forge | (main, Oct  7 2022, 20:14:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from juliacall import Main as jl
>>> jl.seval('ccall((:git_libgit2_init, "C:/Users/johan/.conda/envs/iqc_test/julia_env/pyjuliapkg/install/bin/libgit2.dll"), Cint, ())')
1

I do not understand where julia should look for libgit2.dll and how I could help it find it.

Julia ships its own build of libgit2, as it’s needed by the package manager, it’s in the lib/julia/ subdirectory of its installation.

In my linux, via wsl, the libraries reside in the lib/julia subdirectory, and my program works.

In windows, the libraries reside instead in bin, and julia fails to locate them.

1 Like

When I start the julai repl in windows, using the julia binary that was installed by juliacall in the conda environment, it manages to find libgit2.dll.

The problem therefore seems to be due to juliacall starting julia in a different way.

1 Like

@cjdoris, is this then a (known, someone already made an issue?) bug in juliacall (I’m assuming it’s used as intended)?

That’s for Linux, why not the same on Windows (unless WSL2)? If there’s a good reason for the inconsistency, then never-mind, but it’s likely the reason for the juliacall Windows bug (and potentially affecting other .dlls too?), and a simple path solution (but I’m not on Windows, so I can’t check).

You need to add the path to libgit2.dll to the PATH environment variable.
I think for you it is

"C:/Users/johan/.conda/envs/iqc_test/julia_env/pyjuliapkg/install/bin"

I am not sure what’s your setting, so I use the windows \ standard for this path and I assume that you are using powershell (because I see a PS prompt).
Add the following to your PATH environment variable, e.g.:

PS X:\> $env:Path += ';C:\Users\johan\.conda\envs\iqc_test\julia_env\pyjuliapkg\install\bin'

PS X:\> python.exe
Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from juliacall import Main as jl
>>> jl.seval("ccall((:git_libgit2_init, :libgit2), Cint, ())")
1

Of course I did another PATH for me, so it worked for me. But above should do for you.

I would say this is something worth to open up an issue (if it doesn’t exists already, didn’t check, GitHub - cjdoris/PythonCall.jl: Python and Julia in harmony.).

Not sure what you mean since libgit2 is shipped for all systems.

I meant the inconsistency (probably unrelated to finding it, or juliacall relies on it in lib?):

Fixed! path fix on windows · cjdoris/PythonCall.jl@e1b1670 · GitHub

Just needed to add an entry to the PATH on Windows.

I’m making a release, try again in an hour…

2 Likes