Open brian-dellabetta opened 9 months ago
Thanks for the report. I suspect the issue is that some state is being saved in the sysimage, i.e. __init__
sets some variables somewhere, and these values are what are saved in the sysimage, which is confusing __init__
because they are not their default values. So probably __init__
needs to explicitly set these to the default.
Thanks @cjdoris for the reply. I will try setting the default values in __init__
later this week, hopefully it's a quick fix
I added some println
s to PythonCall.jl (see diff here) to get some more information. I thought it would be a matter of setting CTX, but the issue is more subtle than that.
Running from juliacall import Main as jl
without sysimage, CTX.is_embedded is true.
Running the same with PYTHON_JULIACALL_SYSIMAGE
set, it is false and continues down the function until it fails on this line.
This makes sense, the flag gets set to true normally because __PythonCall_libptr
is set in the startup script before the using PythonCall
line, but it's false when running with a sysimage because the PythonCall __init__
gets called at julia startup, before any other commands are run.
I'm not sure what the best solution is here. Maybe if the sysimage env var is set, consider it embedded and exit out of the init?
CTX.is_embedded = haskey(ENV, "JULIA_PYTHONCALL_SYSIMAGE") ? true : hasproperty(Base.Main, :__PythonCall_libptr)
There might be edge cases where this isn't desired.
Affects: Both
Describe the bug I would like to use a custom sysimage of our julia package which has PythonCall.jl as a dependency. The image builds fine, and is useable with
julia --sysimage=/path/to/myimage.so
, but when I try to use it as the custom sysimage with juliacall, I hit the following initialization error:I tried a sysimage that didn't have PythonCall imported or as a dependency, and juliacall initalized as expected. Maybe this isn't possible, but the Assertion error is occuring at this line, and I'm not using PyCall anywhere, so perhaps it is a bug in
init_context
?Steps to reproduce
In a fresh directory, create
1) build.jl:
2) precompile.jl:
call
julia --project=. build.jl
(preferably in a fresh project) and thenPYTHON_JULIACALL_SYSIMAGE=/home/xxx/.julia/sysimages/myimage.so python -c 'from juliacall import Main as jl'
Your system Please provide detailed information about your system:
Pkg.status()
after running build.jl:juliapkg.status()
.Additional context Add any other context about the problem here.