Skip to content

Commit 6bf7575

Browse files
author
Christopher Doris
committed
check Python and PyCall are using the same libpython
1 parent 149f2fd commit 6bf7575

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/init.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
check_libpath(PyCall) = begin
2+
if realpath(PyCall.libpython) == realpath(CONFIG.libpath)
3+
# @info "libpython path agrees between Python and PyCall" Python.CONFIG.libpath PyCall.libpython
4+
else
5+
@warn "Python and PyCall are using different versions of libpython. This will probably go badly." Python.CONFIG.libpath PyCall.libpython
6+
end
7+
end
8+
19
@init begin
210
# Check if libpython is already loaded (i.e. if the Julia interpreter was started from a Python process)
311
CONFIG.isembedded = haskey(ENV, "PYTHONJL_LIBPTR")
@@ -87,6 +95,14 @@
8795
""")
8896
end
8997

98+
# Compare libpath with PyCall
99+
PyCall = get(Base.loaded_modules, Base.PkgId(Base.UUID("438e738f-606a-5dbb-bf0a-cddfbfd45ab0"), "PyCall"), nothing)
100+
if PyCall === nothing
101+
@require PyCall="438e738f-606a-5dbb-bf0a-cddfbfd45ab0" check_libpath(PyCall)
102+
else
103+
check_libpath(PyCall)
104+
end
105+
90106
# Initialize
91107
with_gil() do
92108
if C.Py_IsInitialized() != 0

0 commit comments

Comments
 (0)