Pyimport works from repl defined module but not in my package

My guess is that this line may not survive pre-compilation:

hnswlib = pyimport("hnswlib")

Can you try to define an object and then initialize it inside __init__ function, like this:

const hnswlib = PyNULL()

function __init__()
    copy!(hnswlib, pyimport("hnswlib"))
end

Ref: https://github.com/JuliaPy/PyCall.jl#using-pycall-from-julia-modules

3 Likes